-
-
Notifications
You must be signed in to change notification settings - Fork 2
183 lines (163 loc) · 6.11 KB
/
docker.yml
File metadata and controls
183 lines (163 loc) · 6.11 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
178
179
180
181
182
183
name: Docker
on:
schedule:
- cron: '0 10 * * 0' # At 10:00 on Sunday
push:
branches:
- '**'
tags:
- 'v*.*.*'
paths-ignore:
- 'docs/**'
- '*.md'
pull_request:
branches:
- 'master'
paths-ignore:
- 'docs/**'
- '*.md'
jobs:
# build single-platform docker images on native runners
build:
strategy:
matrix:
include:
- platform: linux/amd64
platform-pair: linux-amd64
runs-on: ubuntu-24.04
- platform: linux/arm64
platform-pair: linux-arm64
runs-on: ubuntu-24.04-arm
name: Docker (${{ matrix.platform }})
runs-on: ${{ matrix.runs-on }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
persist-credentials: false
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
jonchang/tact
ghcr.io/jonchang/tact
tags: |
type=schedule
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Login to DockerHub
if: github.event_name != 'pull_request' || github.actor != 'dependabot[bot]'
uses: docker/login-action@v3
with:
username: ${{ github.repository_owner }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push by digest (DockerHub)
if: github.event_name != 'pull_request' || github.actor != 'dependabot[bot]'
uses: docker/build-push-action@v6
id: build-dockerhub
with:
context: .
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=jonchang/tact,push-by-digest=true,name-canonical=true,push=${{ github.event_name != 'pull_request' }}
- name: Build and push by digest (GHCR)
uses: docker/build-push-action@v6
id: build-ghcr
with:
context: .
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=ghcr.io/jonchang/tact,push-by-digest=true,name-canonical=true,push=${{ github.event_name != 'pull_request' }}
- name: Export digests
if: github.event_name != 'pull_request'
run: |
mkdir -p /tmp/digests
if [ "${{ github.actor }}" != "dependabot[bot]" ]; then
digest="${{ steps.build-dockerhub.outputs.digest }}"
echo "${digest#sha256:}" > /tmp/digests/dockerhub-digest
fi
digest="${{ steps.build-ghcr.outputs.digest }}"
echo "${digest#sha256:}" > /tmp/digests/ghcr-digest
- name: Upload digests
if: github.event_name != 'pull_request'
uses: actions/upload-artifact@v6
with:
name: digests-${{ matrix.platform-pair }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
# merge single-platform images into multiplatform images
merge:
runs-on: ubuntu-latest
needs:
- build
if: github.event_name != 'pull_request'
steps:
- name: Download digests
uses: actions/download-artifact@v7
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: false
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
jonchang/tact
ghcr.io/jonchang/tact
tags: |
type=schedule
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Login to DockerHub
if: github.actor != 'dependabot[bot]'
uses: docker/login-action@v3
with:
username: ${{ github.repository_owner }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create and push merged image (DockerHub)
if: github.actor != 'dependabot[bot]'
working-directory: /tmp/digests
run: |
# Extract all Docker image tags from the Docker metadata JSON, prepend each with "-t " (required by buildx), and convert them into a single space-separated string
tags=$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON")
digests=$(cat digests-linux-amd64/dockerhub-digest digests-linux-arm64/dockerhub-digest | sed 's/^/jonchang\/tact@sha256:/' | tr '\n' ' ')
docker buildx imagetools create $tags $digests
- name: Create and push merged image (GHCR)
working-directory: /tmp/digests
run: |
# Extract all Docker image tags from the Docker metadata JSON, prepend each with "-t " (required by buildx), and convert them into a single space-separated string
tags=$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON")
digests=$(cat digests-linux-amd64/ghcr-digest digests-linux-arm64/ghcr-digest | sed 's/^/ghcr.io\/jonchang\/tact@sha256:/' | tr '\n' ' ')
docker buildx imagetools create $tags $digests
- name: Inspect Docker images
run: |
if [ "${{ github.actor }}" != "dependabot[bot]" ]; then
docker buildx imagetools inspect "jonchang/tact:${{ steps.meta.outputs.version }}"
fi
docker buildx imagetools inspect "ghcr.io/jonchang/tact:${{ steps.meta.outputs.version }}"