-
Notifications
You must be signed in to change notification settings - Fork 0
144 lines (143 loc) · 5.39 KB
/
buildx.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
on:
workflow_call:
inputs:
image:
type: string
required: true
description: container image
readme:
type: string
required: true
description: readme location
registry:
type: string
required: false
default: ''
description: container registry
platforms:
type: string
required: false
default: linux/amd64,linux/arm64
description: platforms to build images for
cache-type:
type: string
required: false
default: registry
description: buildx cache type [registry | gha]
license:
type: string
required: false
default: MIT
description: container image license
vendor:
type: string
required: false
default: datatrash
description: container image vendor
build-args:
type: string
required: false
default: ''
description: container image build arguments
secrets:
container-registry-username:
required: true
description: username for container registry login
container-registry-password:
required: true
description: password for container registry login
outputs:
sha-tag:
description: image short sha tag
value: ${{ jobs.build.outputs.sha-tag }}
jobs:
build:
runs-on: ubuntu-latest
outputs:
sha-tag: ${{ steps.tags.outputs.sha-tag }}
steps:
- name: Check out
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2.1.0
- name: Set up tags
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ inputs.image }}
labels: |
org.opencontainers.image.licenses=${{ inputs.license }}
org.opencontainers.image.vendor=${{ inputs.vendor }}
io.artifacthub.package.readme-url=${{ inputs.readme }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=edge
type=sha
- name: Output short tag
id: tags
run: |
echo "::set-output name=sha-tag::sha-$(echo ${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }} | cut -c1-7)"
- name: Login to Docker Hub container registry
uses: docker/login-action@v2.1.0
if: ${{ inputs.registry == ''}}
with:
username: ${{ secrets.container-registry-username }}
password: ${{ secrets.container-registry-password }}
- name: Login to ${{ inputs.registry }} container registry
uses: docker/login-action@v2.1.0
if: ${{ inputs.registry != ''}}
with:
registry: ${{ inputs.registry }}
username: ${{ secrets.container-registry-username }}
password: ${{ secrets.container-registry-password }}
- name: Build and push image to container registry using registry cache
uses: docker/build-push-action@v3.2.0
if: ${{ inputs.cache-type == 'registry' && inputs.build-args == '' }}
with:
platforms: ${{ inputs.platforms }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ inputs.image }}:buildcache
cache-to: type=registry,ref=${{ inputs.image }}:buildcache,mode=max
build-args: |
BUILDKIT_CONTEXT_KEEP_GIT_DIR=true
- name: Build and push image with build args ${{ inputs.build-args }} to container registry using registry cache
uses: docker/build-push-action@v3.2.0
if: ${{ inputs.cache-type == 'registry' && inputs.build-args != '' }}
with:
build-args: ${{ inputs.build-args }}
platforms: ${{ inputs.platforms }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ inputs.image }}:buildcache
cache-to: type=registry,ref=${{ inputs.image }}:buildcache,mode=max
- name: Build and push image to container registry using gha cache
uses: docker/build-push-action@v3.2.0
if: ${{ inputs.cache-type == 'gha' && inputs.build-args == '' }}
with:
platforms: ${{ inputs.platforms }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build and push image with build args ${{ inputs.build-args }} to container registry using gha cache
uses: docker/build-push-action@v3.2.0
if: ${{ inputs.cache-type == 'gha' && inputs.build-args != '' }}
with:
build-args: ${{ inputs.build-args }}
platforms: ${{ inputs.platforms }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max