-
Notifications
You must be signed in to change notification settings - Fork 3
169 lines (155 loc) · 4.81 KB
/
_docker-build.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
name: "docker-build"
on:
workflow_call:
inputs:
target:
description: "Bake target"
required: true
type: string
set:
description: "List of targets values to override (eg. targetpattern.key=value)"
required: false
type: string
push:
description: "Push is a shorthand for --set=*.output=type=registry"
required: false
type: boolean
default: false
clean-up:
description: "Whether to clean up"
required: false
type: boolean
default: true
upload-metadata:
description: "Whether to upload metadata files"
required: false
type: boolean
default: true
hw-registry:
description: "Server address of Huawei Cloud registry"
required: false
type: string
default: "swr.cn-southwest-2.myhuaweicloud.com"
secrets:
DOCKERHUB_OWNER:
description: "Owner of the DockerHub registry"
required: false
DOCKERHUB_USERNAME:
description: "Username of the DockerHub registry"
required: false
DOCKERHUB_TOKEN:
description: "Token of the DockerHub registry"
required: false
QUAY_OWNER:
description: "Owner of the Quay registry"
required: false
QUAY_USERNAME:
description: "Username of the Quay registry"
required: false
QUAY_TOKEN:
description: "Token of the Quay registry"
required: false
HW_OWNER:
description: "Owner of the Huawei Cloud registry"
required: false
HW_USERNAME:
description: "Username of the Huawei Cloud registry"
required: false
HW_TOKEN:
description: "Token of the Huawei Cloud registry"
required: false
permissions:
contents: read
jobs:
prepare:
name: 'prepare'
runs-on: ubuntu-latest
outputs:
targets: ${{ steps.list-target.outputs.targets }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: List targets
id: list-target
uses: docker/bake-action/subaction/list-targets@v6
with:
target: ${{ inputs.target }}
files: |
arg.json
docker-bake.hcl
docker:
name: 'docker'
runs-on: ubuntu-24.04-arm # TODO: Use ubuntu-latest
needs:
- prepare
strategy:
fail-fast: false
max-parallel: 10
matrix:
target: ${{ fromJson(needs.prepare.outputs.targets) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Clean up
if: ${{ inputs.clean-up }}
continue-on-error: true
uses: ./.github/actions/clean-up
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker registries
if: ${{ inputs.push }}
uses: ./.github/actions/docker-login
with:
dockerhub-username: ${{ secrets.DOCKERHUB_USERNAME }}
dockerhub-token: ${{ secrets.DOCKERHUB_TOKEN }}
quay-username: ${{ secrets.QUAY_USERNAME }}
quay-token: ${{ secrets.QUAY_TOKEN }}
hw-username: ${{ secrets.HW_USERNAME }}
hw-token: ${{ secrets.HW_TOKEN }}
hw-registry: ${{ inputs.hw-registry }}
- name: Extract metadata for Docker
id: metadata
uses: docker/metadata-action@v5
with:
bake-target: "docker-metadata-action"
- name: Build and push Docker image
id: bake
uses: docker/bake-action@v6
with:
source: .
files: |
${{ github.workspace }}/arg.json
${{ github.workspace }}/docker-bake.hcl
${{ steps.metadata.outputs.bake-file-labels }}
${{ steps.metadata.outputs.bake-file-annotations }}
targets: ${{ matrix.target }}
push: ${{ inputs.push }}
set: ${{ inputs.set }}
provenance: false
sbom: false
- name: Export metadata
id: export
if: ${{ steps.bake.outputs.metadata }}
shell: bash
run: |
METADATA_FILE_NAME="${{ matrix.target }}-metadata.json"
echo "metadata-file-name=${METADATA_FILE_NAME}" >> $GITHUB_OUTPUT
echo '${{ steps.bake.outputs.metadata }}' > /tmp/${METADATA_FILE_NAME}
- name: Upload metadata
id: upload-artifact
if: ${{ inputs.upload-metadata }}
uses: actions/upload-artifact@v4
with:
name: ${{ steps.export.outputs.metadata-file-name }}
path: /tmp/${{ steps.export.outputs.metadata-file-name }}
if-no-files-found: error
retention-days: 7
- name: Show space
if: ${{ always() }}
shell: bash
run: |
set -x
sudo df -h
docker images -a