-
Notifications
You must be signed in to change notification settings - Fork 0
87 lines (76 loc) · 2.99 KB
/
ci.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
name: 🤓 GH Action 🚧
on:
pull_request:
push:
branches:
- main
jobs:
build_test:
name: 🚴 Build + Test 🚴 # Match the name below (8398a7/action-slack).
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v2
- name: Log in to registry
# This is where you will update the personal access token to GITHUB_TOKEN
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
- name: 🐳 Prepare Docker
id: prep
run: |
TAG=$(echo $GITHUB_SHA | head -c7)
IMAGE="ghcr.io/ifrcgo/go-risk-module-api"
echo "tagged_image=${IMAGE}:${TAG}" >> $GITHUB_OUTPUT
echo "tag=${TAG}" >> $GITHUB_OUTPUT
- name: 🐳 Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@master
- name: 🐳 Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.ref }}
restore-keys: |
${{ runner.os }}-buildx-refs/develop
${{ runner.os }}-buildx-
- name: 🐳 Docker build
uses: docker/build-push-action@v4
with:
context: .
builder: ${{ steps.buildx.outputs.name }}
file: Dockerfile
load: true
tags: ${{ steps.prep.outputs.tagged_image }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: 🕮 Validate if there are no pending django migrations.
env:
DOCKER_IMAGE_SERVER: ${{ steps.prep.outputs.tagged_image }}
run: |
docker-compose -f ./gh-docker-compose.yml run --rm server bash -c 'wait-for-it db:5432 && ./manage.py makemigrations --check --dry-run' || {
echo 'There are some changes to be reflected in the migration. Make sure to run makemigrations';
exit 1;
}
- name: Validate SentryMonitor config
env:
DOCKER_IMAGE_SERVER: ${{ steps.prep.outputs.tagged_image }}
run: |
docker-compose -f ./gh-docker-compose.yml run --rm server ./manage.py setup_sentry_cron_monitor --validate-only || {
echo 'There are some changes to be reflected in the SentryMonitor. Make sure to update SentryMonitor';
exit 1;
}
- name: 🐳 Docker push
if: github.event_name == 'push'
uses: docker/build-push-action@v4
with:
tags: ${{ steps.prep.outputs.tagged_image }}
push: true
# Temp fix
# https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md#github-cache
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: 🐳 Move docker cache (🧙 Hack fix)
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache