From 1781647571280a7b6f0b62710da8a5e989437ba6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=C3=A1n=20A=2E=20Young?= Date: Fri, 13 Dec 2019 20:32:32 +0000 Subject: [PATCH] Completed GCP BUild flow. From gcloudBuild.bat to deployment via unit & e2e test. Also some minor isAuthenticated$ changes on login.html. diff --git a/.editorconfig b/.editorconfig index 82f367c..7738f19 100644 --- a/.editorconfig +++ b/.editorconfig @@ -2,7 +2,7 @@ root = true [*] -end_of_line = crlf +# end_of_line = crlf # Let VSCode handle this in case I need some files LF charset = utf-8 indent_style = space indent_size = 2 diff --git a/.gcloudignore b/.gcloudignore index c7f933b..e957075 100644 --- a/.gcloudignore +++ b/.gcloudignore @@ -1,57 +1,21 @@ +## Listed files are not uploaded by 'gcloud builds submit and 'gcloud app deploy' - using the same file for each to avoid environment differences introducing error => all files needed for the build or deployment are included + +# dist directories are not ignored even though they are rebuilt in the build steps - the newly built dist directories are included when you deploy ## ignore from root... .git/ +.nyc_output/ .vscode/ -# backend included - see below -# frontend included - see below +coverage/ node_modules/ -.editorconfig -.gcloudignore .gitignore -.npmrc -.prettierrc -app.yaml cron.yaml -debug.log -# gcpError.html included -LICENSE -package-lock.json -# package.json included project-perform.code-workspace README.md -tsconfig.json -tslint.json ## ignore from backend -# backend/api included as called -# backend/certs included as needed for database access backend/coverage/ -# backend/dist included -backend/src -backend/utils-build/ -backend/.envDevelopment -# backend/.envProduction included -backend/.mocharc.json -backend/.nycrc.json -backend/tsconfig.json -backend/tslint.json - -## ignore from backend/dist -backend/dist/**test/ -backend/dist/**/*.map -## ignore from frontend - all but dist +## ignore from frontend frontend/coverage/ -frontend/e2e/ frontend/node_modules/ -frontend/src/ -frontend/utils/ -frontend/.prettierignore -frontend/angular.json -frontend/browserslist -frontend/debug.log -frontend/package.lock-json -frontend/package.json -frontend/proxy.conf.json -frontend/tsconfig.json -frontend/tslint.json diff --git a/.gitignore b/.gitignore index e591d0c..ef2312b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,34 +1,3 @@ -### Windows ### -# Created by https://www.gitignore.io/api/windows -# Edit at https://www.gitignore.io/?templates=windows - -# Windows thumbnail cache files -Thumbs.db -Thumbs.db:encryptable -ehthumbs.db -ehthumbs_vista.db - -# Dump file -*.stackdump - -# Folder config file -[Dd]esktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msix -*.msm -*.msp - -# Windows shortcuts -*.lnk - -### End of https://www.gitignore.io/api/windows ### - ### Node ### Created by https://www.gitignore.io/api/node # Edit at https://www.gitignore.io/?templates=node @@ -100,8 +69,6 @@ typings/ # dotenv environment variables file .env .env.test -.envDevelopment -.envProduction # parcel-bundler cache (https://parceljs.org/) .cache @@ -126,39 +93,26 @@ typings/ ### End of https://www.gitignore.io/api/node ### -# ignore all dist' directories -**/dist/ -# ignore all '/types' directories -# **/types/ - -### security-relevant ignores ### - -# ignore istanbul report directories -.nyc_output/ -# ignore istanbul coverage directories -coverage/ -# ignore all all 'logs/' directories -logs/ -# ignore all all '.log' files -**/*.log -# ignore all node_module dependencies -node_modules/ -# ignore all files and directories in all public/ directories -public/ -# ignore all '/types'mdirectories -# types/ -# ignore all compiled 'dist' directories -dist/ +### Security-relevant ignores ### + # ignore all credential certs directories **/certs/ + # ignore all .env files .env -.env.test -.envDevelopment -.envProduction +.env* ### End of security-relevant ignores ### +### Other ignores ### + +# ignore all compiled 'dist' directories +dist/ + + +### End of other ignores ### + + # If files are not being ignored then they may have been previously added # try git rm --cached , or git rm -r --cached to get git # to forget the file or directory. (Don't forget the --cached, otherwise git diff --git a/.npmrc b/.npmrc index 8c81096..4d9964c 100644 --- a/.npmrc +++ b/.npmrc @@ -1,2 +1,5 @@ # use same version of node for scripts and npm scripts-prepend-node-path=true + +# turn off color to suit GCP tty output +color=false diff --git a/.vscode/launch.json b/.vscode/launch.json index dd6d57d..1d25f16 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,33 +4,33 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ - // Start frontend - use for frontend debug with watch + // Serve frontend with backend - use for frontend debug with watch { /* - Runs npm run start. - proxy.conf is configured in angular.json => backend server needs to be started first => started in the script. + Runs the task 'Serve Frontend with Backend'. + proxy.conf is configured in angular.json => backend server needs to be started first => started in the task. Close all open Chrome instances if Chrome won't start. */ - "name": "Start frontend", + "name": "Serve frontend with backend", "type": "chrome", "request": "launch", "cwd": "${workspaceFolder}/frontend", - "preLaunchTask": "npm start frontend", + "preLaunchTask": "Serve Frontend with Backend", "url": "http://localhost:4200/", // proxy to 8080 for api calls "webRoot": "${workspaceFolder}", "sourceMapPathOverrides": { }, }, - // Test frontend - use for frontend unit test debug + // Test frontend- use for frontend unit test debug with watch { /* - Runs 'npm run test, i.e. ng test, first which compiles the front end and opens chrome and connects to the Karma runner, and THEN starts Chrome again and connects to the Karma runner. Debug should work on the second session. - Run 'npm run test' manually first if problems with preLaunch task. + Runs 'Test Frontend' task first, i.e. 'ng test:dev', which compiles the front end and opens Chrome and connects to the Karma runner, and THEN it starts Chrome again and connects to the Karma runner. Debug should work on the second session. + Run the preLaunch task manually first if problems. Close all open Chrome instances if Chrome won't start. */ "name": "Test frontend", "type": "chrome", "request": "launch", - "preLaunchTask": "npm test frontend", + "preLaunchTask": "Test Frontend", "runtimeExecutable": "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe", "runtimeArgs": [ "--remote-debugging-port=9222", @@ -60,24 +60,28 @@ "${workspaceFolder}/frontend/node_modules/**/*.js", ], }, - // Test e2e frontend - use for frontend e2e test debug + // e2e frontend with backend - use for frontend e2e test debug { - /* - Runs npm run e2e. - baseUrl is configured in protractor.conf to be localhost:8080 - backend server needs to be started first => started in script. - */ - "name": "Test e2e frontend", + /** + Runs e2e tests allowing VSCode debug. + NOTE: Protractor uses a configured baseUrl to point to the frontend server and the frontend server routes any backend calls to the same host with an added path (e.g. /api-v1). This does NOT use a proxy to redirect the backend calls, as ng e2e does, so the configured server must handle both frontend and backend calls. + NOTE: The frontend/backend server needs to be started first => a preLaunchTask starts the server and a postDebugTask closes it. + NOTE: This does NOT pre-compile the backend like ng e2e - the already-compiled front-end is used. Thus the already-compiled build must be compiled using the e2e enviroment file if you want to run the cache or error test files (whihc rely on e2e environment settings). + Choose .dev or .production configuration by editing args below. + Choose which spec files to run in the .env files. + */ + "name": "E2e frontend with backend", "type": "node", "request": "launch", "program": "${workspaceFolder}/frontend//node_modules/protractor/bin/protractor", "protocol": "inspector", "args": [ - /* choose which spec files to run in protractor.conf.js */ - "${workspaceFolder}/frontend/e2e/protractor.conf.js", + /* Edit here to choose the .dev or .production configuration file to run under .dev of .rpoduction environment settings */ + "${workspaceFolder}/frontend/e2e/src/config/protractor-production.conf.js", ], - "cwd": "${workspaceFolder}/frontend/e2e", + "cwd": "${workspaceFolder}/frontend", "preLaunchTask": "Check Server", + "postDebugTask": "Terminate All Tasks", "outputCapture": "std", "console": "integratedTerminal", "internalConsoleOptions": "neverOpen", @@ -97,7 +101,7 @@ "request": "launch", "name": "Run backend index.js", "program": "${workspaceFolder}/backend/src/index.ts", - "cwd": "${workspaceFolder}/backend", + "cwd": "${workspaceFolder}", "env": { }, "outputCapture": "std", @@ -131,8 +135,10 @@ "--silent" ], "port": 9229, - "cwd": "${workspaceFolder}/backend", - "env": {}, + "cwd": "${workspaceFolder}", + "env": { + // "NODE_ENV": "production", + }, "outputCapture": "std", "console": "integratedTerminal", // allows you use CTRL+C to exit "internalConsoleOptions": "neverOpen", @@ -200,20 +206,20 @@ /* comment out files to select tests */ "${workspaceFolder}/backend/dist/src/database/test/startDatabase.test.js", "${workspaceFolder}/backend/dist/src/database/test/database.test.js", - "${workspaceFolder}/backend/dist/src/models/test/*.test.js", + "${workspaceFolder}/backend/dist/src/models/test/models.test.js", "${workspaceFolder}/backend/dist/src/utils/test/dumpError.test.js", "${workspaceFolder}/backend/dist/src/utils/test/logger.test.js", "${workspaceFolder}/backend/dist/src/controllers/test/api-controller.test.js", "${workspaceFolder}/backend/dist/src/controllers/test/errors-controller.test.js", - "${workspaceFolder}/backend/dist/src/server/test/startserver-test.js", - "${workspaceFolder}/backend/dist/src/server/test/server-test.js", - "${workspaceFolder}/backend/dist/src/test/index-test.js", + "${workspaceFolder}/backend/dist/src/server/test/startserver.test.js", + "${workspaceFolder}/backend/dist/src/server/test/server.test.js", + "${workspaceFolder}/backend/dist/src/test/index.test.js", ], "env": { /* set to 'false' (or omit) to automatically run chrome and set to 'true' when using a compound configuration to launch chrome manually */ "DISABLE_CHROME": "false", }, - "cwd": "${workspaceFolder}/backend", + "cwd": "${workspaceFolder}", "outputCapture": "std", "console": "integratedTerminal", // allows you use CTRL+C to exit "internalConsoleOptions": "neverOpen", @@ -239,16 +245,16 @@ /* include testSetup.js */ "${workspaceFolder}/backend/dist/src/test/testSetup.js", /* comment out files to select tests */ - "${workspaceFolder}/backend/dist/src/database/test/startDatabase.test.js", - "${workspaceFolder}/backend/dist/src/database/test/database.test.js", - "${workspaceFolder}/backend/dist/src/models/test/*.test.js", - "${workspaceFolder}/backend/dist/src/utils/test/dumpError.test.js", - "${workspaceFolder}/backend/dist/src/utils/test/logger.test.js", - "${workspaceFolder}/backend/dist/src/controllers/test/api-controller.test.js", - "${workspaceFolder}/backend/dist/src/controllers/test/errors-controller.test.js", - "${workspaceFolder}/backend/dist/src/server/test/server-test.js", - "${workspaceFolder}/backend/dist/src/server/test/startserver-test.js", - "${workspaceFolder}/backend/dist/src/test/index-test.js", + // "${workspaceFolder}/backend/dist/src/database/test/startDatabase.test.js", + // "${workspaceFolder}/backend/dist/src/database/test/database.test.js", + // "${workspaceFolder}/backend/dist/src/models/test/*.test.js", + // "${workspaceFolder}/backend/dist/src/utils/test/dumpError.test.js", + // "${workspaceFolder}/backend/dist/src/utils/test/logger.test.js", + // "${workspaceFolder}/backend/dist/src/controllers/test/api-controller.test.js", + // "${workspaceFolder}/backend/dist/src/controllers/test/errors-controller.test.js", + // "${workspaceFolder}/backend/dist/src/server/test/server-test.js", + // "${workspaceFolder}/backend/dist/src/server/test/startserver-test.js", + // "${workspaceFolder}/backend/dist/src/test/index-test.js", ], "env": { @@ -257,7 +263,7 @@ /* set to 'false' (or omit) to automatically run chrome and set to 'true' when using a compound configuration to launch chrome manually */ "DISABLE_CHROME": "false", }, - "cwd": "${workspaceFolder}/backend", + "cwd": "${workspaceFolder}", "outputCapture": "std", "console": "integratedTerminal", // allows you use CTRL+C to exit "internalConsoleOptions": "neverOpen", @@ -292,7 +298,7 @@ /* set to 'true' to automatically run chrome and set to 'false' when using a compound configuration to launch chrome manually */ "DISABLE_CHROME": "false", }, - "cwd": "${workspaceFolder}/backend", + "cwd": "${workspaceFolder}", "outputCapture": "std", "console": "integratedTerminal", // allows you use CTRL+C to exit "internalConsoleOptions": "neverOpen", @@ -361,7 +367,7 @@ "type": "node", "request": "launch", "name": "Launch the currently opened .ts file", - "cwd": "${workspaceFolder}/backend", + "cwd": "${workspaceFolder}", "outputCapture": "std", "console": "integratedTerminal", "internalConsoleOptions": "neverOpen", @@ -395,7 +401,7 @@ "name": "Backend/ng serve", "configurations": [ "Run backend index.js", - "Start frontend", + "Serve frontend with backend", ] }, /* Run backend server and ng e2e - debug e2e */ @@ -404,7 +410,7 @@ "name": "Backend/ng e2e", "configurations": [ "Run backend index.js", - "Test e2e frontend", + "E2e frontend with backend", ] }, /* Mocha client tests backend/frontend */ diff --git a/.vscode/settings.json b/.vscode/settings.json index 94a8ed7..99faf73 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -34,6 +34,8 @@ "USIZ", "Vars", "WJLF", + "abcdefghijklmnopqrstuvwxyz", + "abecdefghijklmnopqrstuvwxyz", "admins", "applocals", "appname", @@ -50,6 +52,7 @@ "check", "cname", "codelyzer", + "color", "colorize", "cyclomatic", "daemonized", @@ -59,39 +62,82 @@ "devkit", "devtool", "dotenv", + "dynamodb", "eofline", "esbenp", "esnext", "etag", "favicon", "fdescribe", + "findup", "fkill", "forin", "format", "fullsetup", + "gcignore", + "gcloud", "gcloudignore", + "gconf", + "gmail", "inferrable", "jasminewd", + "jscoverage", + "jspm", "jsyaml", "jwks", "kjhtml", + "lcov", "lcovonly", + "lerna", + "libappindicator", + "libasound", + "libatk", + "libc", + "libdbus", + "libexpat", + "libgcc", + "libgconf", + "libgdk", + "libgtk", + "libnspr", + "libnss", + "libpango", + "libpangocairo", + "libstdc", + "libx", + "libxcb", + "libxcomposite", + "libxcursor", + "libxdamage", + "libxext", + "libxfixes", + "libxi", + "libxrandr", + "libxrender", + "libxss", + "libxtst", + "math", "mocha", "mocharc", "mongodb", "mwads", + "myscript", "nginx", "nomodule", "nopts", "nospace", "npmrc", "nreq", + "nuxt", "nycrc", "openapitools", "openet", "openid", + "packages", "parens", + "pids", "pings", + "pixbuf", "prettier", "prettierrc", "printf", @@ -114,6 +160,7 @@ "svma", "templating", "troj", + "tsbuildinfo", "tsscmp", "unindent", "unsubscribe", @@ -122,6 +169,8 @@ "uuidv", "vscode", "warmup", + "workdir", + "wscript", "wtfnode", "xdescribe", "xframe", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index b02b5fb..28154bb 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -4,14 +4,14 @@ "version": "2.0.0", "tasks": [ { - "label": "npm start frontend", + "label": "Serve Frontend with Backend", "type": "shell", "command": "npm", "args": [ "run", "--prefix", "${workspaceRoot}/frontend", - "start" + "serveWithBackend" ], "isBackground": true, "presentation": { @@ -44,14 +44,14 @@ } }, { - "label": "npm test frontend", + "label": "Test Frontend", "type": "shell", "command": "npm", "args": [ "run", "--prefix", "${workspaceRoot}/frontend", - "test" + "test:dev" ], "isBackground": true, "presentation": { @@ -107,7 +107,7 @@ { "label": "npm backend server-side watch", "type": "npm", - "script": "tscBackendServerWatch", + "script": "tscBackendWatch", "path": "backend/", "problemMatcher": [], "group": "build", @@ -232,6 +232,20 @@ }, "problemMatcher": [] }, + { + "label": "gcloudBuild.bat", + "type": "shell", + "windows": { + "command": "${workspaceFolder}/backend/utils-build/gcloudBuild.bat" + }, + "group": "test", + "presentation": { + "reveal": "always", + "focus": true, + "panel": "shared" + }, + "problemMatcher": [] + }, { "label": "Is Server Up?", "type": "shell", @@ -248,25 +262,19 @@ "focus": true, "panel": "dedicated" }, - "problemMatcher": [ - { - "pattern": [ - { - "regexp": ".", - "file": 1, - "location": 2, - "message": 3 - } - ], - "background": { - "activeOnStart": true, - "beginsPattern": { - "regexp": "(.*?)" - }, - "endsPattern": "Connected to" - } + "problemMatcher": { + "pattern": { + "regexp": ".", + "file": 1, + "location": 2, + "message": 3 + }, + "background": { + "activeOnStart": true, + "beginsPattern": ".", + "endsPattern": "Connected to", } - ] + } }, { "label": "Check Server", @@ -285,32 +293,33 @@ "panel": "dedicated" }, "group": "test", - "problemMatcher": [ - { - "pattern": [ - { - "regexp": ".", - "file": 1, - "location": 2, - "message": 3 - } - ], - "background": { - "activeOnStart": true, - "beginsPattern": { - "regexp": "(.*?)" - }, - "endsPattern": "Connected to" - } + "problemMatcher": { + "pattern": { + "regexp": ".", + "file": 1, + "location": 2, + "message": 3 + }, + "background": { + "activeOnStart": true, + "beginsPattern": ".", + "endsPattern": "Connected to", } - ] + } }, { - "type": "npm", - "script": "build:dev", - "path": "frontend/", - "group": "build", + "label": "Terminate All Tasks", + "command": "echo ${input:terminate}", + "type": "shell", "problemMatcher": [] } + ], + "inputs": [ + { + "id": "terminate", + "type": "command", + "command": "workbench.action.tasks.terminate", + "args": "terminateAll" + } ] } diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4980100 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,30 @@ +# use an image with node that also supports puppeteer */ +FROM 'gcr.io/project-perform/node12.13.0-with-puppeteer' + +# leave the image workdir as the base workdir +WORKDIR / + +# copy the local project files from the source environment to the image (relative to workdir). +COPY . . + +# install and build the backend +RUN npm install +RUN npm run build + +# change the workdir to the frontend directory, install and build the frontend +WORKDIR /frontend +RUN npm install +RUN npm run build:prod + +# return the workdir to root so can start server without changing directories e.g. from docker-compose, or during GCP App Engine start +WORKDIR / + +# expose 8080 port to allow access to a running backend server +EXPOSE 8080 + +# To run an npm script: +# do not chnage workdir to run a top-level package.json script +# set the workdir to '/frontend' to run a frontend package.json script +# pass in 'npm', 'run' '