-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
110 lines (102 loc) · 3.06 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
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
name: "Build Docker Image"
inputs:
image:
required: true
context:
required: false
default: "."
tags:
required: false
registry:
required: false
username:
required: true
password:
required: true
stage:
required: false
dockerfile:
required: false
cache:
required: false
default: true
build-args:
required: false
platforms:
required: false
push:
required: false
default: true
outputs:
image-id:
description: The ID of the image that was built
value: ${{ steps.cached.outputs.imageid || steps.uncached.outputs.imageid }}
image-digest:
description: The Digest of the image that was built
value: ${{ steps.cached.outputs.digest || steps.uncached.outputs.digest }}
image-tags:
description: List of tags generated
value: ${{ steps.meta.outputs.tags }}
image-version:
description: The version of the image
value: ${{ steps.meta.outputs.version }}
image-labels:
description: The labels of the image
value: ${{ steps.meta.outputs.labels }}
metadata:
description: The Digest of the image that was built
value: ${{ steps.cached.outputs.metadata || steps.uncached.outputs.metadata }}
runs:
using: "composite"
steps:
- name: Set up Docker
uses: cern-sis/gh-workflows/.github/actions/[email protected]
- name: Generate image name
id: generate
shell: bash
run: echo "image=${{ inputs.registry }}${{ inputs.registry && '/' }}${{ inputs.image }}" >>$GITHUB_OUTPUT
- name: Generate metadata
id: meta
uses: docker/metadata-action@v4
env:
DOCKER_METADATA_PR_HEAD_SHA: true
with:
images: ${{ steps.generate.outputs.image }}
tags: |
type=sha
${{ inputs.tags }}
- name: Login
uses: docker/login-action@v2
with:
registry: ${{ inputs.registry || 'docker.io' }}
username: ${{ inputs.username }}
password: ${{ inputs.password }}
- name: Build and export
id: cached
if: ${{ inputs.cache == 'true' }}
uses: docker/build-push-action@v4
with:
context: ${{ inputs.context }}
target: ${{ inputs.stage }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: ${{ inputs.push }}
cache-from: type=registry,ref=${{ steps.generate.outputs.image }}:buildcache
cache-to: type=registry,ref=${{ steps.generate.outputs.image }}:buildcache,mode=max
file: ${{ inputs.dockerfile }}
build-args: ${{ inputs.build-args }}
platforms: ${{ inputs.platforms }}
- name: Build and export
id: uncached
if: ${{ inputs.cache == 'false'}}
uses: docker/build-push-action@v4
with:
context: ${{ inputs.context }}
target: ${{ inputs.stage }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: ${{ inputs.push }}
no-cache: true
file: ${{ inputs.dockerfile }}
build-args: ${{ inputs.build-args }}
platforms: ${{ inputs.platforms }}