-
Notifications
You must be signed in to change notification settings - Fork 0
172 lines (151 loc) · 5.29 KB
/
Copy pathrust.yml
File metadata and controls
172 lines (151 loc) · 5.29 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
name: Rust Build CI
on:
release:
types: [published]
pull_request:
branches: [main]
env:
CARGO_TERM_COLOR: always
REGISTRY_IMAGE: nihaopaul/forward-auth-rust
jobs:
build:
name: lint, build and test
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- name: check repository
uses: actions/checkout@v7
# Cheap checks first, so a formatting slip fails in seconds instead of
# after a full release build. rustfmt and clippy ship with the runner's
# stable toolchain.
- name: format
run: cargo fmt --all --check
- name: clippy
run: cargo clippy --workspace --all-targets -- -D warnings
- name: build
run: cargo build --release --locked --workspace
- name: test
run: cargo test --workspace
# Release only: this starts real containers, so it is too heavy for every
# pull request. It gates the image build below via `needs: build`, so a
# broken audience-binding middleware contract fails the release before
# anything is published.
- name: test Traefik audience binding
if: github.event_name == 'release'
run: sh tests/traefik/run.sh
# One job per architecture, each on a runner of that architecture, so the
# Rust tree is never cross-compiled under emulation. These push by digest
# only; tags are applied by the merge job below.
docker:
name: build image (${{ matrix.arch }})
if: github.event_name == 'release'
needs: build
permissions:
contents: read
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- arch: amd64
platform: linux/amd64
runner: ubuntu-latest
- arch: arm64
platform: linux/arm64
runner: ubuntu-24.04-arm
steps:
- name: check repository
uses: actions/checkout@v7
- name: Docker meta
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ env.REGISTRY_IMAGE }}
- name: set up buildx
uses: docker/setup-buildx-action@v4
- name: login to docker registry
uses: docker/login-action@v4
with:
username: ${{secrets.DOCKERHUB_USERNAME}}
password: ${{secrets.DOCKERHUB_TOKEN}}
- name: build and push by digest
id: build
uses: docker/build-push-action@v7
with:
context: .
file: ./Dockerfile
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
- name: export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: upload digest
uses: actions/upload-artifact@v7
with:
name: digests-${{ matrix.arch }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
# Collects the per-architecture digests into one multi-arch tag, so that
# `docker pull nihaopaul/forward-auth-rust:<tag>` resolves per host.
docker-merge:
name: push multi-arch manifest
if: github.event_name == 'release'
needs: docker
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- name: download digests
uses: actions/download-artifact@v8
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true
- name: set up buildx
uses: docker/setup-buildx-action@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ env.REGISTRY_IMAGE }}
env:
# Annotations default to the `manifest:` level, which is wrong for a
# manifest list. Emit them pre-prefixed for the index instead.
DOCKER_METADATA_ANNOTATIONS_LEVELS: index
- name: login to docker registry
uses: docker/login-action@v4
with:
username: ${{secrets.DOCKERHUB_USERNAME}}
password: ${{secrets.DOCKERHUB_TOKEN}}
- name: create manifest list and push
shell: bash
working-directory: /tmp/digests
run: |
set -euo pipefail
args=()
while IFS= read -r a; do
[ -n "$a" ] && args+=("--annotation" "$a")
done <<< "${DOCKER_METADATA_OUTPUT_ANNOTATIONS:-}"
while IFS= read -r t; do
[ -n "$t" ] && args+=("-t" "$t")
done < <(jq -r '.tags[]' <<< "$DOCKER_METADATA_OUTPUT_JSON")
for d in *; do
args+=("${REGISTRY_IMAGE}@sha256:${d}")
done
docker buildx imagetools create "${args[@]}"
- name: verify both architectures are published
shell: bash
run: |
set -euo pipefail
tag='${{ steps.meta.outputs.version }}'
docker buildx imagetools inspect "${REGISTRY_IMAGE}:${tag}"
for arch in amd64 arm64; do
docker buildx imagetools inspect --raw "${REGISTRY_IMAGE}:${tag}" \
| jq -e --arg a "$arch" '[.manifests[].platform.architecture] | index($a)' >/dev/null \
|| { echo "::error::$arch is missing from the published manifest"; exit 1; }
done