Skip to content
Open
42 changes: 0 additions & 42 deletions .circleci/config.ch4.yml

This file was deleted.

85 changes: 0 additions & 85 deletions .circleci/config.ch9.yml

This file was deleted.

230 changes: 62 additions & 168 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]