-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
78 lines (76 loc) · 2.51 KB
/
action.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
name: 'Build and push Docker image'
description: 'Composite action to build and push a Docker image to a registry.'
inputs:
context:
description: "Build's context is the set of files located in the specified PATH or URL"
required: true
default: .
file:
description: "Path to the Dockerfile"
required: true
default: ./Dockerfile
image:
description: "Name of the Docker image"
required: true
default: ${{ github.repository }}
registry:
description: "Address of the Docker registry"
required: true
default: ghcr.io
username:
description: "Username for the Docker registry"
required: true
default: ${{ github.actor }}
password:
description: "Password for the Docker registry"
required: true
platforms:
description: "Target platforms for the Docker image"
required: true
default: linux/amd64
push:
description: "Whether or not to push the image to the registry"
required: true
default: true
runs:
using: "composite"
steps:
- uses: docker/setup-qemu-action@v2
- uses: docker/setup-buildx-action@v2
- uses: docker/metadata-action@v4
id: meta
with:
images: ${{ inputs.registry }}/${{ inputs.image }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
# (A) push = true => push image and cache to registry
- uses: docker/login-action@v2
if: ${{ inputs.push == 'true' }}
with:
registry: ${{ inputs.registry }}
username: ${{ inputs.username }}
password: ${{ inputs.password }}
- uses: docker/build-push-action@v3
if: ${{ inputs.push == 'true' }}
with:
push: true
context: ${{ inputs.context }}
file: ${{ inputs.file }}
platforms: ${{ inputs.platforms }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ inputs.registry }}/${{ inputs.image }}:buildcache
cache-to: type=registry,ref=${{ inputs.registry }}/${{ inputs.image }}:buildcache,mode=max
# (B) push = false => do not push image or cache to registry
- uses: docker/build-push-action@v3
if: ${{ inputs.push != 'true' }}
with:
push: false
context: ${{ inputs.context }}
file: ${{ inputs.file }}
platforms: ${{ inputs.platforms }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}