-
Notifications
You must be signed in to change notification settings - Fork 1
94 lines (82 loc) · 3.06 KB
/
cicd-datapipeline.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
name: CI/CD data processing pipeline
on:
push:
paths:
- "backend/src/main/resources/db/migration/**"
- ".github/workflows/cicd-database.yml"
- ".github/workflows/cicd-datapipeline.yml"
- "datascience/**"
- "infra/**"
- "Makefile"
schedule:
- cron: "38 11 */3 * *"
workflow_dispatch:
jobs:
build:
name: Build & test docker image
runs-on: ubuntu-22.04
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get last release version
id: lastrelease
uses: pozetroninc/github-action-get-latest-release@master
with:
repository: mtes-mct/monitorenv
- name: Set ENV_PROFILE as PROD when it is a release
if: startsWith(github.ref, 'refs/tags/v1') || startsWith(github.ref, 'refs/heads/v1') || startsWith(github.ref, 'refs/tags/v2') || startsWith(github.ref, 'refs/heads/v2')
run: echo "ENV_PROFILE=prod" >> $GITHUB_ENV
- name: Set VERSION
run: |
if [ "${ENV_PROFILE}" != "prod" ]; then\
if [ "${{github.ref}}" == "refs/heads/main" ]; then\
export VERSION=${{ steps.lastrelease.outputs.release }}_snapshot
else\
export REF_NAME=${{ github.ref_name }}
export VERSION=${REF_NAME//\//_}
fi
else\
export VERSION=${{ steps.lastrelease.outputs.release }}
fi
echo $VERSION
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@master
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache-pipeline
key: ${{ runner.os }}-single-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-single-buildx
- name: Build image
uses: docker/build-push-action@v6
with:
context: .
load: true
builder: ${{ steps.buildx.outputs.name }}
file: infra/docker/datapipeline/Dockerfile
push: false
tags: monitorenv-pipeline:${{ env.VERSION }}
cache-from: type=local,src=/tmp/.buildx-cache-pipeline
cache-to: type=local,dest=/tmp/.buildx-cache-pipeline-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-pipeline
mv /tmp/.buildx-cache-pipeline-new /tmp/.buildx-cache-pipeline
- name: Set DOCKER_GROUP
run: echo "DOCKER_GROUP=$(getent group docker | cut --delimiter=":" -f3)" >> $GITHUB_ENV
- name: Test docker image
run: make docker-test-pipeline
- name: Push docker image to registry
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${GITHUB_ACTOR} --password-stdin
make docker-tag-pipeline
make docker-push-pipeline