-
Notifications
You must be signed in to change notification settings - Fork 180
168 lines (149 loc) · 5.35 KB
/
docker-publish.yml
File metadata and controls
168 lines (149 loc) · 5.35 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
name: Publish Docker Images
on:
release:
types: [published]
push:
branches: [main]
paths:
- "*.Dockerfile"
- "apps/**"
- "packages/**"
- ".github/workflows/docker-publish.yml"
workflow_dispatch:
concurrency:
group: docker-${{ github.ref }}
cancel-in-progress: ${{ github.event_name != 'release' }}
env:
REGISTRY: ghcr.io
IMAGE_PREFIX: ghcr.io/databuddy-analytics/databuddy
jobs:
build:
name: Build ${{ matrix.service }} (${{ matrix.platform.arch }})
runs-on: ${{ matrix.platform.runner }}
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
service: [api, basket, links, uptime]
platform:
- arch: amd64
os: linux/amd64
runner: blacksmith-4vcpu-ubuntu-2404
- arch: arm64
os: linux/arm64
runner: blacksmith-4vcpu-ubuntu-2404-arm
include:
- service: api
description: "Databuddy API service - analytics backend"
- service: basket
description: "Databuddy Basket service - event ingestion"
- service: links
description: "Databuddy Links service - URL shortening and tracking"
- service: uptime
description: "Databuddy Uptime service - availability monitoring"
steps:
- uses: actions/checkout@v4
- name: Mount Docker build cache
uses: useblacksmith/stickydisk@v1
with:
key: ${{ github.repository }}-${{ matrix.service }}-${{ matrix.platform.arch }}
path: /tmp/docker-build-cache
- name: Set up Docker Builder
uses: useblacksmith/setup-docker-builder@v1
- uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Determine version tag
id: version
env:
EVENT_NAME: ${{ github.event_name }}
TAG_NAME: ${{ github.event.release.tag_name }}
run: |
if [[ "$EVENT_NAME" == "release" ]]; then
echo "tag=$TAG_NAME" >> "$GITHUB_OUTPUT"
else
echo "tag=edge" >> "$GITHUB_OUTPUT"
fi
- name: Capture build date
id: builddate
run: echo "timestamp=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_OUTPUT"
- name: Extract metadata (labels)
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_PREFIX }}-${{ matrix.service }}
labels: |
org.opencontainers.image.title=databuddy-${{ matrix.service }}
org.opencontainers.image.description=${{ matrix.description }}
org.opencontainers.image.vendor=Databuddy Analytics
org.opencontainers.image.licenses=AGPL-3.0
- uses: useblacksmith/build-push-action@v2
with:
context: .
file: ${{ matrix.service }}.Dockerfile
push: true
platforms: ${{ matrix.platform.os }}
provenance: false
labels: ${{ steps.meta.outputs.labels }}
tags: ${{ env.IMAGE_PREFIX }}-${{ matrix.service }}:${{ steps.version.outputs.tag }}-${{ matrix.platform.arch }}
build-args: |
VERSION=${{ steps.version.outputs.tag }}
BUILD_DATE=${{ steps.builddate.outputs.timestamp }}
GIT_SHA=${{ github.sha }}
cache-from: type=gha,scope=${{ matrix.service }}-${{ matrix.platform.arch }}
cache-to: type=gha,mode=max,scope=${{ matrix.service }}-${{ matrix.platform.arch }}
manifest:
name: Publish ${{ matrix.service }} manifest
needs: build
runs-on: blacksmith-2vcpu-ubuntu-2404
permissions:
packages: write
strategy:
matrix:
service: [api, basket, links, uptime]
steps:
- uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Determine version tag
id: version
env:
EVENT_NAME: ${{ github.event_name }}
TAG_NAME: ${{ github.event.release.tag_name }}
run: |
if [[ "$EVENT_NAME" == "release" ]]; then
echo "tag=$TAG_NAME" >> "$GITHUB_OUTPUT"
echo "is_release=true" >> "$GITHUB_OUTPUT"
else
echo "tag=edge" >> "$GITHUB_OUTPUT"
echo "is_release=false" >> "$GITHUB_OUTPUT"
fi
- name: Create multi-arch manifest
run: |
IMAGE="${{ env.IMAGE_PREFIX }}-${{ matrix.service }}"
TAG="${{ steps.version.outputs.tag }}"
SHA_SHORT="${{ github.sha }}"
SHA_SHORT="${SHA_SHORT:0:7}"
docker buildx imagetools create \
--tag "$IMAGE:$TAG" \
--tag "$IMAGE:sha-$SHA_SHORT" \
"$IMAGE:$TAG-amd64" \
"$IMAGE:$TAG-arm64"
if [[ "${{ steps.version.outputs.is_release }}" == "true" ]]; then
docker buildx imagetools create \
--tag "$IMAGE:latest" \
"$IMAGE:$TAG-amd64" \
"$IMAGE:$TAG-arm64"
fi
- name: Verify manifest
run: |
IMAGE="${{ env.IMAGE_PREFIX }}-${{ matrix.service }}"
TAG="${{ steps.version.outputs.tag }}"
echo "Inspecting $IMAGE:$TAG"
docker buildx imagetools inspect "$IMAGE:$TAG"