-
Notifications
You must be signed in to change notification settings - Fork 0
162 lines (144 loc) · 4.62 KB
/
build.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: Build
on:
workflow_call:
inputs:
GO_VERSION:
required: true
type: string
REGISTRY:
required: true
type: string
NAMESPACE:
required: true
type: string
TAG:
required: true
type: string
MAJOR_TAG:
required: false
type: string
MINOR_TAG:
required: false
type: string
PATCH_TAG:
required: false
type: string
PLATFORMS:
required: false
type: string
workflow_dispatch:
inputs:
GO_VERSION:
description: Go version to use
required: true
type: string
default: 1.22.4
REGISTRY:
description: Target registry to push images
required: true
type: string
default: ghcr.io
NAMESPACE:
description: Target namespace to the given registry
required: true
type: string
default: titigmr/external-dns-midaas-webhook
PLATFORMS:
description: Target platforms for build
required: false
type: string
default: linux/amd64,linux/arm64
permissions:
packages: write
contents: write
jobs:
vars:
name: Generate variables
runs-on: ubuntu-latest
outputs:
short-sha: ${{ steps.infos.outputs.SHORT_SHA }}
platforms-json: ${{ steps.infos.outputs.PLATFORMS_JSON }}
steps:
- name: Checks-out repository
uses: actions/checkout@v4
- name: Get variables
id: infos
run: |
echo "SHORT_SHA=sha-$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "PLATFORMS_JSON=$(echo '"${{ inputs.PLATFORMS }}"' | jq -c 'split(",")')" >> $GITHUB_OUTPUT
build-binaries:
name: Build application binaries
runs-on: ubuntu-latest
needs:
- vars
strategy:
matrix:
platforms: ${{ fromJson(needs.vars.outputs.platforms-json) }}
steps:
- name: Checks-out repository
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ inputs.GO_VERSION }}
- name: Install dependencies
run: go mod download
- name: Run vet command
run: go vet .
- name: Run build
run: |
export BUILD_OS="$(echo ${{ matrix.platforms }} | cut -d '/' -f 1)"
export BUILD_ARCH="$(echo ${{ matrix.platforms }} | cut -d '/' -f 2,3)"
echo "BUILD_OS=$BUILD_OS" >> $GITHUB_ENV
echo "BUILD_ARCH=$BUILD_ARCH" >> $GITHUB_ENV
CGO_ENABLED=0 GOOS=${BUILD_OS} GOARCH=${BUILD_ARCH} \
go build -o ./binaries/external-dns-midaas-webhook_${BUILD_OS}-${BUILD_ARCH} .
- name: Upload build results
uses: actions/upload-artifact@v4
with:
name: external-dns-midaas-webhook_${{ env.BUILD_OS }}-${{ env.BUILD_ARCH }}
path: ./binaries/external-dns-midaas-webhook_${{ env.BUILD_OS }}-${{ env.BUILD_ARCH }}
build-docker:
name: Build application image
runs-on: ubuntu-latest
needs:
- vars
steps:
- name: Checks-out repository
uses: actions/checkout@v4
- name: Set up Docker buildx
uses: docker/setup-buildx-action@v3
- name: Set up QEMU (for multi platform build)
uses: docker/setup-qemu-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ inputs.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
logout: true
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ inputs.REGISTRY }}/${{ inputs.NAMESPACE }}
tags: |
type=raw,value=${{ needs.vars.outputs.short-sha }},enable=${{ inputs.TAG == '' }}
type=raw,value=${{ inputs.TAG }},enable=${{ inputs.TAG != '' }}
type=raw,value=${{ inputs.MAJOR_TAG }}.${{ inputs.MINOR_TAG }},enable=${{ inputs.MAJOR_TAG != '' && inputs.MINOR_TAG != '' }}
type=raw,value=${{ inputs.MAJOR_TAG }},enable=${{ inputs.MAJOR_TAG != '' }}
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
- name: Build and push docker image
id: build
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
target: prod
provenance: false
platforms: ${{ inputs.PLATFORMS }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: true
cache-from: type=gha
cache-to: type=gha,mode=max