-
Notifications
You must be signed in to change notification settings - Fork 8
221 lines (194 loc) · 9.05 KB
/
build_docker.yml
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
---
name: Build sha-p2pool docker images
'on':
push:
paths-ignore:
- '**/*.md'
tags:
- 'v[0-9]+.[0-9]+.[0-9]*'
branches:
- 'build-all-*'
- 'build-dockers-*'
schedule:
- cron: '05 00 * * *'
workflow_dispatch:
inputs:
version:
type: string
description: 'override image tag/version'
tag_alias:
type: string
description: 'image tag alias'
env:
DOCKER_IMAGE: sha-p2pool
DAYS_to_EXPIRE: 30
concurrency:
# https://docs.github.com/en/actions/examples/using-concurrency-expressions-and-a-test-matrix
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: ${{ !startsWith(github.ref, 'refs/tags/v') || github.ref != 'refs/heads/development' }}
permissions: {}
jobs:
builds_envs_setup:
name: Build envs setup
runs-on: ubuntu-latest
outputs:
version: ${{ steps.envs_setup.outputs.version }}
steps:
- name: Prep docker build environment
id: envs_setup
shell: bash
run: |
#TESHA_SHORT=$(git rev-parse --short HEAD)
TESHA_SHORT=${GITHUB_SHA::7}
if [[ "${{ github.ref }}" =~ ^refs\/tags\/v[0-9]+\.[0-9]+\.[0-9]+.*$ ]]; then
VERSION="${{ github.ref_name }}_$(date -u '+%Y%m%d')_${TESHA_SHORT}"
echo "TAG_ALIAS=${{ secrets.DOCKER_PROVIDER }}/${{ secrets.DOCKER_REPO }}/${{ env.DOCKER_IMAGE }}:${{ github.ref_name }}" >> $GITHUB_ENV
else
if [ -z "${{ inputs.version }}" ] ; then
VERSION="${{ github.ref_name }}_$(date -u '+%Y%m%d')_${TESHA_SHORT}"
else
VERSION=${{ inputs.version }}
fi
fi
echo "Setting ${VERSION} as docker tag"
echo "VERSION=${VERSION}" >> $GITHUB_ENV
echo "version=${VERSION}" >> $GITHUB_OUTPUT
if [ ! -z "${{ inputs.tag_alias }}" ] ; then
echo "Setup tag_alias"
echo "TAG_ALIAS=${{ secrets.DOCKER_PROVIDER }}/${{ secrets.DOCKER_REPO }}/${{ env.DOCKER_IMAGE }}:${{ inputs.tag_alias }}" >> $GITHUB_ENV
fi
docker_build:
name: Docker building
needs: builds_envs_setup
runs-on: ubuntu-latest
outputs:
version: ${{ steps.envs_setup.outputs.version }}
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
platform: [amd64, arm64]
steps:
- name: Checkout p2pool explorer
uses: actions/checkout@v4
- name: Set up QEMU for Docker
uses: docker/setup-qemu-action@v3
with:
platforms: all
- name: Expire setup
shell: bash
run: |
if [[ "${{ github.ref }}" =~ ^refs\/tags\/v[0-9]+\.[0-9]+\.[0-9]+.*$ ]]; then
echo "No Expire for release"
else
echo "EXPIRATION=${{ env.DAYS_to_EXPIRE }}d" >> $GITHUB_ENV
fi
echo "VERSION=${{ needs.builds_envs_setup.outputs.version }}" >> $GITHUB_ENV
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE }}
${{ secrets.DOCKER_PROVIDER }}/${{ secrets.DOCKER_REPO }}/${{ env.DOCKER_IMAGE }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
labels: |
maintainer=${{ github.actor }}
quay.expires-after=${{ env.EXPIRATION }}
org.opencontainers.image.vendor=TariLabs
org.opencontainers.image.title=${{ env.DOCKER_IMAGE }}
org.opencontainers.image.description=Multi-arch Docker image for ${{ env.DOCKER_IMAGE }}
org.opencontainers.image.url=https://github.com/${{ github.repository }}
org.opencontainers.image.source=https://github.com/${{ github.repository }}
flavor: |
suffix=-${{ matrix.platform }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Docker Image Provider
uses: docker/login-action@v3
with:
registry: ${{ secrets.DOCKER_PROVIDER }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Docker image build and push
id: docker_build
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile.cross-compile
platforms: linux/${{ matrix.platform }}
push: true
provenance: false
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ env.VERSION }}
tags: |
${{ steps.meta.outputs.tags }}
${{ secrets.DOCKER_PROVIDER }}/${{ secrets.DOCKER_REPO }}/${{ env.DOCKER_IMAGE }}:${{ env.VERSION }}-${{ matrix.platform }}
ghcr.io/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE }}:latest-${{ matrix.platform }}
${{ secrets.DOCKER_PROVIDER }}/${{ secrets.DOCKER_REPO }}/${{ env.DOCKER_IMAGE }}:latest-${{ matrix.platform }}
${{ env.TAG_ALIAS }}
outputs: |
type=registry,annotation-manifest-descriptor.org.opencontainers.image.title=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.title'] }},annotation-manifest-descriptor.org.opencontainers.image.description=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.description'] }},annotation.org.opencontainers.image.title=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.title'] }},annotation.org.opencontainers.image.description=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.description'] }},annotation-index.org.opencontainers.image.title=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.title'] }},annotation-index.org.opencontainers.image.description=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.description'] }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
create-manifest:
needs: [ builds_envs_setup, docker_build ]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Log in to Registries
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login ${{ secrets.DOCKER_PROVIDER }} -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
# Create and push the multi-arch image to both registries
- name: Push multi-arch image
run: |
DVERSION=${{ needs.builds_envs_setup.outputs.version }}
for DREGISTRY in ghcr.io quay.io; do
if [[ "${DREGISTRY}" == "ghcr.io" ]]; then
repo="${{ github.repository_owner }}"
else
repo="${{ secrets.DOCKER_REPO }}"
fi
echo "Registry run - ${DREGISTRY}"
echo "Creating multi-arch image for ${repo}/${{ env.DOCKER_IMAGE }} for ${DVERSION}"
docker manifest create \
${DREGISTRY}/${repo}/${{ env.DOCKER_IMAGE }}:${DVERSION} \
--amend ${DREGISTRY}/${repo}/${{ env.DOCKER_IMAGE }}:latest-amd64 \
--amend ${DREGISTRY}/${repo}/${{ env.DOCKER_IMAGE }}:latest-arm64
echo "Inspect multi-arch image for ${repo}/${{ env.DOCKER_IMAGE }}"
docker manifest inspect ${DREGISTRY}/${repo}/${{ env.DOCKER_IMAGE }}:${DVERSION} > manifest.json
cat manifest.json
echo "Pushing multi-arch image for ${repo}/${{ env.DOCKER_IMAGE }}"
docker manifest push ${DREGISTRY}/${repo}/${{ env.DOCKER_IMAGE }}:${DVERSION} || true
if [[ "${{ github.ref }}" =~ ^refs\/tags\/v[0-9]+\.[0-9]+\.[0-9]+.*$ ]]; then
echo "Release Multi-Arch Tag"
docker manifest create \
${DREGISTRY}/${repo}/${{ env.DOCKER_IMAGE }}:${{ github.ref_name }} \
--amend ${DREGISTRY}/${repo}/${{ env.DOCKER_IMAGE }}:latest-amd64 \
--amend ${DREGISTRY}/${repo}/${{ env.DOCKER_IMAGE }}:latest-arm64
docker manifest push ${DREGISTRY}/${repo}/${{ env.DOCKER_IMAGE }}:${{ github.ref_name }} || true
fi
echo "Latest Multi-Arch tag"
docker manifest create \
${DREGISTRY}/${repo}/${{ env.DOCKER_IMAGE }}:latest \
--amend ${DREGISTRY}/${repo}/${{ env.DOCKER_IMAGE }}:latest-amd64 \
--amend ${DREGISTRY}/${repo}/${{ env.DOCKER_IMAGE }}:latest-arm64
#docker manifest annotate ${DREGISTRY}/${repo}/${{ env.DOCKER_IMAGE }}:latest --file manifest.json
docker manifest push ${DREGISTRY}/${repo}/${{ env.DOCKER_IMAGE }}:latest || true
done