-
Notifications
You must be signed in to change notification settings - Fork 7
118 lines (106 loc) · 5.3 KB
/
build-publish-docker.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
name: Build and Publish Docker Image
on:
push:
paths-ignore:
- 'operations/deployments/openstad-headless/environments/acc/images.yml'
branches:
- '**'
tags:
- "v*"
jobs:
# define job to build and publish docker image
build-and-push-docker-image:
strategy:
matrix:
app: [admin-server, api-server, auth-server, image-server, cms-server]
include:
- app: api-server
build-target: release-with-packages
name: '[${{ matrix.app }}] Build & push image'
runs-on: ubuntu-latest
outputs:
image_tag: ${{ steps.image_output.outputs.image_tag }}
env:
IMAGE: '${{ github.repository_owner }}/${{ matrix.app }}'
APP: ${{ matrix.app }}
BUILD_TARGET: release
steps:
- name: Checkout code
uses: actions/checkout@v3
- if: ${{ matrix.build-target }}
name: Set correct build target
run: echo "BUILD_TARGET=${{ matrix.build-target}}" >> $GITHUB_ENV
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE }}
tags: |
# branch event
type=ref,event=branch,suffix=-{{sha}}
# tag event
type=ref,event=tag
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build image and push to GitHub Container Registry
id: docker_build
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: 'ghcr.io/${{ steps.meta.outputs.tags }}'
build-args: |
APP=${{ matrix.app }}
- name: Add image output
id: image_output
run: echo "image_tag=${{ steps.meta.outputs.version }}" >> "$GITHUB_OUTPUT"
set-images-in-yaml-and-commit:
name: Set images in yaml and commit
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs: build-and-push-docker-image
env:
SOPS_AGE_KEY: ${{ secrets.SOPS_AGE_KEY }}
SOPS_AGE_KEY_FILE: headless.agekey
SOPS_AGE_RECIPIENTS: age1pnz2leuqnfhyt9qpxjjcjs9xe9ys8xjkjn9m656wygy3ndfxya0q6kthy8
# Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest
defaults:
run:
shell: bash
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
persist-credentials: false
- name: Install yq
run: sudo snap install yq --channel=v4/stable
- name: Set images and commit
run: |
git config --global user.email [email protected] && \
git config --global user.name "Github action" && \
git remote set-url origin https://${{ secrets.GH_COMMIT_PAT }}@github.com/${{ github.repository }}.git && \
/snap/bin/yq -i '.admin.deploymentContainer.image = "ghcr.io/${{ github.repository_owner }}/admin-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}"' ./operations/deployments/openstad-headless/environments/acc/images.yml && \
/snap/bin/yq -i '.api.deploymentContainer.image = "ghcr.io/${{ github.repository_owner }}/api-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}"' ./operations/deployments/openstad-headless/environments/acc/images.yml && \
/snap/bin/yq -i '.cms.deploymentContainer.image = "ghcr.io/${{ github.repository_owner }}/cms-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}"' ./operations/deployments/openstad-headless/environments/acc/images.yml && \
/snap/bin/yq -i '.auth.deploymentContainer.image = "ghcr.io/${{ github.repository_owner }}/auth-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}"' ./operations/deployments/openstad-headless/environments/acc/images.yml && \
/snap/bin/yq -i '.image.deploymentContainer.image = "ghcr.io/${{ github.repository_owner }}/image-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}"' ./operations/deployments/openstad-headless/environments/acc/images.yml && \
git add operations/deployments/openstad-headless/environments/acc/images.yml && \
git commit -m "ci: release ${{ needs.build-and-push-docker-image.outputs.image_tag }}" && \
git push origin main
- name: Display images in Github Action
run: |
echo "**New images 🐳**
| App | Image |
|---|---|
| admin-server | \`ghcr.io/${{ github.repository_owner}}/admin-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}\` |
| api-server | \`ghcr.io/${{ github.repository_owner}}/api-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}\` |
| cms-server | \`ghcr.io/${{ github.repository_owner}}/cms-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}\` |
| auth-server | \`ghcr.io/${{ github.repository_owner}}/auth-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}\` |
| image-server | \`ghcr.io/${{ github.repository_owner}}/image-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}\` |" >> $GITHUB_STEP_SUMMARY