-
Notifications
You must be signed in to change notification settings - Fork 11
296 lines (264 loc) · 10.9 KB
/
publish-docker-images.yml
File metadata and controls
296 lines (264 loc) · 10.9 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
name: Publish Docker Images
on: [push]
jobs:
build:
name: Build docker images
runs-on: ubuntu-20.04
steps:
- name: Check out the repo
uses: actions/checkout@v2
with:
submodules: 'recursive'
- name: Get commit SHA
id: sha
shell: bash
run: |
echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
echo "::set-output name=gitea_sha_short::$( git submodule foreach 'echo "$sha1"' \
| sed -n "/gitea/{N; p}" | sed '2q;d'| xargs git rev-parse --short )"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.CR_PAT }}
# to avoid being rate-limited
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_PAT }}
- name: Push frontend to GitHub Container Registry
uses: docker/build-push-action@v2
with:
context: ./frontend
file: ./frontend/Dockerfile.prod
push: true
tags: ghcr.io/kitspace/frontend:${{ steps.sha.outputs.sha_short }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Push processor to GitHub Container Registry
uses: docker/build-push-action@v2
with:
context: ./processor
file: ./processor/Dockerfile
push: true
tags: ghcr.io/kitspace/processor:${{ steps.sha.outputs.sha_short }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Push nginx to GitHub Container Registry
uses: docker/build-push-action@v2
with:
context: ./nginx
file: ./nginx/Dockerfile
push: true
tags: ghcr.io/kitspace/nginx:${{ steps.sha.outputs.sha_short }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Pull gitea image with current submodule SHA
shell: bash
run: docker pull ghcr.io/kitspace/gitea:${{ steps.sha.outputs.gitea_sha_short }}
continue-on-error: true
- name: Push gitea to GitHub Container Registry
# If the previous step failed, i.e., there's no image tagged
# gitea:${{gitea_sha_short}} in ghcr, build image and push it
if: ${{ failure() }}
uses: docker/build-push-action@v2
with:
context: ./gitea
file: ./gitea/Dockerfile
push: true
tags: ghcr.io/kitspace/gitea:${{ steps.sha.outputs.gitea_sha_short }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
deploy-pre-e2e-dev:
if: github.ref == 'refs/heads/dev'
name: Deploy pre-e2e-dev
runs-on: ubuntu-20.04
environment: staging
needs:
- build
steps:
- name: Check out the repo
uses: actions/checkout@v2
with:
submodules: 'recursive'
- name: Get commit SHA
id: sha
shell: bash
run: |
echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
echo "::set-output name=gitea_sha_short::$( git submodule foreach 'echo "$sha1"' \
| sed -n "/gitea/{N; p}" | sed '2q;d'| xargs git rev-parse --short )"
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.CR_PAT }}
# to avoid being rate-limited
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_PAT }}
- name: Deploy to dev.staging.kitspace.org
uses: kitspace/docker-remote-deployment-action@master
env:
POSTGRES_PASSWORD: ${{ secrets.STAGING_POSTGRES_ROOT_PASSWORD }}
GITEA_SECRET_KEY: ${{ secrets.STAGING_GITEA_SECRET }}
KITSPACE_DOMAIN: dev.staging.kitspace.org
KITSPACE_SCHEME: https
KITSPACE_DEV_PORT: '80'
CERTBOT_EMAIL: kaspar@kitspace.org
COMPOSE_PROJECT_NAME: kitspace-pre-e2e-dev
# Incremental static regeneration period(in seconds) for `/`
INDEX_ISR_INTERVAL: '3600'
# Incremental static regeneration period(in seconds) for `/projects/[user]`
USER_ISR_INTERVAL: '86400'
# The maximum allowable file size that can be uploaded to Gitea
MAX_FILE_SIZE: '6M'
FRONTEND_DEPLOY_IMAGE_TAG: ':${{ steps.sha.outputs.sha_short }}'
PROCESSOR_DEPLOY_IMAGE_TAG: ':${{ steps.sha.outputs.sha_short }}'
NGINX_DEPLOY_IMAGE_TAG: ':${{ steps.sha.outputs.sha_short }}'
GITEA_DEPLOY_IMAGE_TAG: ':${{ steps.sha.outputs.gitea_sha_short }}'
with:
remote_docker_host: deploy@staging.kitspace.org
ssh_private_key: ${{ secrets.STAGING_SSH_PRIVATE_KEY }}
ssh_public_key: ${{ secrets.STAGING_SSH_PUBLIC_KEY }}
stack_file_name: docker-compose.yml,docker-compose.deploy.yml
args: up -d
test:
name: Run e2e tests
runs-on: ubuntu-20.04
needs:
- build
steps:
- name: Check out the repo
uses: actions/checkout@v2
with:
submodules: 'recursive'
- name: Set environment variables
uses: c-py/action-dotenv-to-setenv@v2
with:
env-file: .env.example
- name: Get commit SHA
id: sha
shell: bash
run: |
echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
echo "::set-output name=gitea_sha_short::$( git submodule foreach 'echo "$sha1"' \
| sed -n "/gitea/{N; p}" | sed '2q;d'| xargs git rev-parse --short )"
- name: Configure /etc/hosts
shell: bash
run: cat ./config/hosts | sudo tee -a /etc/hosts
- name: Install Gitea
shell: bash
timeout-minutes: 5
env:
FRONTEND_DEPLOY_IMAGE_TAG: ':${{ steps.sha.outputs.sha_short }}'
PROCESSOR_DEPLOY_IMAGE_TAG: ':${{ steps.sha.outputs.sha_short }}'
GITEA_DEPLOY_IMAGE_TAG: ':${{ steps.sha.outputs.gitea_sha_short }}'
run: |
scripts/install_gitea.sh
- name: pre e2e
shell: bash
run: scripts/pre_e2e.sh
- name: e2e
uses: cypress-io/github-action@v2
env:
# pass the Dashboard record key as an environment variable
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
# pass GitHub token to allow accurately detecting a build vs a re-run build
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FRONTEND_DEPLOY_IMAGE_TAG: ${{ steps.sha.outputs.sha_short }}
PROCESSOR_DEPLOY_IMAGE_TAG: ${{ steps.sha.outputs.sha_short }}
GITEA_DEPLOY_IMAGE_TAG: ${{ steps.sha.outputs.gitea_sha_short }}
with:
start: docker-compose -f ../docker-compose.yml -f ../docker-compose.deploy.yml up
browser: chrome
command: yarn e2e --record
working-directory: frontend
# wait for 2 minutes for the server to respond
wait-on: 'http://kitspace.test:3000'
# This value is in seconds
wait-on-timeout: 120
publish:
name: Tag images with "latest"
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-20.04
needs:
- test
steps:
- name: Check out the repo
uses: actions/checkout@v2
with:
submodules: 'recursive'
- name: Get commit SHA
id: sha
shell: bash
run: |
echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
echo "::set-output name=gitea_sha_short::$( git submodule foreach 'echo "$sha1"' \
| sed -n "/gitea/{N; p}" | sed '2q;d'| xargs git rev-parse --short )"
- name: Tag frontend:latest
run: |
curl \
https://ghcr.io/v2/kitspace/frontend/manifests/${{ steps.sha.outputs.sha_short }} \
-H "Authorization: Bearer $(echo '${{ secrets.CR_PAT }}' | base64)" \
-H "Accept: application/vnd.docker.distribution.manifest.list.v2+json" \
> manifest.json
curl -X PUT \
https://ghcr.io/v2/kitspace/frontend/manifests/latest \
-H "Authorization: Bearer $(echo '${{ secrets.CR_PAT }}' | base64)" \
-H "Content-Type: application/vnd.docker.distribution.manifest.v2+json" \
-d '@manifest.json'
rm manifest.json
- name: Tag processor:latest
run: |
curl \
https://ghcr.io/v2/kitspace/processor/manifests/${{ steps.sha.outputs.sha_short }} \
-H "Authorization: Bearer $(echo '${{ secrets.CR_PAT }}' | base64)" \
-H "Accept: application/vnd.docker.distribution.manifest.list.v2+json" \
> manifest.json
curl -X PUT \
https://ghcr.io/v2/kitspace/processor/manifests/latest \
-H "Authorization: Bearer $(echo '${{ secrets.CR_PAT }}' | base64)" \
-H "Content-Type: application/vnd.docker.distribution.manifest.v2+json" \
-d '@manifest.json'
rm manifest.json
- name: Tag nginx:latest
run: |
curl \
https://ghcr.io/v2/kitspace/nginx/manifests/${{ steps.sha.outputs.sha_short }} \
-H "Authorization: Bearer $(echo '${{ secrets.CR_PAT }}' | base64)" \
-H "Accept: application/vnd.docker.distribution.manifest.list.v2+json" \
> manifest.json
curl -X PUT \
https://ghcr.io/v2/kitspace/nginx/manifests/latest \
-H "Authorization: Bearer $(echo '${{ secrets.CR_PAT }}' | base64)" \
-H "Content-Type: application/vnd.docker.distribution.manifest.v2+json" \
-d '@manifest.json'
rm manifest.json
- name: Tag gitea:latest
run: |
curl \
https://ghcr.io/v2/kitspace/gitea/manifests/${{ steps.sha.outputs.gitea_sha_short }} \
-H "Authorization: Bearer $(echo '${{ secrets.CR_PAT }}' | base64)" \
-H "Accept: application/vnd.docker.distribution.manifest.list.v2+json" \
> manifest.json
curl -X PUT \
https://ghcr.io/v2/kitspace/gitea/manifests/latest \
-H "Authorization: Bearer $(echo '${{ secrets.CR_PAT }}' | base64)" \
-H "Content-Type: application/vnd.docker.distribution.manifest.v2+json" \
-d '@manifest.json'
rm manifest.json