-
-
Notifications
You must be signed in to change notification settings - Fork 3
177 lines (151 loc) · 5.67 KB
/
Copy pathdocker.yml
File metadata and controls
177 lines (151 loc) · 5.67 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
name: Docker Build & Publish
on:
push:
branches: [develop]
release:
types: [published]
workflow_dispatch:
inputs:
branch:
description: "Branch to build from"
required: false
default: develop
env:
REGISTRY: ghcr.io
jobs:
prepare-tags-and-names:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ github.event.inputs.branch || github.ref }}
- name: Derive version
id: version
run: |
if [ "${{ github.event_name }}" = "release" ]; then
VERSION="${{ github.event.release.tag_name }}"
else
VERSION="$(git describe --tags --always 2>/dev/null || echo 'v0.0.0-dev')"
fi
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "sha_short=$(echo '${{ github.sha }}' | cut -c1-7)" >> "$GITHUB_OUTPUT"
- name: Sanitize version for Docker tag
id: sanitize
run: |
VERSION="${{ steps.version.outputs.version }}"
SANITIZED="$(echo "$VERSION" | sed 's/[^a-zA-Z0-9_.-]/-/g')"
SANITIZED="$(echo "$SANITIZED" | sed 's/^[^a-zA-Z0-9_]\+//')"
echo "sanitized_tag=${SANITIZED:0:128}" >> "$GITHUB_OUTPUT"
- name: Normalize repository name
id: repo
uses: actions/github-script@v7
with:
result-encoding: string
script: return `${context.repo.owner}/${context.repo.repo}`.toLowerCase()
outputs:
version: ${{ steps.version.outputs.version }}
sha_short: ${{ steps.version.outputs.sha_short }}
sanitized_tag: ${{ steps.sanitize.outputs.sanitized_tag }}
repository: ${{ steps.repo.outputs.result }}
build-and-push:
runs-on: ${{ matrix.runner }}
needs: prepare-tags-and-names
strategy:
fail-fast: false
matrix:
service:
- name: frontend
image: librislog
dockerfile: ./frontend/Dockerfile
context: ./frontend
- name: backend
image: librislog-api
dockerfile: ./backend/Dockerfile
context: ./backend
arch: [amd64, arm64]
include:
- arch: amd64
runner: ubuntu-latest
- arch: arm64
runner: ubuntu-24.04-arm
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ github.event.inputs.branch || github.ref }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate image tags
id: tags
run: |
IMAGE="${{ env.REGISTRY }}/${{ needs.prepare-tags-and-names.outputs.repository }}/${{ matrix.service.image }}"
SHA_SHORT="${{ needs.prepare-tags-and-names.outputs.sha_short }}"
if [ "${{ github.event_name }}" = "release" ]; then
SANITIZED="${{ needs.prepare-tags-and-names.outputs.sanitized_tag }}"
TAGS="${IMAGE}:${SANITIZED}-${{ matrix.arch }},${IMAGE}:latest-${{ matrix.arch }}"
else
TAGS="${IMAGE}:develop-${{ matrix.arch }},${IMAGE}:${SHA_SHORT}-${{ matrix.arch }}"
fi
echo "tags=${TAGS}" >> "$GITHUB_OUTPUT"
- name: Build and push
uses: docker/build-push-action@v7
with:
context: ${{ matrix.service.context }}
file: ${{ matrix.service.dockerfile }}
push: true
platforms: linux/${{ matrix.arch }}
tags: ${{ steps.tags.outputs.tags }}
build-args: |
APP_VERSION=${{ needs.prepare-tags-and-names.outputs.version }}
GIT_SHA=${{ github.sha }}
${{ matrix.service.name == 'frontend' && 'PUBLIC_DEFAULT_LOCALE=en' || '' }}
cache-from: type=gha
cache-to: type=gha,mode=max
create-manifest:
needs: [prepare-tags-and-names, build-and-push]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
service:
- name: frontend
image: librislog
- name: backend
image: librislog-api
permissions:
packages: write
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create multi-arch manifest
run: |
IMAGE="${{ env.REGISTRY }}/${{ needs.prepare-tags-and-names.outputs.repository }}/${{ matrix.service.image }}"
SHA_SHORT="${{ needs.prepare-tags-and-names.outputs.sha_short }}"
if [ "${{ github.event_name }}" = "release" ]; then
SANITIZED="${{ needs.prepare-tags-and-names.outputs.sanitized_tag }}"
docker buildx imagetools create -t "${IMAGE}:${SANITIZED}" "${IMAGE}:${SANITIZED}-amd64" "${IMAGE}:${SANITIZED}-arm64"
docker buildx imagetools create -t "${IMAGE}:latest" "${IMAGE}:latest-amd64" "${IMAGE}:latest-arm64"
else
docker buildx imagetools create -t "${IMAGE}:develop" "${IMAGE}:develop-amd64" "${IMAGE}:develop-arm64"
docker buildx imagetools create -t "${IMAGE}:${SHA_SHORT}" "${IMAGE}:${SHA_SHORT}-amd64" "${IMAGE}:${SHA_SHORT}-arm64"
fi