-
Notifications
You must be signed in to change notification settings - Fork 0
126 lines (123 loc) · 3.98 KB
/
docker-publish.yml
File metadata and controls
126 lines (123 loc) · 3.98 KB
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
name: Docker publish
on:
workflow_call:
inputs:
repository:
description: "Repository to checkout"
required: false
type: string
repository-ref:
description: "Repository ref to checkout"
required: false
type: string
build-args:
description: "Docker build args"
required: false
type: string
docker-image:
description: "Name of the docker image to push"
required: true
type: string
docker-platforms:
description: "List of comma separated platforms to build"
required: false
type: string
default: "linux/amd64"
docker-extra-tag:
description: "Static tag to add on build image"
required: false
type: string
docker-auto-tag:
description: "Wether to automatically tag or not"
required: false
type: boolean
default: true
runs-on:
description: "Runner to use"
required: false
type: string
default: "ubuntu-latest"
environment:
description: "Environment to use"
required: false
type: string
environment-url:
description: "Environment URL to use"
required: false
type: string
secrets:
docker-repo:
description: "Docker registry to push to"
required: true
docker-username:
description: "Docker username"
required: true
docker-token:
description: "Docker token"
required: true
outputs:
image-digest:
description: "Pushed docker image's digest"
value: ${{ jobs.publish.outputs.digest }}
permissions:
contents: read
packages: write
jobs:
publish:
name: Docker - Publish
runs-on: [ "${{ inputs.runs-on }}" ]
concurrency:
group: docker-publish-${{ inputs.docker-extra-tag }}
cancel-in-progress: true
environment:
name: ${{ inputs.environment }}
url: ${{ inputs.environment-url }}
outputs:
digest: ${{ steps.docker_build.outputs.digest }}
steps:
- name: Checkout source
uses: actions/checkout@v6.0.2
with:
repository: '${{ inputs.repository }}'
ref: '${{ inputs.repository-ref }}'
- name: Set up QEMU
uses: docker/setup-qemu-action@v4.1.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4.1.0
- name: Login on registry
uses: docker/login-action@v4.2.0
with:
registry: ${{ secrets.docker-repo }}
username: ${{ secrets.docker-username }}
password: ${{ secrets.docker-token }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v6.1.0
with:
images: ${{ secrets.docker-repo }}/${{ inputs.docker-image }}
tags: |
# Default values
type=schedule,enable=${{ inputs.docker-auto-tag }}
type=ref,event=branch,enable=${{ inputs.docker-auto-tag }}
type=ref,event=tag,enable=${{ inputs.docker-auto-tag }}
type=ref,event=pr,enable=${{ inputs.docker-auto-tag }}
# Set latest tag for default branch
type=raw,value=latest,enable=${{ inputs.docker-auto-tag && github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
# Custom tag
${{ inputs.docker-extra-tag != '' && format('type=raw,value={0},enable=true', inputs.docker-extra-tag) || '' }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v7.2.0
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ inputs.docker-platforms }}
build-args: |
BUILDX_QEMU_ENV=true
${{ inputs.build-args }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}