-
Notifications
You must be signed in to change notification settings - Fork 154
106 lines (92 loc) · 3.67 KB
/
reusable-docker-images.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
name: docker-images
on:
workflow_call:
secrets:
DOCKERHUB_USERNAME:
required: true
DOCKERHUB_TOKEN:
required: true
jobs:
docker-images:
name: Publish docker images
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
matrix:
helm:
- 2.17.0
- 3.12.3
- 3.13.1
env:
IMAGE_NAME: hypnoglow/helm-s3
HELM_VERSION: ${{ matrix.helm }}
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Setup Go
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
with:
cache: true
go-version-file: 'go.mod'
- name: Download dependencies
run: |
go mod download -x
go mod vendor
- name: Prepare variables
id: vars
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
with:
script: |
const { GITHUB_REF_NAME, GITHUB_REF_TYPE, GITHUB_SHA } = process.env
let helm_version_minor = "${{ matrix.helm }}".split('.').slice(0, -1).join('.')
let plugin_version = `commit.${context.sha}`
let push = false
if (GITHUB_REF_TYPE === "branch" && GITHUB_REF_NAME === "master") {
plugin_version = "master"
push = true
}
if (GITHUB_REF_TYPE === "tag") {
plugin_version = GITHUB_REF_NAME.replace(/^v/, "")
push = true
}
let build_date = new Date().toISOString()
core.setOutput('helm_version_minor', helm_version_minor)
core.setOutput('plugin_version', plugin_version)
core.setOutput('build_date', build_date)
core.setOutput('vcs_ref', context.sha)
core.setOutput('push', push)
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
with:
images: |
hypnoglow/helm-s3
tags: |
type=semver,pattern={{ version }},suffix=-helm${{ matrix.helm }}
type=semver,pattern={{ version }},suffix=-helm${{ steps.vars.outputs.helm_version_minor }}
type=ref,event=branch,enable={{ is_default_branch }},suffix=-helm${{ matrix.helm }}
type=ref,event=branch,enable={{ is_default_branch }},suffix=-helm${{ steps.vars.outputs.helm_version_minor }}
type=raw,value=commit.{{ sha }},suffix=-helm${{ matrix.helm }}
type=raw,value=commit.{{ sha }},suffix=-helm${{ steps.vars.outputs.helm_version_minor }}
- name: Login to Docker Hub
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
if: steps.vars.outputs.push == 'true'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
- name: Build and push
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: .
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
HELM_VERSION=${{ matrix.helm }}
PLUGIN_VERSION=${{ steps.vars.outputs.plugin_version }}
BUILD_DATE=${{ steps.vars.outputs.build_date }}
VCS_REF=${{ steps.vars.outputs.vcs_ref }}
push: ${{ steps.vars.outputs.push }}