diff --git a/Makefile b/Makefile index 5656e7a..d625db7 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,8 @@ WEBDIR := web LINTER := $(TOOLBINDIR)/golangci-lint LINTER_CONFIG := .golangci.yaml JSLINTER_BIN := $(realpath tools)/node-v12.16.3/bin +NPM := $(JSLINTER_BIN)/npm +NPX := $(JSLINTER_BIN)/npx COVERAGE_OUTPUT := coverage.out @@ -43,22 +45,28 @@ DIRS = internal RECURSIVE_DIRS = $(addprefix ./, $(addsuffix /..., $(DIRS))) .PHONY: build -build: $(MAIN) $(EXAMPLES) - +build: $(MAIN) $(NPX) $(MAIN): FORCE @mkdir -p $(BUILD_DIR) go build -o $(MAIN)$(EXTENSION) $(GO_FLAGS) cmd/$(@F)/main.go +FORCE: + +.PHONY: examples +examples: $(EXAMPLES) $(EXAMPLES): FORCE @mkdir -p $(BUILD_DIR) go build -o $@$(EXTENSION) $(GO_FLAGS) examples/$(@F)/main.go -FORCE: .PHONY: install-octant-plugins install-octant-plugins: @mkdir -p $(OCTANT_PLUGINSTUB_DIR) cp $(addsuffix $(EXTENSION), $(BUILD_DIR)/octant) $(OCTANT_PLUGINSTUB_DIR) +.PHONY: install-npm-modules +install-npm-modules: $(NPX) + cd $(WEBDIR) && (PATH="$(PATH):$(JSLINTER_BIN)"; $(NPM) install) && cd .. + .PHONY: test test: go test $(RECURSIVE_DIRS) -v $(TESTFLAGS) @@ -83,10 +91,10 @@ docs: .PHONY: env .PHONY: lint -lint: $(LINTER) +lint: $(LINTER) $(NPX) $(LINTER) run --config $(LINTER_CONFIG) - cd $(WEBDIR) && (PATH="$(PATH):$(JSLINTER_BIN)"; $(JSLINTER_BIN)/npx --no-install eslint js) && cd .. - cd $(WEBDIR) && (PATH="$(PATH):$(JSLINTER_BIN)"; $(JSLINTER_BIN)/npx --no-install eslint --ext .html .) && cd .. + cd $(WEBDIR) && (PATH="$(PATH):$(JSLINTER_BIN)"; $(NPX) --no-install eslint js) && cd .. + cd $(WEBDIR) && (PATH="$(PATH):$(JSLINTER_BIN)"; $(NPX) --no-install eslint --ext .html .) && cd .. .PHONY: tidy tidy: @@ -96,4 +104,8 @@ tidy: $(LINTER): @mkdir -p $(TOOLBINDIR) - ./tools/install_linter + ./tools/install_go_linter + +$(NPX): + @mkdir -p $(TOOLBINDIR) + ./tools/install_js_linter diff --git a/README.md b/README.md index e4918ae..126e0b2 100644 --- a/README.md +++ b/README.md @@ -13,11 +13,8 @@ Airship UI is an [electron](https://www.electronjs.org/) that is designed to all ``` git clone https://opendev.org/airship/airshipui cd airshipui -make build -cd web -npm install -npm install --save-dev electron -npm install electron-json-config +make +make install-npm-modules # Note running behind a proxy can cause issues, notes on solving is in the Appendix of the Developer's Guide ``` ## Adding Additional Functionality diff --git a/docs/source/developers.md b/docs/source/developers.md index 85b2337..cb9e53e 100644 --- a/docs/source/developers.md +++ b/docs/source/developers.md @@ -11,11 +11,11 @@ Clone the Airship UI repository and build git clone https://opendev.org/airship/airshipui cd airshipui make + make install-npm-modules # Note running behind a proxy can cause issues, notes on solving is in the Appendix + make examples # (optional) make install-octant-plugins # (if running with octant) - cd web - npm install - npm install --save-dev electron - npm install electron-json-config + + Run the airshipui binary @@ -69,6 +69,82 @@ Run the octant binary and the plugin should show "Hello World just some text on [Minikube](https://kubernetes.io/docs/setup/learning-environment/minikube/) runs a single-node Kubernetes cluster for users looking to try out Kubernetes or develop with it day-to-day. Installation instructions are available on the kubernetes website: https://kubernetes.io/docs/tasks/tools/install-minikube/). If you are running behind a proxy it may be necessary to follow the steps outlined in the [How to use an HTTP/HTTPS proxy with minikube](https://minikube.sigs.k8s.io/docs/reference/networking/proxy/) website. +### Issues with npm / npx and the electron go module +It is possible that the airship ui will exit with an error code 1 when attempting to start the first time: + + $ bin/airshipui + 2020/05/28 14:54:16 Attempting to start webservice on localhost:8080 + 2020/05/28 14:54:16 Exit electron 1 + +You can attempt a manual start of electron from the root of the airshipui tree to see a more verbose log + + $ npm start --prefix web + + > electron-poc@0.0.1 start /home/ubuntu/airshipui/web + > electron . + + /home/ubuntu/airshipui/web/node_modules/electron/index.js:14 + throw new Error('Electron failed to install correctly, please delete node_modules/electron and try installing again') + ^ + + Error: Electron failed to install correctly, please delete node_modules/electron and try installing again + at getElectronPath (/home/ubuntu/airshipui/web/node_modules/electron/index.js:14:11) + at Object. (/home/ubuntu/airshipui/web/node_modules/electron/index.js:18:18) + at Module._compile (internal/modules/cjs/loader.js:1133:30) + at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10) + at Module.load (internal/modules/cjs/loader.js:977:32) + at Function.Module._load (internal/modules/cjs/loader.js:877:14) + at Module.require (internal/modules/cjs/loader.js:1019:19) + at require (internal/modules/cjs/helpers.js:77:18) + at Object. (/home/ubuntu/airshipui/web/node_modules/electron/cli.js:3:16) + at Module._compile (internal/modules/cjs/loader.js:1133:30) + npm ERR! code ELIFECYCLE + npm ERR! errno 1 + npm ERR! electron-poc@0.0.1 start: `electron .` + npm ERR! Exit status 1 + npm ERR! + npm ERR! Failed at the electron-poc@0.0.1 start script. + npm ERR! This is probably not a problem with npm. There is likely additional logging output above. + + npm ERR! A complete log of this run can be found in: + npm ERR! /home/ubuntu/.npm/_logs/2020-05-28T14_55_52_327Z-debug.log + $ + +This is likely due to a problem with the electron install. If you cd to the web directory and attempt to install you may see an error: + + npm install electron + + > electron@8.3.0 postinstall /home/ubuntu/airshipui/web/node_modules/electron + > node install.js + + (node:19823) UnhandledPromiseRejectionWarning: RequestError: connect ETIMEDOUT 192.30.255.113:443 + at ClientRequest. (/home/ubuntu/airshipui/web/node_modules/got/source/request-as-event-emitter.js:178:14) + at Object.onceWrapper (events.js:417:26) + at ClientRequest.emit (events.js:322:22) + at ClientRequest.EventEmitter.emit (domain.js:482:12) + at ClientRequest.origin.emit (/home/ubuntu/airshipui/web/node_modules/@szmarczak/http-timer/source/index.js:37:11) + at TLSSocket.socketErrorListener (_http_client.js:426:9) + at TLSSocket.emit (events.js:310:20) + at TLSSocket.EventEmitter.emit (domain.js:482:12) + at emitErrorNT (internal/streams/destroy.js:92:8) + at emitErrorAndCloseNT (internal/streams/destroy.js:60:3) + (node:19823) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) + (node:19823) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. + npm WARN electron-poc@0.0.1 No repository field. + + + electron@8.3.0 + updated 1 package and audited 361 packages in 143.19s + + 9 packages are looking for funding + run `npm fund` for details + + found 1 low severity vulnerability + run `npm audit fix` to fix them, or `npm audit` for details + +If you're running behind a corporate proxy this is the workaround: + + npx cross-env ELECTRON_GET_USE_PROXY=true GLOBAL_AGENT_HTTPS_PROXY=http://: npm install electron + ### Optional proxy settings #### Environment settings for wget or curl diff --git a/internal/electron/app.go b/internal/electron/app.go index d5e3336..b23f39f 100755 --- a/internal/electron/app.go +++ b/internal/electron/app.go @@ -2,9 +2,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - https://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,12 +14,28 @@ package electron import ( "fmt" + "log" + "os" "os/exec" + "path/filepath" "syscall" ) // RunElectron executes the standalone electron app which serves up our web components func RunElectron() error { + // determine ; or : depending on the OS + sep := string(os.PathListSeparator) + + // get the current working directory, should be the root of the airshipui tree + path, err := os.Getwd() + if err != nil { + log.Println(err) + } + + // TODO: make the node path dynamic or setable at compile time + os.Setenv("PATH", filepath.Join(path+"/tools/node-v12.16.3/bin")+sep+os.Getenv("PATH")) + + // This should start the electron app with the internal npm & node binaries cmd := exec.Command("npm", "start", "--prefix", "web") if err := cmd.Run(); err != nil { diff --git a/tools/install_go_linter b/tools/install_go_linter new file mode 100755 index 0000000..b0fa9d0 --- /dev/null +++ b/tools/install_go_linter @@ -0,0 +1,11 @@ +#!/bin/bash +set -x + +tools_bin_dir="${BASH_SOURCE%/*}" +download_url=https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh +version=v1.24.0 + +if ! curl -sfL "$download_url" | sh -s -- -b "$tools_bin_dir/bin" "$version"; then + printf "Something went wrong while installing golangci-lint\n" 1>&2 + exit 1 +fi diff --git a/tools/install_js_linter b/tools/install_js_linter new file mode 100755 index 0000000..e093cef --- /dev/null +++ b/tools/install_js_linter @@ -0,0 +1,48 @@ +#!/bin/bash +set -x + +tools_bin_dir="${BASH_SOURCE%/*}" +node_version=v12.16.3 + +if [[ ! -d $tools_bin_dir/node-$node_version ]]; then + if [[ "$OSTYPE" == "linux-gnu"* ]]; then + # Linux + if ! curl -sfL "https://nodejs.org/dist/$node_version/node-$node_version-linux-x64.tar.gz" | tar zxf - --directory "$tools_bin_dir"; then + printf "Something went wrong while installing linux-gnu nodejs\n" 1>&2 + exit 1 + else + mv $tools_bin_dir/node-$node_version-linux-x64 $tools_bin_dir/node-$node_version + fi + elif [[ "$OSTYPE" == "darwin"* ]]; then + # Mac OSX + if ! curl -sfL "https://nodejs.org/dist/$node_version/node-$node_version-darwin-x64.tar.gz" | tar zxf - --directory "$tools_bin_dir"; then + printf "Something went wrong while installing Mac OSX nodejs\n" 1>&2 + exit 1 + else + mv $tools_bin_dir/node-$node_version-darwin-x64 $tools_bin_dir/node-$node_version + fi + elif [[ "$OSTYPE" == "cygwin" ]]; then + # Windows + if ! wget -qO- https://nodejs.org/dist/$node_version/node-$node_version-win-x64.zip | bsdtar -xf- -C tools; then + printf "Something went wrong while installing Windows nodejs\n" 1>&2 + exit 1 + else + mv $tools_bin_dir/node-$node_version-win-x64 $tools_bin_dir/node-$node_version + # the windows install doesn't conform to the same directory structure so making it conform + mkdir $tools_bin_dir/node-$node_version/bin + mv $tools_bin_dir/node-$node_version/n* $tools_bin_dir/node-$node_version/bin + chmod -R a+x $tools_bin_dir/node-$node_version/bin + fi + fi + + # npm requires node to also be on the path + export PATH=$(realpath $tools_bin_dir)/node-$node_version/bin:$PATH + + # npm will write to a node_modules even with the --directory flag it's better to be in the root of where you want this to live + cd web + if ! npm install eslint-plugin-html@latest --save-dev; then + printf "Something went wrong while installing eslint-plugin-html\n" 1>&2 + exit 1 + fi + cd .. +fi \ No newline at end of file diff --git a/tools/install_linter b/tools/install_linter deleted file mode 100755 index 1cfc1af..0000000 --- a/tools/install_linter +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/bash -set -x - -tools_bin_dir="${BASH_SOURCE%/*}" -download_url=https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh -version=v1.24.0 -node_version=v12.16.3 - -if ! curl -sfL "$download_url" | sh -s -- -b "$tools_bin_dir/bin" "$version"; then - printf "Something went wrong while installing golangci-lint\n" 1>&2 - exit 1 -fi - -if [[ "$OSTYPE" == "linux-gnu"* ]]; then - # Linux - if ! curl -sfL "https://nodejs.org/dist/$node_version/node-$node_version-linux-x64.tar.gz" | tar zxf - --directory "$tools_bin_dir"; then - printf "Something went wrong while installing linux-gnu nodejs\n" 1>&2 - exit 1 - else - mv $tools_bin_dir/node-$node_version-linux-x64 $tools_bin_dir/node-$node_version - fi -elif [[ "$OSTYPE" == "darwin"* ]]; then - # Mac OSX - if ! curl -sfL "https://nodejs.org/dist/$node_version/node-$node_version-darwin-x64.tar.gz" | tar zxf - --directory "$tools_bin_dir"; then - printf "Something went wrong while installing Mac OSX nodejs\n" 1>&2 - exit 1 - else - mv $tools_bin_dir/node-$node_version-darwin-x64 $tools_bin_dir/node-$node_version - fi -elif [[ "$OSTYPE" == "cygwin" ]]; then - # Windows - if ! wget -qO- https://nodejs.org/dist/$node_version/node-$node_version-win-x64.zip | bsdtar -xf- -C tools; then - printf "Something went wrong while installing Windows nodejs\n" 1>&2 - exit 1 - else - mv $tools_bin_dir/node-$node_version-win-x64 $tools_bin_dir/node-$node_version - # the windows install doesn't conform to the same directory structure so making it conform - mkdir $tools_bin_dir/node-$node_version/bin - mv $tools_bin_dir/node-$node_version/n* $tools_bin_dir/node-$node_version/bin - chmod -R a+x $tools_bin_dir/node-$node_version/bin - fi -fi - -# npm requires node to also be on the path -export PATH=$(realpath $tools_bin_dir)/node-$node_version/bin:$PATH - -# npm will write to a node_modules even with the --directory flag it's better to be in the root of where you want this to live -cd web -if ! npm install eslint-plugin-html@latest --save-dev; then - printf "Something went wrong while installing eslint-plugin-html\n" 1>&2 - exit 1 -fi -cd .. \ No newline at end of file