diff --git a/.circleci/config.ch4.yml b/.circleci/config.ch4.yml deleted file mode 100644 index 7de02f84..00000000 --- a/.circleci/config.ch4.yml +++ /dev/null @@ -1,42 +0,0 @@ -version: 2.1 -jobs: - build: - docker: - - image: circleci/node:lts-browsers - working_directory: ~/repo - steps: - - checkout - - - restore_cache: - keys: - - v1-dependencies-{{ checksum "package-lock.json" }} - - - run: npm ci - - # force update the webdriver, so it runs with latest version of Chrome - - run: cd ./node_modules/protractor && npm i webdriver-manager@latest - - # because we use "npm ci" to install NPM dependencies - # we cache "~/.npm" folder - - save_cache: - key: v1-dependencies-{{ checksum "package-lock.json" }} - paths: - - ~/.npm - - - run: npm run style - - run: npm run lint - - - run: npm run build:prod - - run: npm run test:coverage -- --watch=false - - run: npm run e2e - - - run: - name: Tar & Gzip compiled app - command: tar zcf dist.tar.gz dist/local-weather-app - - store_artifacts: - path: dist.tar.gz -workflows: - version: 2 - build-and-test: - jobs: - - build diff --git a/.circleci/config.ch9.yml b/.circleci/config.ch9.yml deleted file mode 100644 index 7c84332e..00000000 --- a/.circleci/config.ch9.yml +++ /dev/null @@ -1,85 +0,0 @@ -version: 2.1 -orbs: - coveralls: coveralls/coveralls@1.0.4 -jobs: - build: - docker: - - image: circleci/node:lts-browsers - working_directory: ~/repo - steps: - - checkout - - restore_cache: - keys: - - v1-dependencies-{{ checksum "package-lock.json" }} - # fallback to using the latest cache if no exact match is found - - v1-dependencies- - - - run: npm ci - - # force update the webdriver, so it runs with latest version of Chrome - - run: cd ./node_modules/protractor && npm i webdriver-manager@latest - - # because we use "npm ci" to install NPM dependencies - # we cache "~/.npm" folder - - save_cache: - paths: - - ~/.npm - key: v1-dependencies-{{ checksum "package-lock.json" }} - - - run: npm run style - - run: npm run lint - - - run: npm run build:prod - - run: npm run test:coverage -- --watch=false - - run: npm run e2e - - - store_test_results: - path: ./test_results - - store_artifacts: - path: ./coverage - - # upload coverage report to coveralls for readme badge support - # requires config.yml version 2.1 and orbs: coveralls: coveralls/coveralls@1.0.4 - # requires coveralls account and token named COVERALLS_REPO_TOKEN specific to repo to be stored in CircleCI - - coveralls/upload - - - run: - name: Tar & Gzip compiled app - command: tar zcf dist.tar.gz dist/local-weather-app - - store_artifacts: - path: dist.tar.gz - - - run: - name: Move compiled app to workspace - command: | - set -exu - mkdir -p /tmp/workspace/dist - mv dist/local-weather-app /tmp/workspace/dist/ - - persist_to_workspace: - root: /tmp/workspace - paths: - - dist/local-weather-app - deploy: - docker: - - image: circleci/node:lts - working_directory: ~/repo - steps: - - attach_workspace: - at: /tmp/workspace - - run: npx now --token $NOW_TOKEN --platform-version 2 --prod /tmp/workspace/dist/local-weather-app --confirm - -workflows: - version: 2 - build-test-and-approval-deploy: - jobs: - - build - - hold: - type: approval - requires: - - build - filters: - branches: - only: master - - deploy: - requires: - - hold diff --git a/.circleci/config.yml b/.circleci/config.yml index 57e3a377..ce02efbb 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,71 +1,44 @@ version: 2.1 orbs: - coveralls: coveralls/coveralls@1.0.4 -commands: - install: - description: 'Install project dependencies' - parameters: - warm-cache: - type: boolean - default: false + cloudrun: circleci/gcp-cloud-run@1.0.2 +jobs: + build: + docker: + - image: circleci/node:lts-browsers + working_directory: ~/repo steps: - checkout - restore_cache: keys: - - node_modules-{{ checksum "package-lock.json" }} - - when: - condition: << parameters.warm-cache >> - steps: - - run: npm install - # Pre-build Angular modules - - run: npx ngcc --properties es2015 --async false # async false is temp CI build fix - # force update the webdriver, so it runs with latest version of Chrome - - run: cd ./node_modules/protractor && npm i webdriver-manager@latest - - save_cache: - key: node_modules-{{ checksum "package-lock.json" }} - paths: - - node_modules - lint: - description: 'Check for code style and linting errors' - steps: + - v1-dependencies-{{ checksum "package-lock.json" }} + # fallback to using the latest cache if no exact match is found + - v1-dependencies- + + - run: npm ci + + # force update the webdriver, so it runs with latest version of Chrome + - run: cd ./node_modules/protractor && npm i webdriver-manager@latest + + # because we use "npm ci" to install NPM dependencies + # we cache "~/.npm" folder + - save_cache: + paths: + - ~/.npm + key: v1-dependencies-{{ checksum "package-lock.json" }} + - run: npm run style - run: npm run lint - build_and_test: - description: 'Build command that accepts Angular project name as parameter' - parameters: - project: - type: string - default: 'local-weather-app' - run-tests: - type: boolean - default: true - steps: - - run: npx ng build --prod --project << parameters.project >> - - when: - condition: << parameters.run-tests >> - steps: - - run: npx ng test --code-coverage --watch=false --project << parameters.project >> - - run: npx ng e2e << parameters.project >> - store: - description: 'Stores build_and_test artifacts' - parameters: - project: - type: string - default: 'local-weather-app' - steps: + + - run: npx ng build ch6 --prod + - run: npx ng test --watch=false --project ch6 + - run: npx ng e2e --project ch6 + - store_test_results: path: ./test_results - - store_artifacts: - path: ./coverage - - # upload coverage report to coveralls for readme badge support - # requires config.yml version 2.1 and orbs: coveralls: coveralls/coveralls@1.0.4 - # requires coveralls account and token named COVERALLS_REPO_TOKEN specific to repo to be stored in CircleCI - - coveralls/upload - run: name: Tar & Gzip compiled app - command: tar zcf dist.tar.gz dist/<< parameters.project >> + command: tar zcf dist.tar.gz dist/ch6 - store_artifacts: path: dist.tar.gz @@ -74,127 +47,48 @@ commands: command: | set -exu mkdir -p /tmp/workspace/dist - mv dist/<< parameters.project >> /tmp/workspace/dist/ + mv dist/ch6 /tmp/workspace/dist/ - persist_to_workspace: root: /tmp/workspace paths: - - dist/<< parameters.project >> - deploy_now: - description: 'Deploys project to Zeit Now --> https://now.sh' - parameters: - project: - type: string - default: 'local-weather-app' - steps: - - attach_workspace: - at: /tmp/workspace - - run: npx now --token $NOW_TOKEN --platform-version 2 --prod /tmp/workspace/dist/<< parameters.project >> --confirm -jobs: - initialize: - docker: - - image: circleci/node:lts-browsers - working_directory: ~/repo - steps: - - install: - warm-cache: true - default: + - dist/ch6 + deploy_cloudrun: docker: - - image: circleci/node:lts-browsers - working_directory: ~/repo - steps: - - install - - lint - - build_and_test - - store - deploy: - docker: - - image: circleci/node:lts + - image: 'cimg/base:stable' working_directory: ~/repo steps: - - deploy_now + - attach_workspace: + at: /tmp/workspace + - checkout + - run: + name: Copy built app to dist folder + command: cp -avR /tmp/workspace/dist/ . + - cloudrun/init + - cloudrun/build: + tag: 'gcr.io/${GOOGLE_PROJECT_ID}/test-${CIRCLE_SHA1}' + source: ~/repo + - cloudrun/deploy: + image: 'gcr.io/${GOOGLE_PROJECT_ID}/test-${CIRCLE_SHA1}' + platform: managed + region: us-east1 + service-name: localcast-weather + unauthenticated: true + - run: + command: > + GCP_API_RESULTS=$(curl -s "$GCP_DEPLOY_ENDPOINT") - ch2: # this job is only here to verify sample code from the book, remove it in your own projects - docker: - - image: circleci/node:lts-browsers - working_directory: ~/repo - steps: - - install - - build_and_test: - project: 'ch2' - ch3: # this job is only here to verify sample code from the book, remove it in your own projects - docker: - - image: circleci/node:lts-browsers - working_directory: ~/repo - steps: - - install - - build_and_test: - project: 'ch3' - run-tests: false - ch4: # this job is only here to verify sample code from the book, remove it in your own projects - docker: - - image: circleci/node:lts-browsers - working_directory: ~/repo - steps: - - install - - build_and_test: - project: 'ch4' - ch5: # this job is only here to verify sample code from the book, remove it in your own projects - docker: - - image: circleci/node:lts-browsers - working_directory: ~/repo - steps: - - install - - build_and_test: - project: 'ch5' - ch6: # this job is only here to verify sample code from the book, remove it in your own projects - docker: - - image: circleci/node:lts-browsers - working_directory: ~/repo - steps: - - install - - build_and_test: - project: 'ch6' - ch12: # this job is only here to verify sample code from the book, remove it in your own projects - docker: - - image: circleci/node:lts-browsers - working_directory: ~/repo - steps: - - install - - build_and_test: - project: 'ch12' + if ! echo "$GCP_API_RESULTS" | grep -nwo "LocalCast Weather"; then + echo "Result is unexpected" + echo 'Result: ' + curl -s "$GCP_DEPLOY_ENDPOINT" + exit 1; + fi + name: Test managed deployed service. workflows: version: 2 - build-test-and-approval-deploy: + build-test-and-deploy: jobs: - - initialize - - default: - requires: - - initialize - - ch2: # this job is only here to verify sample code from the book, remove it in your own projects - requires: - - initialize - - ch3: # this job is only here to verify sample code from the book, remove it in your own projects - requires: - - initialize - - ch4: # this job is only here to verify sample code from the book, remove it in your own projects - requires: - - initialize - - ch5: # this job is only here to verify sample code from the book, remove it in your own projects - requires: - - initialize - - ch6: # this job is only here to verify sample code from the book, remove it in your own projects - requires: - - initialize - # - ch12: # this job is only here to verify sample code from the book, remove it in your own projects - # requires: - # - initialize - - hold: - type: approval - requires: - - default - filters: - branches: - only: master - - deploy: + - build + - deploy_cloudrun: requires: - - hold + - build diff --git a/Dockerfile b/Dockerfile index d81752f4..6a0d9e50 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM duluca/minimal-node-web-server:lts-alpine WORKDIR /usr/src/app -COPY dist/local-weather-app public +COPY dist/ch6 public #Overriding default ENTRYPOINT because gcloud doesn't like dumb-init ENTRYPOINT [ "npm", "start" ]