From 6aaf05bacd8671aebe243c32e61caebd84e91658 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Wed, 25 Nov 2020 11:34:04 +0300 Subject: [PATCH 01/20] Initial setup. --- .gitlab-ci.yml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..a3bcbc3 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,7 @@ +job_1: + stage: stage_a + image: node:15-alpine3.10 + tags: + - docker + script: + - node --version From 13ac7fe77c65564de711cf0110a5ba56f066b27f Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Wed, 25 Nov 2020 11:49:35 +0300 Subject: [PATCH 02/20] Add install dependencies stage. --- .gitlab-ci.yml | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a3bcbc3..109cf59 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,23 @@ -job_1: - stage: stage_a +stages: + - install + +install_dependencies: + stage: install image: node:15-alpine3.10 tags: - docker script: - - node --version + - npm install + cache: + key: + files: + - package-lock.json + paths: + - node_modules + policy: pull + only: + refs: + - merge_requests + - master + changes: + - package-lock.json From 4091b04c03fabf7a85d27938dee71027be465108 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Wed, 25 Nov 2020 13:26:00 +0300 Subject: [PATCH 03/20] Add build and test stages. --- .gitlab-ci.yml | 55 +++++++++++++++++++++++++++++++++++++++++++++++ angular.json | 2 +- karma.conf.js | 27 ++++++++++++++++++----- package-lock.json | 18 ++++++++++++++++ package.json | 3 ++- 5 files changed, 98 insertions(+), 7 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 109cf59..6e88778 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,11 @@ stages: - install +variables: + PROJECT_PATH: "$CI_PROJECT_DIR" + APP_OUTPUT_PATH: "$CI_PROJECT_DIR/artifacts/app" + OUTPUT_PATH: "$CI_PROJECT_DIR/artifacts" + install_dependencies: stage: install image: node:15-alpine3.10 @@ -21,3 +26,53 @@ install_dependencies: - master changes: - package-lock.json + +build_app: + stage: build_and_test + image: node:15-alpine3.10 + tags: + - docker + script: + - ng build --prod + after_script: + - mv $PROJECT_PATH/nginx.conf $PROJECT_PATH/default.conf + - cp $PROJECT_PATH/default.conf $APP_OUTPUT_PATH + - cp $PROJECT_PATH/Dockerfile $APP_OUTPUT_PATH + artifacts: + name: "cic-staff-client-pipeline" + paths: + - $APP_OUTPUT_PATH + cache: + key: + files: + - package-lock.json + paths: + - node_modules + policy: pull + +test_app: + stage: build_and_test + image: node:15-alpine3.10 + tags: + - docker + before_script: + - apk add chromium + - export CHROME_BIN=/usr/bin/chromium-browser + script: + - ng lint + - ng test --code-coverage --watch=false --browsers=GitlabChromeHeadless + coverage: '/Statements\s+:\s\d+.\d+%/' + artifacts: + name: "tests-and-coverage" + reports: + junit: + - $OUTPUT_PATH/tests/junit-test-results.xml + cobertura: + - $OUTPUT_PATH/coverage/cobetura-coverage.xml + cache: + key: + files: + - package-lock.json + paths: + - node_modules + policy: pull diff --git a/angular.json b/angular.json index 3a0243d..b26b15f 100644 --- a/angular.json +++ b/angular.json @@ -17,7 +17,7 @@ "build": { "builder": "@angular-devkit/build-angular:browser", "options": { - "outputPath": "dist/cic-staff-client", + "outputPath": "artifacts/app", "index": "src/index.html", "main": "src/main.ts", "polyfills": "src/polyfills.ts", diff --git a/karma.conf.js b/karma.conf.js index a66327a..03148c5 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -7,6 +7,7 @@ module.exports = function (config) { frameworks: ['jasmine', '@angular-devkit/build-angular'], plugins: [ require('karma-jasmine'), + require('karma-junit-reporter'), require('karma-chrome-launcher'), require('karma-jasmine-html-reporter'), require('karma-coverage-istanbul-reporter'), @@ -16,17 +17,33 @@ module.exports = function (config) { clearContext: false // leave Jasmine Spec Runner output visible in browser }, coverageIstanbulReporter: { - dir: require('path').join(__dirname, './coverage/cic-staff-client'), - reports: ['html', 'lcovonly', 'text-summary'], - fixWebpackSourcePaths: true + dir: require('path').join(__dirname, './artifacts/coverage'), + reports: ['html', 'lcovonly', 'text-summary', 'cobertura'], + fixWebpackSourcePaths: true, + 'report-config': { + 'text-summary': { + file: 'text-summary.txt' + } + }, }, - reporters: ['progress', 'kjhtml'], + junitReporter: { + outputDir: 'artifacts/tests', + outputFile: 'junit-test-results.xml', + useBrowserName: false + }, + reporters: ['progress', 'kjhtml', 'junit'], port: 9876, colors: true, logLevel: config.LOG_INFO, autoWatch: true, browsers: ['Chrome'], singleRun: false, - restartOnFileChange: true + restartOnFileChange: true, + customLaunchers: { + GitlabHeadlessChrome: { + base: 'ChromeHeadless', + flags: ['--no-sandbox'], + }, + }, }); }; diff --git a/package-lock.json b/package-lock.json index 9f58aee..72d0a5c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7032,6 +7032,24 @@ "integrity": "sha512-PtilRLno5O6wH3lDihRnz0Ba8oSn0YUJqKjjux1peoYGwo0AQqrWRbdWk/RLzcGlb+onTyXAnHl6M+Hu3UxG/Q==", "dev": true }, + "karma-junit-reporter": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/karma-junit-reporter/-/karma-junit-reporter-2.0.1.tgz", + "integrity": "sha512-VtcGfE0JE4OE1wn0LK8xxDKaTP7slN8DO3I+4xg6gAi1IoAHAXOJ1V9G/y45Xg6sxdxPOR3THCFtDlAfBo9Afw==", + "dev": true, + "requires": { + "path-is-absolute": "^1.0.0", + "xmlbuilder": "12.0.0" + }, + "dependencies": { + "xmlbuilder": { + "version": "12.0.0", + "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-12.0.0.tgz", + "integrity": "sha512-lMo8DJ8u6JRWp0/Y4XLa/atVDr75H9litKlb2E5j3V3MesoL50EBgZDWoLT3F/LztVnG67GjPXLZpqcky/UMnQ==", + "dev": true + } + } + }, "karma-source-map-support": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/karma-source-map-support/-/karma-source-map-support-1.4.0.tgz", diff --git a/package.json b/package.json index df44760..a41143e 100644 --- a/package.json +++ b/package.json @@ -27,9 +27,9 @@ "@angular-devkit/build-angular": "~0.1002.0", "@angular/cli": "~10.2.0", "@angular/compiler-cli": "~10.2.0", - "@types/node": "^12.11.1", "@types/jasmine": "~3.5.0", "@types/jasminewd2": "~2.0.3", + "@types/node": "^12.11.1", "codelyzer": "^6.0.0", "jasmine-core": "~3.6.0", "jasmine-spec-reporter": "~5.0.0", @@ -38,6 +38,7 @@ "karma-coverage-istanbul-reporter": "~3.0.2", "karma-jasmine": "~4.0.0", "karma-jasmine-html-reporter": "^1.5.0", + "karma-junit-reporter": "^2.0.1", "protractor": "~7.0.0", "ts-node": "~8.3.0", "tslint": "~6.1.0", From 9327e15b449bf997eec4788d65c2e9f6fa90ed69 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Wed, 25 Nov 2020 13:28:46 +0300 Subject: [PATCH 04/20] Add build and test stage to stage declarations. --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6e88778..488ff47 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,6 @@ stages: - install + - build_and-test variables: PROJECT_PATH: "$CI_PROJECT_DIR" From 987f8edebeac6ac44d7ea345a90d2ccdad898bb0 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Wed, 25 Nov 2020 13:29:55 +0300 Subject: [PATCH 05/20] Refactor pipeline. --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 488ff47..e766a7f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,6 @@ stages: - install - - build_and-test + - build_and_test variables: PROJECT_PATH: "$CI_PROJECT_DIR" From 0745c3089dc0e15497a603b7f408766f55e3fd5b Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Wed, 25 Nov 2020 17:58:36 +0300 Subject: [PATCH 06/20] Add separate build and test stages. --- .gitlab-ci.yml | 52 ++++++++++++++++++++++++++++++++++++++++++++++++-- angular.json | 2 +- karma.conf.js | 4 ++-- 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e766a7f..b7da720 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,11 +1,14 @@ stages: - install - build_and_test + - build + - test variables: PROJECT_PATH: "$CI_PROJECT_DIR" - APP_OUTPUT_PATH: "$CI_PROJECT_DIR/artifacts/app" - OUTPUT_PATH: "$CI_PROJECT_DIR/artifacts" + APP_OUTPUT_PATH: "$CI_PROJECT_DIR/dist/cic-staff-client" + OUTPUT_PATH: "$CI_PROJECT_DIR/dist" + CLI_VERSION: 10.2.0 install_dependencies: stage: install @@ -41,6 +44,7 @@ build_app: - cp $PROJECT_PATH/Dockerfile $APP_OUTPUT_PATH artifacts: name: "cic-staff-client-pipeline" + expire_in: 30 days paths: - $APP_OUTPUT_PATH cache: @@ -77,3 +81,47 @@ test_app: paths: - node_modules policy: pull + +build: + stage: build + image: trion/ng-cli + tags: + - docker + before_script: + - npm ci + script: + - ng build --prod + artifacts: + expire_in: 1 days + paths: + - dist/cic-staff-client + +test:karma: + stage: test + image: trion/ng-cli-karma:$(CLI_VERSION) + allow_failure: false + tags: + - docker + script: + - ng test --code-coverage --progress false --watch false + coverage: '/Lines \W+: (\d+\.\d+)%.*/' + artifacts: + paths: + - coverage/ + +test:e2e: + stage: test + image: trion/ng-cli-e2e:$(CLI_VERSION) + allow_failure: false + tags: + - docker + script: + - ng e2e + +test:nglint: + stage: test + image: trion/ng-cli:$(CLI_VERSION) + tags: + - docker + script: + - ng lint diff --git a/angular.json b/angular.json index b26b15f..3a0243d 100644 --- a/angular.json +++ b/angular.json @@ -17,7 +17,7 @@ "build": { "builder": "@angular-devkit/build-angular:browser", "options": { - "outputPath": "artifacts/app", + "outputPath": "dist/cic-staff-client", "index": "src/index.html", "main": "src/main.ts", "polyfills": "src/polyfills.ts", diff --git a/karma.conf.js b/karma.conf.js index 03148c5..5eed447 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -17,7 +17,7 @@ module.exports = function (config) { clearContext: false // leave Jasmine Spec Runner output visible in browser }, coverageIstanbulReporter: { - dir: require('path').join(__dirname, './artifacts/coverage'), + dir: require('path').join(__dirname, './coverage/cic-staff-client'), reports: ['html', 'lcovonly', 'text-summary', 'cobertura'], fixWebpackSourcePaths: true, 'report-config': { @@ -27,7 +27,7 @@ module.exports = function (config) { }, }, junitReporter: { - outputDir: 'artifacts/tests', + outputDir: require('path').join(__dirname, './tests/cic-staff-client'), outputFile: 'junit-test-results.xml', useBrowserName: false }, From 259b06f87dbeab622fea08419ed7b08d280f365c Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Wed, 25 Nov 2020 18:01:42 +0300 Subject: [PATCH 07/20] Refactor ci pipeline. --- .gitlab-ci.yml | 90 +++++++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b7da720..fe4e0b2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,8 +1,8 @@ stages: - install - - build_and_test - build - test + - build_and_test variables: PROJECT_PATH: "$CI_PROJECT_DIR" @@ -31,6 +31,50 @@ install_dependencies: changes: - package-lock.json +build: + stage: build + image: trion/ng-cli + tags: + - docker + before_script: + - npm ci + script: + - ng build --prod + artifacts: + expire_in: 1 days + paths: + - dist/cic-staff-client + +test:karma: + stage: test + image: trion/ng-cli-karma:$(CLI_VERSION) + allow_failure: false + tags: + - docker + script: + - ng test --code-coverage --progress false --watch false + coverage: '/Lines \W+: (\d+\.\d+)%.*/' + artifacts: + paths: + - coverage/ + +test:e2e: + stage: test + image: trion/ng-cli-e2e:$(CLI_VERSION) + allow_failure: false + tags: + - docker + script: + - ng e2e + +test:nglint: + stage: test + image: trion/ng-cli:$(CLI_VERSION) + tags: + - docker + script: + - ng lint + build_app: stage: build_and_test image: node:15-alpine3.10 @@ -81,47 +125,3 @@ test_app: paths: - node_modules policy: pull - -build: - stage: build - image: trion/ng-cli - tags: - - docker - before_script: - - npm ci - script: - - ng build --prod - artifacts: - expire_in: 1 days - paths: - - dist/cic-staff-client - -test:karma: - stage: test - image: trion/ng-cli-karma:$(CLI_VERSION) - allow_failure: false - tags: - - docker - script: - - ng test --code-coverage --progress false --watch false - coverage: '/Lines \W+: (\d+\.\d+)%.*/' - artifacts: - paths: - - coverage/ - -test:e2e: - stage: test - image: trion/ng-cli-e2e:$(CLI_VERSION) - allow_failure: false - tags: - - docker - script: - - ng e2e - -test:nglint: - stage: test - image: trion/ng-cli:$(CLI_VERSION) - tags: - - docker - script: - - ng lint From 3f22b1ab1144cee163cf8db47cf843d392cb6e63 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Wed, 25 Nov 2020 19:53:41 +0300 Subject: [PATCH 08/20] Refactor cic pipeline. --- .gitlab-ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fe4e0b2..ee2cee7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -47,7 +47,7 @@ build: test:karma: stage: test - image: trion/ng-cli-karma:$(CLI_VERSION) + image: trion/ng-cli-karma allow_failure: false tags: - docker @@ -60,7 +60,7 @@ test:karma: test:e2e: stage: test - image: trion/ng-cli-e2e:$(CLI_VERSION) + image: trion/ng-cli-e2e allow_failure: false tags: - docker @@ -69,7 +69,7 @@ test:e2e: test:nglint: stage: test - image: trion/ng-cli:$(CLI_VERSION) + image: trion/ng-cli tags: - docker script: @@ -88,7 +88,7 @@ build_app: - cp $PROJECT_PATH/Dockerfile $APP_OUTPUT_PATH artifacts: name: "cic-staff-client-pipeline" - expire_in: 30 days + expire_in: 1 days paths: - $APP_OUTPUT_PATH cache: From 81d7a6540dceb3db62e751958b7243fc42856107 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Mon, 28 Dec 2020 13:31:35 +0300 Subject: [PATCH 09/20] Add docker setup. --- .dockerignore | 3 +++ .gitlab-ci.yml | 28 ++++++++++++++++++++++++++++ Dockerfile | 34 ++++++++++++++++++++++++++++++++++ nginx.conf | 8 ++++++++ 4 files changed, 73 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 nginx.conf diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5a9fb25 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.idea/ +dist/ +node_modules/ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ee2cee7..fc7de27 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -44,6 +44,13 @@ build: expire_in: 1 days paths: - dist/cic-staff-client + cache: + key: + files: + - package-lock.json + paths: + - node_modules + policy: pull test:karma: stage: test @@ -57,6 +64,13 @@ test:karma: artifacts: paths: - coverage/ + cache: + key: + files: + - package-lock.json + paths: + - node_modules + policy: pull test:e2e: stage: test @@ -66,6 +80,13 @@ test:e2e: - docker script: - ng e2e + cache: + key: + files: + - package-lock.json + paths: + - node_modules + policy: pull test:nglint: stage: test @@ -74,6 +95,13 @@ test:nglint: - docker script: - ng lint + cache: + key: + files: + - package-lock.json + paths: + - node_modules + policy: pull build_app: stage: build_and_test diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..550cbd0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +### STAGE 1: Build ### +# defining version of the base image +FROM node:15.1.0-alpine as build + +# defining work directory +WORKDIR /app + +# copying the json files into the image +COPY package*.json ./ + +RUN npm install + +# copying rest of project +COPY . . + +# running build script +RUN npm run build --prod + +### STAGE 2: Setup ### +# defining nginx image version +FROM nginx:1.19.4-alpine + +## Remove default nginx website +RUN rm -rf /usr/share/nginx/html/* + +# copy dist output from our first image +COPY --from=build /app/dist/cic-staff-client /usr/share/nginx/html + +# copy nginx configuration file +COPY nginx.conf /etc/nginx/conf.d/default.conf + +EXPOSE 80 443 + +CMD [ "nginx", "-g", "daemon off;" ] diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..1a12d7b --- /dev/null +++ b/nginx.conf @@ -0,0 +1,8 @@ +server { + listen 80; + location / { + root /usr/share/nginx/html; + index index.html index.htm; + try_files $uri $uri/ /index.html =404; + } +} From 5424de5d9ae00233458da76749466f069ad35415 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Mon, 28 Dec 2020 13:49:15 +0300 Subject: [PATCH 10/20] Refactor ci pipeline. --- .gitlab-ci.yml | 100 ++++++++++++++++++++++++------------------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fc7de27..ac6fcac 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -52,56 +52,56 @@ build: - node_modules policy: pull -test:karma: - stage: test - image: trion/ng-cli-karma - allow_failure: false - tags: - - docker - script: - - ng test --code-coverage --progress false --watch false - coverage: '/Lines \W+: (\d+\.\d+)%.*/' - artifacts: - paths: - - coverage/ - cache: - key: - files: - - package-lock.json - paths: - - node_modules - policy: pull - -test:e2e: - stage: test - image: trion/ng-cli-e2e - allow_failure: false - tags: - - docker - script: - - ng e2e - cache: - key: - files: - - package-lock.json - paths: - - node_modules - policy: pull - -test:nglint: - stage: test - image: trion/ng-cli - tags: - - docker - script: - - ng lint - cache: - key: - files: - - package-lock.json - paths: - - node_modules - policy: pull +#test:karma: +# stage: test +# image: trion/ng-cli-karma +# allow_failure: false +# tags: +# - docker +# script: +# - ng test --code-coverage --progress false --watch false +# coverage: '/Lines \W+: (\d+\.\d+)%.*/' +# artifacts: +# paths: +# - coverage/ +# cache: +# key: +# files: +# - package-lock.json +# paths: +# - node_modules +# policy: pull +# +#test:e2e: +# stage: test +# image: trion/ng-cli-e2e +# allow_failure: false +# tags: +# - docker +# script: +# - ng e2e +# cache: +# key: +# files: +# - package-lock.json +# paths: +# - node_modules +# policy: pull +# +#test:nglint: +# stage: test +# image: trion/ng-cli +# tags: +# - docker +# script: +# - ng lint +# cache: +# key: +# files: +# - package-lock.json +# paths: +# - node_modules +# policy: pull build_app: stage: build_and_test From 749fb67eee5a54201858a547fd898a8db9dd0195 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Mon, 28 Dec 2020 13:56:51 +0300 Subject: [PATCH 11/20] Refactor ci pipeline. --- .gitlab-ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ac6fcac..e952176 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -110,10 +110,10 @@ build_app: - docker script: - ng build --prod - after_script: - - mv $PROJECT_PATH/nginx.conf $PROJECT_PATH/default.conf - - cp $PROJECT_PATH/default.conf $APP_OUTPUT_PATH - - cp $PROJECT_PATH/Dockerfile $APP_OUTPUT_PATH +# after_script: +# - mv $PROJECT_PATH/nginx.conf $PROJECT_PATH/default.conf +# - cp $PROJECT_PATH/default.conf $APP_OUTPUT_PATH +# - cp $PROJECT_PATH/Dockerfile $APP_OUTPUT_PATH artifacts: name: "cic-staff-client-pipeline" expire_in: 1 days From d0642ad4d8e3aff2c8b58402a53dd1defccb7f67 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Mon, 28 Dec 2020 14:02:37 +0300 Subject: [PATCH 12/20] Add angular cli. --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e952176..00b3d5e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -16,6 +16,7 @@ install_dependencies: tags: - docker script: + - npm install -g @angular/cli - npm install cache: key: From 3088970adc4c34148afb6539962a0ba3f02eef49 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Mon, 28 Dec 2020 14:12:10 +0300 Subject: [PATCH 13/20] Refactor ci pipeline. --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 00b3d5e..cd74826 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -110,7 +110,7 @@ build_app: tags: - docker script: - - ng build --prod + - npm ng build --prod # after_script: # - mv $PROJECT_PATH/nginx.conf $PROJECT_PATH/default.conf # - cp $PROJECT_PATH/default.conf $APP_OUTPUT_PATH From 99a0c39eb70bbe06b6141b138ce03d0d5dfa4d72 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Mon, 28 Dec 2020 14:16:10 +0300 Subject: [PATCH 14/20] Refactor ci pipeline. --- .gitlab-ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cd74826..8a1b5f8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -111,10 +111,10 @@ build_app: - docker script: - npm ng build --prod -# after_script: -# - mv $PROJECT_PATH/nginx.conf $PROJECT_PATH/default.conf -# - cp $PROJECT_PATH/default.conf $APP_OUTPUT_PATH -# - cp $PROJECT_PATH/Dockerfile $APP_OUTPUT_PATH + after_script: + - mv $PROJECT_PATH/nginx.conf $PROJECT_PATH/default.conf + - cp $PROJECT_PATH/default.conf $APP_OUTPUT_PATH + - cp $PROJECT_PATH/Dockerfile $APP_OUTPUT_PATH artifacts: name: "cic-staff-client-pipeline" expire_in: 1 days @@ -137,8 +137,8 @@ test_app: - apk add chromium - export CHROME_BIN=/usr/bin/chromium-browser script: - - ng lint - - ng test --code-coverage --watch=false --browsers=GitlabChromeHeadless + - npm ng lint + - npm ng test --code-coverage --watch=false --browsers=GitlabChromeHeadless coverage: '/Statements\s+:\s\d+.\d+%/' artifacts: name: "tests-and-coverage" From 5e74238df22f21dbc3fb0d1fe13f333046b508b6 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Mon, 28 Dec 2020 14:23:16 +0300 Subject: [PATCH 15/20] Refactor ci pipeline. --- .gitlab-ci.yml | 113 +++++++++++++++++++++++++------------------------ 1 file changed, 58 insertions(+), 55 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8a1b5f8..738e016 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -34,17 +34,20 @@ install_dependencies: build: stage: build - image: trion/ng-cli + image: node:15-alpine3.10 tags: - docker - before_script: - - npm ci script: - - ng build --prod + - npm ng build --prod + after_script: + - mv $PROJECT_PATH/nginx.conf $PROJECT_PATH/default.conf + - cp $PROJECT_PATH/default.conf $APP_OUTPUT_PATH + - cp $PROJECT_PATH/Dockerfile $APP_OUTPUT_PATH artifacts: + name: "cic-staff-client-pipeline" expire_in: 1 days paths: - - dist/cic-staff-client + - $APP_OUTPUT_PATH cache: key: files: @@ -53,56 +56,56 @@ build: - node_modules policy: pull -#test:karma: -# stage: test -# image: trion/ng-cli-karma -# allow_failure: false -# tags: -# - docker -# script: -# - ng test --code-coverage --progress false --watch false -# coverage: '/Lines \W+: (\d+\.\d+)%.*/' -# artifacts: -# paths: -# - coverage/ -# cache: -# key: -# files: -# - package-lock.json -# paths: -# - node_modules -# policy: pull -# -#test:e2e: -# stage: test -# image: trion/ng-cli-e2e -# allow_failure: false -# tags: -# - docker -# script: -# - ng e2e -# cache: -# key: -# files: -# - package-lock.json -# paths: -# - node_modules -# policy: pull -# -#test:nglint: -# stage: test -# image: trion/ng-cli -# tags: -# - docker -# script: -# - ng lint -# cache: -# key: -# files: -# - package-lock.json -# paths: -# - node_modules -# policy: pull +test:karma: + stage: test + image: node:15-alpine3.10 + allow_failure: false + tags: + - docker + script: + - npm ng test --code-coverage --progress false --watch false + coverage: '/Lines \W+: (\d+\.\d+)%.*/' + artifacts: + paths: + - coverage/ + cache: + key: + files: + - package-lock.json + paths: + - node_modules + policy: pull + +test:e2e: + stage: test + image: node:15-alpine3.10 + allow_failure: false + tags: + - docker + script: + - npm ng e2e + cache: + key: + files: + - package-lock.json + paths: + - node_modules + policy: pull + +test:nglint: + stage: test + image: node:15-alpine3.10 + tags: + - docker + script: + - npm ng lint + cache: + key: + files: + - package-lock.json + paths: + - node_modules + policy: pull build_app: stage: build_and_test From 5549821f267b0aafdbd8bb1f616e9ea22d2861f6 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Mon, 28 Dec 2020 14:31:42 +0300 Subject: [PATCH 16/20] Refactor ci pipeline. --- .gitlab-ci.yml | 72 +++++++++----------------------------------------- 1 file changed, 13 insertions(+), 59 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 738e016..e660414 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,7 +2,8 @@ stages: - install - build - test - - build_and_test + +image: node:15-alpine3.10 variables: PROJECT_PATH: "$CI_PROJECT_DIR" @@ -12,7 +13,6 @@ variables: install_dependencies: stage: install - image: node:15-alpine3.10 tags: - docker script: @@ -34,7 +34,6 @@ install_dependencies: build: stage: build - image: node:15-alpine3.10 tags: - docker script: @@ -58,14 +57,22 @@ build: test:karma: stage: test - image: node:15-alpine3.10 allow_failure: false tags: - docker + before_script: + - apk add chromium + - export CHROME_BIN=/usr/bin/chromium-browser script: - - npm ng test --code-coverage --progress false --watch false - coverage: '/Lines \W+: (\d+\.\d+)%.*/' + - npm ng test --code-coverage --progress false --watch false --browsers=GitlabChromeHeadless + coverage: '/Statements\s+:\s\d+.\d+%/' artifacts: + name: "tests-and-coverage" + reports: + junit: + - $OUTPUT_PATH/tests/junit-test-results.xml + cobertura: + - $OUTPUT_PATH/coverage/cobetura-coverage.xml paths: - coverage/ cache: @@ -78,7 +85,6 @@ test:karma: test:e2e: stage: test - image: node:15-alpine3.10 allow_failure: false tags: - docker @@ -94,7 +100,6 @@ test:e2e: test:nglint: stage: test - image: node:15-alpine3.10 tags: - docker script: @@ -106,54 +111,3 @@ test:nglint: paths: - node_modules policy: pull - -build_app: - stage: build_and_test - image: node:15-alpine3.10 - tags: - - docker - script: - - npm ng build --prod - after_script: - - mv $PROJECT_PATH/nginx.conf $PROJECT_PATH/default.conf - - cp $PROJECT_PATH/default.conf $APP_OUTPUT_PATH - - cp $PROJECT_PATH/Dockerfile $APP_OUTPUT_PATH - artifacts: - name: "cic-staff-client-pipeline" - expire_in: 1 days - paths: - - $APP_OUTPUT_PATH - cache: - key: - files: - - package-lock.json - paths: - - node_modules - policy: pull - -test_app: - stage: build_and_test - image: node:15-alpine3.10 - tags: - - docker - before_script: - - apk add chromium - - export CHROME_BIN=/usr/bin/chromium-browser - script: - - npm ng lint - - npm ng test --code-coverage --watch=false --browsers=GitlabChromeHeadless - coverage: '/Statements\s+:\s\d+.\d+%/' - artifacts: - name: "tests-and-coverage" - reports: - junit: - - $OUTPUT_PATH/tests/junit-test-results.xml - cobertura: - - $OUTPUT_PATH/coverage/cobetura-coverage.xml - cache: - key: - files: - - package-lock.json - paths: - - node_modules - policy: pull From f9785c81c9168de74985b734707ca2142540997c Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Mon, 28 Dec 2020 14:38:34 +0300 Subject: [PATCH 17/20] Refactor ci pipeline. --- .gitlab-ci.yml | 44 ++++++++------------------------------------ 1 file changed, 8 insertions(+), 36 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e660414..3ef5efa 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,6 +3,14 @@ stages: - build - test +cache: + key: + files: + - package-lock.json + paths: + - node_modules + policy: pull + image: node:15-alpine3.10 variables: @@ -16,15 +24,7 @@ install_dependencies: tags: - docker script: - - npm install -g @angular/cli - npm install - cache: - key: - files: - - package-lock.json - paths: - - node_modules - policy: pull only: refs: - merge_requests @@ -47,13 +47,6 @@ build: expire_in: 1 days paths: - $APP_OUTPUT_PATH - cache: - key: - files: - - package-lock.json - paths: - - node_modules - policy: pull test:karma: stage: test @@ -75,13 +68,6 @@ test:karma: - $OUTPUT_PATH/coverage/cobetura-coverage.xml paths: - coverage/ - cache: - key: - files: - - package-lock.json - paths: - - node_modules - policy: pull test:e2e: stage: test @@ -90,13 +76,6 @@ test:e2e: - docker script: - npm ng e2e - cache: - key: - files: - - package-lock.json - paths: - - node_modules - policy: pull test:nglint: stage: test @@ -104,10 +83,3 @@ test:nglint: - docker script: - npm ng lint - cache: - key: - files: - - package-lock.json - paths: - - node_modules - policy: pull From 85d2f43b57aea7b12a8f840d7ae5aed81c17684c Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Mon, 28 Dec 2020 14:43:53 +0300 Subject: [PATCH 18/20] Bump docker images. --- .gitlab-ci.yml | 2 +- Dockerfile | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3ef5efa..f492b6a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,7 +11,7 @@ cache: - node_modules policy: pull -image: node:15-alpine3.10 +image: node:alpine variables: PROJECT_PATH: "$CI_PROJECT_DIR" diff --git a/Dockerfile b/Dockerfile index 550cbd0..1d8fa2a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ ### STAGE 1: Build ### # defining version of the base image -FROM node:15.1.0-alpine as build +FROM node:alpine as build # defining work directory WORKDIR /app @@ -18,7 +18,7 @@ RUN npm run build --prod ### STAGE 2: Setup ### # defining nginx image version -FROM nginx:1.19.4-alpine +FROM nginx:alpine ## Remove default nginx website RUN rm -rf /usr/share/nginx/html/* From 06e141d5197aa9746433842608d4af75573cfe88 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Mon, 28 Dec 2020 18:43:36 +0300 Subject: [PATCH 19/20] Add docker image packaging stage. --- .gitlab-ci.yml | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f492b6a..3feae9e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,13 +2,14 @@ stages: - install - build - test + - package cache: key: files: - package-lock.json paths: - - node_modules + - node_modules/ policy: pull image: node:alpine @@ -24,6 +25,7 @@ install_dependencies: tags: - docker script: + - npm install -g @angular/cli@$CLI_VERSION - npm install only: refs: @@ -83,3 +85,18 @@ test:nglint: - docker script: - npm ng lint + +docker-build: + image: docker:latest + stage: package + services: + - docker:dind + only: + - master + before_script: + - echo $CI_BUILD_TOKEN | docker login -u "$CI_REGISTRY_USER" + --password-stdin $CI_REGISTRY + script: + - IMAGE_NAME="$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME" + - docker build --pull -t "$IMAGE_NAME" -f Dockerfile . + - docker push "$IMAGE_NAME" From f17cc1dff3db23c40894a21b2be383f9046d9e17 Mon Sep 17 00:00:00 2001 From: Spencer Ofwiti Date: Mon, 28 Dec 2020 19:00:16 +0300 Subject: [PATCH 20/20] Refactor ci pipeline. --- .gitlab-ci.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3feae9e..fcd7d56 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -87,16 +87,16 @@ test:nglint: - npm ng lint docker-build: - image: docker:latest stage: package + image: docker:latest services: - docker:dind + variables: + IMAGE_TAG: "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHORT_SHA" + before_script: + - docker login -u $CI_DEPLOY_USER -p $CI_DEPLOY_PASSWORD $CI_REGISTRY + script: + - docker build -t $IMAGE_TAG -f Dockerfile . + - docker push $IMAGE_TAG only: - master - before_script: - - echo $CI_BUILD_TOKEN | docker login -u "$CI_REGISTRY_USER" - --password-stdin $CI_REGISTRY - script: - - IMAGE_NAME="$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME" - - docker build --pull -t "$IMAGE_NAME" -f Dockerfile . - - docker push "$IMAGE_NAME"