|
| 1 | +version: 2.1 |
| 2 | +orbs: |
| 3 | + gcp-gcr: circleci/[email protected] |
| 4 | + |
| 5 | + gcp-cli: circleci/[email protected] |
| 6 | + |
| 7 | +jobs: |
| 8 | + build: |
| 9 | + docker: |
| 10 | + - image: circleci/node:14.3.0 |
| 11 | + steps: |
| 12 | + - checkout |
| 13 | + - restore_cache: |
| 14 | + key: dependency-cache-{{ checksum "package-lock.json" }} |
| 15 | + - run: |
| 16 | + name: Install dependencies |
| 17 | + command: npm install |
| 18 | + - save_cache: |
| 19 | + key: dependency-cache-{{ checksum "package-lock.json" }} |
| 20 | + paths: |
| 21 | + - ./node_modules |
| 22 | + - run: |
| 23 | + name: Test |
| 24 | + command: npm run test -- --ci --reporters=default --reporters=jest-junit |
| 25 | + environment: |
| 26 | + - JEST_JUNIT_OUTPUT_DIR: ./test-results |
| 27 | + - store_test_results: |
| 28 | + path: ./test-results |
| 29 | + - run: |
| 30 | + name: Build |
| 31 | + command: npm run build |
| 32 | + - persist_to_workspace: |
| 33 | + root: . |
| 34 | + paths: |
| 35 | + - build |
| 36 | + build_and_push_docker: |
| 37 | + machine: true |
| 38 | + steps: |
| 39 | + - checkout |
| 40 | + - attach_workspace: |
| 41 | + at: . |
| 42 | + - gcp-gcr/build-image: |
| 43 | + image: $CIRCLE_PROJECT_REPONAME |
| 44 | + tag: $CIRCLE_SHA1 |
| 45 | + - gcp-gcr/gcr-auth |
| 46 | + - gcp-gcr/push-image: |
| 47 | + image: $CIRCLE_PROJECT_REPONAME |
| 48 | + tag: $CIRCLE_SHA1 |
| 49 | + secrets: |
| 50 | + docker: |
| 51 | + - image: ubuntu:20.04 |
| 52 | + steps: |
| 53 | + - checkout |
| 54 | + - run: |
| 55 | + name: Install git-crypt |
| 56 | + command: apt-get update -y && apt-get install -y git-crypt |
| 57 | + - run: |
| 58 | + name: Import GPG key |
| 59 | + command: echo $GPG_KEY | base64 -d > key.gpg && gpg --pinentry-mode loopback --passphrase $GPG_PASSPHRASE --allow-secret-key-import --import key.gpg && rm key.gpg |
| 60 | + - run: |
| 61 | + name: Trust ultimately key |
| 62 | + command: echo -e "5\ny\n" | gpg --command-fd 0 --expert --edit-key $GPG_FINGERPRINT trust; |
| 63 | + - run: |
| 64 | + name: Decrypt manually git-crypt key |
| 65 | + command: gpg --pinentry-mode loopback --passphrase $GPG_PASSPHRASE --decrypt ./.git-crypt/keys/default/0/$GPG_FINGERPRINT.gpg > ./.git-crypt/keys/default/0/decrypted.gpg |
| 66 | + - run: |
| 67 | + name: Unlock the secrets |
| 68 | + command: git-crypt unlock .git-crypt/keys/default/0/decrypted.gpg |
| 69 | + - persist_to_workspace: |
| 70 | + root: . |
| 71 | + paths: |
| 72 | + - helm/values |
| 73 | + deploy_helm: |
| 74 | + docker: |
| 75 | + - image: google/cloud-sdk |
| 76 | + steps: |
| 77 | + - checkout |
| 78 | + - attach_workspace: |
| 79 | + at: . |
| 80 | + - gcp-cli/initialize |
| 81 | + - run: |
| 82 | + name: Get cluster credentials |
| 83 | + command: gcloud container clusters get-credentials prod |
| 84 | + - helm/install-helm-client: |
| 85 | + version: v2.9.1 |
| 86 | + - run: |
| 87 | + name: Update Helm release |
| 88 | + command: helm upgrade $CIRCLE_PROJECT_REPONAME ./helm/$CIRCLE_PROJECT_REPONAME --namespace daily -f ./helm/values/prod.yaml --set-string image.tag=$CIRCLE_SHA1 -i |
| 89 | +workflows: |
| 90 | + build: |
| 91 | + jobs: |
| 92 | + - build |
| 93 | + - build_and_push_docker: |
| 94 | + requires: |
| 95 | + - build |
| 96 | + context: GCR |
| 97 | + filters: |
| 98 | + branches: |
| 99 | + ignore: /pull\/[0-9]+/ |
| 100 | + - secrets: |
| 101 | + context: GPG |
| 102 | + filters: |
| 103 | + branches: |
| 104 | + only: |
| 105 | + - master |
| 106 | + - deploy_helm: |
| 107 | + requires: |
| 108 | + - secrets |
| 109 | + - build_and_push_docker |
| 110 | + context: PROD |
| 111 | + filters: |
| 112 | + branches: |
| 113 | + only: |
| 114 | + - master |
| 115 | + - gcp-gcr/add-image-tag: |
| 116 | + requires: |
| 117 | + - build_and_push_docker |
| 118 | + context: GCR |
| 119 | + image: $CIRCLE_PROJECT_REPONAME |
| 120 | + source-tag: $CIRCLE_SHA1 |
| 121 | + target-tag: latest |
| 122 | + filters: |
| 123 | + branches: |
| 124 | + only: |
| 125 | + - master |
0 commit comments