-
Notifications
You must be signed in to change notification settings - Fork 5
193 lines (183 loc) · 7.3 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
name: build
on: [workflow_dispatch, push]
env:
PRD_NAME: "consul-lambda"
REG_NAME: "consul-lambda-registrator"
EXT_NAME: "consul-lambda-extension"
jobs:
action-lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- name: Lint workflow
uses: docker://docker.mirror.hashicorp.services/rhysd/actionlint:latest
get-go-version:
needs: action-lint
uses: ./.github/workflows/reusable-get-go-version.yml
get-product-version:
defaults:
run:
working-directory: ./consul-lambda
runs-on: ubuntu-latest
needs: action-lint
outputs:
product-version: ${{ steps.get-product-version.outputs.product-version }}
ldflags: ${{ steps.get-product-version.outputs.ldflags }}
git-short-sha: ${{ steps.get-product-version.outputs.git-short-sha }}
steps:
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- name: get product version
id: get-product-version
run: |
{
echo "product-version=$(make version)"
echo "ldflags=-s -w"
echo "git-short-sha=$(git rev-parse --short HEAD)"
} >> "$GITHUB_OUTPUT"
generate-metadata-file:
defaults:
run:
working-directory: ./consul-lambda
runs-on: ubuntu-latest
needs: [action-lint, get-product-version]
outputs:
filepath: ${{ steps.generate-metadata-file.outputs.filepath }}
steps:
- name: "Checkout directory"
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- name: Generate metadata file
id: generate-metadata-file
uses: hashicorp/actions-generate-metadata@v1
with:
version: ${{ needs.get-product-version.outputs.product-version }}
product: ${{ env.PRD_NAME }}
repositoryOwner: "hashicorp"
- uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
with:
name: metadata.json
path: ${{ steps.generate-metadata-file.outputs.filepath }}
build-linux:
strategy:
matrix:
goos:
- linux
goarch:
- amd64
- arm64
defaults:
run:
working-directory: ./consul-lambda
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
LDFLAGS: ${{ needs.get-product-version.outputs.ldflags }}
CGO_ENABLED: 0
needs:
- get-go-version
- get-product-version
runs-on: ubuntu-latest
name: Go build
steps:
- name: Checkout
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- name: Setup go
uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0
with:
go-version: ${{ needs.get-go-version.outputs.go-version }}
cache-dependency-path: ./consul-lambda/go.sum
- name: Build
run: |
mkdir dist out extensions
cd consul-lambda-registrator
go build -ldflags="$LDFLAGS" -o ../dist/ .
cd ..
cd consul-lambda-extension
go build -ldflags="$LDFLAGS" -o ../extensions/ .
cd ..
zip -r -j out/${{ env.REG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ env.GOOS }}_${{ env.GOARCH }}.zip dist/
zip -r out/${{ env.EXT_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ env.GOOS }}_${{ env.GOARCH }}.zip extensions/
- name: Upload consul-lambda-registrator
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
with:
name: ${{ env.REG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ env.GOOS }}_${{ env.GOARCH }}.zip
path: ./consul-lambda/out/${{ env.REG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ env.GOOS }}_${{ env.GOARCH }}.zip
- name: Upload consul-lambda-extension
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
with:
name: ${{ env.EXT_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ env.GOOS }}_${{ env.GOARCH }}.zip
path: ./consul-lambda/out/${{ env.EXT_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ env.GOOS }}_${{ env.GOARCH }}.zip
build-docker-default:
strategy:
matrix:
goarch:
- amd64
- arm64
defaults:
run:
working-directory: ./consul-lambda/consul-lambda-registrator
name: Docker consul-lambda-registrator build
needs:
- get-product-version
- build-linux
runs-on: ubuntu-latest
env:
version: ${{ needs.get-product-version.outputs.product-version }}
arch: ${{ matrix.goarch }}
steps:
- name: Checkout
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- name: Docker Build
uses: hashicorp/actions-docker-build@v1
with:
pkg_name: ${{ env.REG_NAME }}_${{ env.version }}
bin_name: ${{ env.REG_NAME }}
version: ${{ env.version }}
target: release-default
workdir: ./consul-lambda/consul-lambda-registrator
arch: ${{ env.arch }}
tags: |
docker.io/hashicorp/${{ env.REG_NAME }}:${{ env.version }}
public.ecr.aws/hashicorp/${{ env.REG_NAME }}:${{ env.version }}
dev_tags: |
hashicorppreview/${{ env.REG_NAME }}:${{ env.version }}
docker.io/hashicorppreview/${{ env.REG_NAME }}:${{ env.version }}
upload-dev-docker:
name: Upload dev image (hashicorpdev/consul-lambda-registrator:<commit>)
environment: dockerhub/hashicorpdev
needs:
- get-product-version
- build-docker-default
runs-on: ubuntu-latest
env:
repo: ${{ github.event.repository.name }}
version: ${{ needs.get-product-version.outputs.product-version }}
arch: amd64
target: release-default
git-short-sha: ${{ needs.get-product-version.outputs.git-short-sha }}
steps:
- name: Download image artifact
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: ${{ env.repo }}_${{ env.target }}_linux_${{ env.arch }}_${{ env.version }}_${{ github.sha }}.docker.dev.tar
- name: Docker push
shell: bash
run: |
TAG=hashicorpdev/${{ env.REG_NAME }}:${{ env.git-short-sha }}
echo "==> Load docker image from tar archive"
docker load -i "${{ env.repo }}_${{ env.target }}_linux_${{ env.arch }}_${{ env.version }}_${{ github.sha }}.docker.dev.tar"
echo "==> Tag docker image $TAG"
docker tag "hashicorppreview/${{ env.REG_NAME }}:${{ env.version }}" "$TAG"
echo "==> Docker login"
echo ${{ secrets.DOCKER_PASS }} | docker login -u=${{ secrets.DOCKER_USER }} --password-stdin
echo "==> Push docker image $TAG"
docker push "$TAG"
- name: Docker push (latest)
shell: bash
if: ${{ github.ref == 'refs/heads/main' }}
run: |
TAG=hashicorpdev/${{ env.REG_NAME }}:latest
echo "==> Tag docker image $TAG as :latest"
docker tag "hashicorpdev/${{ env.REG_NAME }}:${{ env.git-short-sha }}" "$TAG"
echo "==> Push docker image $TAG"
docker push "$TAG"