-
Notifications
You must be signed in to change notification settings - Fork 153
103 lines (89 loc) · 3.61 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
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
strategy:
matrix:
helm:
- 2.17.0
- 3.9.4
- 3.10.1
env:
IMAGE_NAME: hypnoglow/helm-s3
HELM_VERSION: ${{ matrix.helm }}
steps:
- name: Checkout
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2
- name: Setup Go
uses: actions/setup-go@268d8c0ca0432bb2cf416faae41297df9d262d7f # v3.3.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@7dff1a87643417cf3b95bb10b29f4c4bc60d8ebd # v6.3.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@69f6fc9d46f2f8bf0d5491e4aabe0bb8c6a4678a # v4.0.1
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@49ed152c8eca782a232dede0303416e8f356c37b # v2.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@dc7b9719a96d48369863986a06765841d7ea23f6 # v2.0.0
- name: Build and push
uses: docker/build-push-action@c84f38281176d4c9cdb1626ffafcd6b3911b5d94 # v3.1.1
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 }}