-
Notifications
You must be signed in to change notification settings - Fork 27
140 lines (125 loc) · 4.81 KB
/
Copy pathdocker_publish.yaml
File metadata and controls
140 lines (125 loc) · 4.81 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
name: Publish Docker Image
on:
push:
branches: [main]
workflow_dispatch:
inputs:
tags:
description: "Docker image tags, comma-separated (e.g., latest,v0.1.0)"
required: false
default: "latest"
permissions:
contents: read
packages: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
# On push to main, inputs.tags is empty, so fall back to "unstable" so it
# tracks main. Manual dispatch still honors custom tags.
TAGS_INPUT: ${{ inputs.tags || 'unstable' }}
jobs:
build-image:
name: Build Docker image (${{ matrix.arch.name }}, ${{ matrix.variant.name }})
strategy:
matrix:
arch:
- runner: ubuntu-latest
name: amd64
- runner: ubuntu-22.04-arm
name: arm64
# Each tag is published twice: once as the regular image and once as a
# Shadow-simulator-compatible image (tag suffixed "-shadow"). The shadow
# build args mirror the `shadow-docker-build` Makefile target. LOCKED=
# builds the shadow variant unlocked (the quinn-udp [patch] is absent
# from Cargo.lock; see Dockerfile), so -shadow images are not
# reproducible and should not be treated as equivalent-security
# artifacts to the regular tags.
variant:
- name: default
suffix: ""
build_args: ""
- name: shadow
suffix: "-shadow"
build_args: |
SHADOW=1
FEATURES=shadow-integration
NO_DEFAULT_FEATURES=--no-default-features
LOCKED=
runs-on: ${{ matrix.arch.runner }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Prepare tags
id: prep
env:
SUFFIX: ${{ matrix.variant.suffix }}
ARCH: ${{ matrix.arch.name }}
run: |
TAGS=""
IFS=',' read -ra TAG_ARRAY <<< "${TAGS_INPUT}"
for t in "${TAG_ARRAY[@]}"; do
TAGS="${TAGS}${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${t}${SUFFIX}-${ARCH},"
done
TAGS="${TAGS%,}" # Remove trailing comma
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
build-args: |
GIT_COMMIT=${{ github.sha }}
GIT_BRANCH=${{ github.ref_name }}
${{ matrix.variant.build_args }}
push: true
tags: ${{ steps.prep.outputs.tags }}
platforms: linux/${{ matrix.arch.name }}
cache-from: type=gha,scope=${{ matrix.arch.name }}-${{ matrix.variant.name }}
cache-to: type=gha,scope=${{ matrix.arch.name }}-${{ matrix.variant.name }},mode=max
publish-manifest:
name: Create and push multi-arch manifest
runs-on: ubuntu-latest
needs: build-image
steps:
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create multi-arch manifests
env:
SHORT_SHA: ${{ github.sha }}
run: |
IFS=',' read -ra TAG_ARRAY <<< "${TAGS_INPUT}"
FIRST_TAG="${TAG_ARRAY[0]}"
SHORT="${SHORT_SHA::7}"
# Publish each tag twice: the regular image and its "-shadow" twin.
# These suffixes must stay in sync with the `variant` matrix suffixes
# in the build-image job above: a new variant must be added in both.
for suffix in "" "-shadow"; do
# First tag also gets an immutable sha-<sha> tag.
docker buildx imagetools create \
-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${FIRST_TAG}${suffix} \
-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:sha-${SHORT}${suffix} \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${FIRST_TAG}${suffix}-amd64 \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${FIRST_TAG}${suffix}-arm64
# Remaining tags.
for t in "${TAG_ARRAY[@]:1}"; do
docker buildx imagetools create \
-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${t}${suffix} \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${t}${suffix}-amd64 \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${t}${suffix}-arm64
done
done