-
Notifications
You must be signed in to change notification settings - Fork 4
138 lines (118 loc) · 3.75 KB
/
build-and-push.yaml
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
name: Build and push
on:
push:
branches:
- 'main'
paths-ignore:
- 'README**'
- 'LICENSE'
pull_request_target:
paths-ignore:
- 'README**'
- 'LICENSE'
env:
REGISTRY_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/flexget
GHCR_IMAGE: ghcr.io/${{ github.repository_owner }}/flexget
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.platforms.outputs.matrix }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- id: platforms
run: |
echo "matrix=$(docker buildx f all --print | jq -cr '.target.all.platforms')" >> ${GITHUB_OUTPUT}
- id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.REGISTRY_IMAGE }}
${{ env.GHCR_IMAGE }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch
type=ref,event=pr
type=pep440,pattern={{version}}
type=pep440,pattern={{major}}.{{minor}}
type=pep440,pattern={{major}}
- uses: actions/upload-artifact@v4
with:
name: bake-meta
path: ${{ steps.meta.outputs.bake-file }}
retention-days: 1
build:
runs-on: ubuntu-latest
needs:
- prepare
strategy:
matrix:
platform: ${{ fromJson(needs.prepare.outputs.matrix) }}
steps:
- run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/download-artifact@v4
with:
name: bake-meta
path: /tmp
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- id: bake
uses: docker/bake-action@v5
with:
files: |
./docker-bake.hcl
/tmp/docker-metadata-action-bake.json
targets: all
set: |
*.tags=
*.platform=${{ matrix.platform }}
*.output=type=registry,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true
- run: |
mkdir -p /tmp/digests
digest="${{ fromJSON(steps.bake.outputs.metadata).all['containerimage.digest'] }}"
touch "/tmp/digests/${digest#sha256:}"
- uses: actions/upload-artifact@v4
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
retention-days: 1
merge:
runs-on: ubuntu-latest
needs:
- build
steps:
- uses: actions/download-artifact@v4
with:
name: bake-meta
path: /tmp
- uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.target."docker-metadata-action".tags |
map(select(startswith("${{ env.REGISTRY_IMAGE }}") or startswith("${{ env.GHCR_IMAGE }}")) | "-t " + .) |
join(" ")' /tmp/docker-metadata-action-bake.json) $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)