forked from politics-rewired/switchboard-rewired
-
Notifications
You must be signed in to change notification settings - Fork 0
131 lines (116 loc) · 3.98 KB
/
ci-cd.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
name: CI/CD Pipeline
on:
push:
jobs:
hadolint:
runs-on: ubuntu-latest
name: 'Hadolint'
steps:
- uses: actions/checkout@v2
- uses: jbergstroem/hadolint-gh-action@v1
with:
error_level: 0
dockerfile: 'Dockerfile'
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version:
- 16.14.0-buster
container:
image: node:${{ matrix.node-version }}
services:
postgres:
image: registry.opensource.zalan.do/acid/spilo-14:2.1-p6
env:
ALLOW_NOSSL: 'true'
PGVERSION: '14'
SPILO_PROVIDER: local
PGUSER_SUPERUSER: postgres
PGPASSWORD_SUPERUSER: zalando
options: >-
--health-cmd "pg_isready"
--health-interval 10s
--health-timeout 5s
--health-retries 10
env:
NODE_ENV: test
BASE_URL: 'localhost:3000'
TEST_POSTGRES_URL: 'postgres://postgres:zalando@postgres:5432/postgres'
TWILIO_ACCOUNT_SID: ${{ secrets.TWILIO_ACCOUNT_SID }}
TWILIO_AUTH_TOKEN: ${{ secrets.TWILIO_AUTH_TOKEN }}
TELNYX_API_KEY: ${{ secrets.TELNYX_API_KEY }}
steps:
- name: checkout
uses: actions/checkout@v2
- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: node_modules
key: ${{ runner.os }}-node-${{ matrix.node-version }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-${{ matrix.node-version }}-yarn-
- run: yarn install
- name: Lint Apps
shell: bash
run: yarn test:lint
- name: Run migrations
shell: bash
run: yarn migrate:worker && yarn migrate up
- name: Run Tests
shell: bash
run: yarn test:unit
publish-docker-image:
if: startsWith( github.ref, 'refs/tags/v')
needs: test
name: Publish Docker image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
version: latest
# Caching strategy from: https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md#github-cache
- name: Cache Docker layers for ${{ matrix.service }}
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-switchboard-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-switchboard-
- name: Get image tags
id: image-tags
run: |
export GIT_SHA="${{ github.sha }}"
export GIT_SHA_SHORT=${GIT_SHA:0:7}
echo "::set-output name=sha::$GIT_SHA_SHORT"
export GIT_REF=${GITHUB_REF#refs/*/}
echo "$GIT_REF"
export SWITCHBOARD_VERSION=${GIT_REF#"v"}
echo "::set-output name=version::$SWITCHBOARD_VERSION"
- name: Login to GAR
uses: docker/login-action@v1
with:
registry: us-west1-docker.pkg.dev
username: _json_key
password: ${{ secrets.GCR_JSON_KEY }}
- name: Build and push ${{ matrix.service }}
id: docker_build
uses: docker/build-push-action@v2
with:
push: true
tags: |
us-west1-docker.pkg.dev/spoke-407503/switchboard/core:latest
us-west1-docker.pkg.dev/spoke-407503/switchboard/core:${{ steps.image-tags.outputs.version }}
us-west1-docker.pkg.dev/spoke-407503/switchboard/core:${{ steps.image-tags.outputs.sha }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache