generated from EPFL-ENAC/it4r-webmap
-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (93 loc) · 3.16 KB
/
build-and-push.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
# https://github.com/EPFL-ENAC/epfl-enac-deploy-action#readme
name: build-push-deploy
"on":
push:
branches:
- dev
- main
tags: [ 'v*.*.*' ]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{github.repository}}
jobs:
build-and-push-image:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- Dockerfile: ./Dockerfile
context: ./
image: ghcr.io/epfl-enac/sxl-recrete-atlas-frontend
permissions:
contents: read
packages: write
outputs:
github_sha: ${{ github.sha }}
digest: ${{ steps.build-docker-push.outputs.digest}}
tags: ${{ steps.meta.outputs.tags }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ matrix.image }}
- name: Build and push Docker image EPFL-ENAC.Agent.Service
id: build-docker-push
uses: docker/build-push-action@v5
with:
context: ${{ matrix.context }}
push: true
file: ${{ matrix.dockerfile }}
tags: ${{ steps.meta.outputs.tags }},${{ matrix.image }}:${{ github.sha }},${{ matrix.image }}:latest
labels: ${{ steps.meta.outputs.labels }}
deploy:
needs: build-and-push-image
runs-on: ubuntu-latest
steps:
- name: what's the git ref
run: echo ${{ github.ref }} // ${{ github.ref_name }}
# This is used to trigger the correct github CI pipeline:
# push to main: update dev deployment
# push a tag: update stage, trigger prod merge req.
- name: Deploy application to dev
if: startsWith(github.ref, 'refs/heads/dev')
run: |
echo "Deploying application to dev" && \
echo "Digest: ${{ toJson(needs.build-and-push-image) }}" && \
curl -X POST \
-H "Authorization: Bearer ${{ secrets.CD_TOKEN }}" \
${{ secrets.CD_URI }} \
-d '{
"event_type": "update-manifest",
"client_payload": {
"digest": "${{ needs.build-and-push-image.outputs.digest }}",
"repo_name": "${{ secrets.CD_REPO }}",
"repo_org": "${{ secrets.CD_ORG }}",
"branch": "dev"
}
}'
- name: Deploy to prod rules (defined in CD pipeline)
if: startsWith(github.ref, 'refs/tags/')
run: |
curl -X POST \
-H "Authorization: Bearer ${{ secrets.CD_TOKEN }}" \
${{ secrets.CD_URI }} \
-d '{
"event_type": "update-manifest",
"client_payload": {
"digest": "${{ needs.build-and-push-image.outputs.digest }}",
"repo_name": "${{ secrets.CD_REPO }}",
"repo_org": "${{ secrets.CD_ORG }}",
"branch": "prod",
"ref_name": "${{ github.ref_name }}"
}
}'