Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wui #302

Merged
merged 5 commits into from
Mar 31, 2021
Merged

Wui #302

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .internal/api/src/utils/commonBuildChecks.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ const {

const checkPortConflicts = ({ buildTemplate, buildOptions, serviceName }) => {
const portConflicts = [];

const currentServiceExternalPorts = buildTemplate?.services?.[serviceName]?.ports?.map((port) => {
return getExternalPort(port);
}) ?? [];

// This is for services that have network mode set to host (and ports can't be specified in the docker-compose file)
const currentConfiguredServiceExternalPorts = Object.values(buildOptions?.serviceConfigurations?.services?.[serviceName]?.ports ?? [])?.map((port) => {
return getExternalPort(port);
}) ?? [];

Object.keys(buildTemplate?.services ?? {}).forEach((service) => {
if (service === serviceName) {
return null; // Skip self
Expand All @@ -18,7 +24,7 @@ const checkPortConflicts = ({ buildTemplate, buildOptions, serviceName }) => {
}) ?? [];

checkingServiceExternalPorts.forEach((port) => {
if (currentServiceExternalPorts.includes(port)) {
if ([...currentConfiguredServiceExternalPorts, ...currentServiceExternalPorts].includes(port)) {
portConflicts.push({
type: 'service',
name: serviceName,
Expand Down
9 changes: 9 additions & 0 deletions .internal/api/src/utils/commonCompileLogic.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ const setModifiedPorts = ({ buildTemplate, buildOptions, serviceName }) => {
const modifiedPortList = Object.keys(serviceConfig?.ports ?? {});
let updated = false;

if (serviceTemplate.network_mode === 'host') {
delete buildTemplate?.services?.[serviceName]?.['ports'];
return true;
}

for (let i = 0; i < modifiedPortList.length; i++) {
(serviceTemplate?.ports ?? []).forEach((port, index) => {
const eiPort = port.split('/')[0];
Expand Down Expand Up @@ -143,6 +148,10 @@ const setNetworkMode = ({ buildTemplate, buildOptions, serviceName }) => {
if (serviceConfig.networkMode === 'none') {
delete serviceTemplate['network_mode'];
}

if (serviceTemplate.network_mode === 'host') {
delete buildTemplate?.services?.[serviceName]?.['ports'];
}
}

return currentNetworkMode !== serviceTemplate['network_mode'];
Expand Down
657 changes: 252 additions & 405 deletions .internal/pycli/buildstack_menu.py

Large diffs are not rendered by default.

185 changes: 185 additions & 0 deletions .internal/pycli/deps/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def checkApiHealth(host, protocol="http://"):
res['json'] = None
except:
res = {}
res['funcName'] = 'checkApiHealth'
res['url'] = url
res['apiRequest'] = None
res['status'] = -1
Expand All @@ -39,6 +40,7 @@ def deleteBuild(host, build, protocol="http://"):
res['json'] = None
except:
res = {}
res['funcName'] = 'deleteBuild'
res['url'] = url
res['apiRequest'] = None
res['status'] = -1
Expand Down Expand Up @@ -69,6 +71,7 @@ def getTemplateBuildBootstrap(host, build, noFluff = True, protocol="http://"):
res['json'] = None
except:
res = {}
res['funcName'] = 'getTemplateBuildBootstrap'
res['url'] = url
res['body'] = requestData
res['apiRequest'] = None
Expand Down Expand Up @@ -101,6 +104,7 @@ def getPreviousBuildList(host, index = None, limit = None, protocol="http://"):
res['json'] = None
except:
res = {}
res['funcName'] = 'getPreviousBuildList'
res['url'] = url
res['apiRequest'] = None
res['status'] = -1
Expand All @@ -120,6 +124,187 @@ def checkWuiState(host, protocol="http://"):
res['json'] = None
except:
res = {}
res['funcName'] = 'checkWuiState'
res['apiRequest'] = None
res['status'] = -1
res['text'] = None
res['json'] = None

return res

def getBuildServicesList(host, protocol="http://"):
try:
url = '{protocol}{host}/templates/services/list'.format(host=host, protocol=protocol)

apiRequest = requests.get(url, timeout = 2)

res = {}
res['apiRequest'] = apiRequest
res['status'] = apiRequest.status_code
res['text'] = apiRequest.text
try:
res['json'] = apiRequest.json()
except:
res['json'] = None
except:
res = {}
res['funcName'] = 'getBuildServicesList'
res['url'] = url
res['apiRequest'] = None
res['status'] = -1
res['text'] = None
res['json'] = None

return res

def getBuildServicesJsonList(host, protocol="http://"):
try:
url = '{protocol}{host}/templates/services/json'.format(host=host, protocol=protocol)

apiRequest = requests.get(url, timeout = 2)

res = {}
res['apiRequest'] = apiRequest
res['status'] = apiRequest.status_code
res['text'] = apiRequest.text
try:
res['json'] = apiRequest.json()
except:
res['json'] = None
except:
res = {}
res['funcName'] = 'getBuildServicesJsonList'
res['url'] = url
res['apiRequest'] = None
res['status'] = -1
res['text'] = None
res['json'] = None

return res

def getBuildServicesYamlList(host, protocol="http://"):
try:
url = '{protocol}{host}/templates/services/yaml'.format(host=host, protocol=protocol)

apiRequest = requests.get(url, timeout = 2)

res = {}
res['apiRequest'] = apiRequest
res['status'] = apiRequest.status_code
res['text'] = apiRequest.text
res['json'] = None
except:
res = {}
res['funcName'] = 'getBuildServicesYamlList'
res['url'] = url
res['apiRequest'] = None
res['status'] = -1
res['text'] = None
res['json'] = None

return res

def getBuildServicesMetaData(host, protocol="http://"):
try:
url = '{protocol}{host}/config/meta'.format(host=host, protocol=protocol)

apiRequest = requests.get(url, timeout = 2)

res = {}
res['apiRequest'] = apiRequest
res['status'] = apiRequest.status_code
res['text'] = apiRequest.text
try:
res['json'] = apiRequest.json()
except:
res['json'] = None
except:
res = {}
res['funcName'] = 'getBuildServicesMetaData'
res['url'] = url
res['apiRequest'] = None
res['status'] = -1
res['text'] = None
res['json'] = None

return res

def getBuildServicesOptionsData(host, protocol="http://"):
try:
url = '{protocol}{host}/config/options'.format(host=host, protocol=protocol)

apiRequest = requests.get(url, timeout = 2)

res = {}
res['apiRequest'] = apiRequest
res['status'] = apiRequest.status_code
res['text'] = apiRequest.text
try:
res['json'] = apiRequest.json()
except:
res['json'] = None
except:
res = {}
res['funcName'] = 'getBuildServicesOptionsData'
res['url'] = url
res['apiRequest'] = None
res['status'] = -1
res['text'] = None
res['json'] = None

return res

def saveBuild(host, selectedServices, serviceConfigurations = {}, protocol="http://"):
try:
url = '{protocol}{host}/build/save'.format(host=host, protocol=protocol)
requestData = {}
requestData['buildOptions'] = {}
requestData['buildOptions']['selectedServices'] = selectedServices
requestData['buildOptions']['serviceConfigurations'] = serviceConfigurations

apiRequest = requests.post(url = url, json = requestData, timeout = 2)

res = {}
res['apiRequest'] = apiRequest
res['status'] = apiRequest.status_code
res['text'] = apiRequest.text
try:
res['json'] = apiRequest.json()
except:
res['json'] = None
except:
res = {}
res['funcName'] = 'saveBuild'
res['url'] = url
res['apiRequest'] = None
res['status'] = -1
res['text'] = None
res['json'] = None

return res

def checkBuild(host, selectedServices, serviceConfigurations = {}, protocol="http://"):
try:
requestData = {}
requestData['buildOptions'] = {}
requestData['buildOptions']['selectedServices'] = selectedServices
requestData['buildOptions']['serviceConfigurations'] = serviceConfigurations
url = '{protocol}{host}/build/dryrun'.format(host=host, protocol=protocol)

apiRequest = requests.post(url = url, json = requestData, timeout = 2)

res = {}
res['apiRequest'] = apiRequest
res['status'] = apiRequest.status_code
res['text'] = apiRequest.text
try:
res['json'] = apiRequest.json()
except:
res['json'] = None
except:
res = {}
res['funcName'] = 'checkBuild'
res['url'] = url
res['apiRequest'] = None
res['status'] = -1
res['text'] = None
Expand Down
2 changes: 1 addition & 1 deletion .internal/pycli/entry.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

# cd .internal/pycli && nodemon --no-stdin --exec python3 entry.py
# export API_ADDR=localhost:32128 && export HOST_CON_API=localhost:32128 && cd .internal/pycli; nodemon --no-stdin --exec python3 entry.py

import blessed
import yaml
Expand Down
4 changes: 3 additions & 1 deletion .internal/pycli/menu_main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python3

# export API_ADDR=localhost:32128 && export HOST_CON_API=localhost:32128 && cd .internal/pycli; nodemon --no-stdin --exec python3 entry.py

from blessed import Terminal
import sys
import subprocess
Expand Down Expand Up @@ -231,7 +233,7 @@ def skipItem(currentMenuItemIndex, direction):

baseMenu = [
["Install Builds", installBuild],
# ["Create Build", buildStack], # Not yet ready
["Create Build", buildStack], # Not yet ready
["Docker Commands", dockerCommands],
["Miscellaneous Commands", miscCommands],
["Backup and Restore", backupAndRestore],
Expand Down
4 changes: 3 additions & 1 deletion .internal/templates/services/influxdb/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ const ServiceBuilder = ({
setModifiedPorts,
setLoggingState,
setNetworkMode,
setNetworks
setNetworks,
setDevices,
setEnvironmentVariables
} = require('../../../src/utils/commonCompileLogic');

const {
Expand Down
2 changes: 1 addition & 1 deletion .internal/wui/.eslintcache

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ if [[ "$HAS_ERROR" == "true" ]]; then
echo "--------"
echo ""
echo "An error occured installing IOTstack. Please review the output above."
echo "If you have just installed the OS, try giving the RPi 30 minutes to complete setup and try installing IOTstack again."
read -n 1 -s -r -p "Press any key to continue"
else
echo "IOTstack setup completed"
Expand Down