-
Notifications
You must be signed in to change notification settings - Fork 32
134 lines (125 loc) · 4.87 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
name: build
on:
push:
branches:
- main
- release/**
workflow_dispatch:
env:
PKG_NAME: 'hcp-terraform-operator'
PKG_PATH: 'github.com/hashicorp/hcp-terraform-operator'
DOCKER_HUB_REPO: 'hashicorp/hcp-terraform-operator'
DOCKER_HUB_DEV_REPO: 'hashicorppreview/hcp-terraform-operator'
jobs:
set-product-version:
runs-on: ubuntu-latest
outputs:
product-version: ${{ steps.set-product-version.outputs.product-version }}
steps:
- name: Checkout repository
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- name: Set product version
id: set-product-version
uses: hashicorp/actions-set-product-version@d9b52fb778068099ca4c5e28e1ca0fee2544e114 # v2
generate-metadata-file:
needs: set-product-version
runs-on: ubuntu-latest
env:
METADATA_FILE_NAME: 'metadata.json'
outputs:
filepath: ${{ steps.generate-metadata-file.outputs.filepath }}
steps:
- name: Checkout repository
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- name: Generate metadata file
id: generate-metadata-file
uses: hashicorp/actions-generate-metadata@fdbc8803a0e53bcbb912ddeee3808329033d6357 # v1.1.1
with:
version: ${{ needs.set-product-version.outputs.product-version }}
product: ${{ env.PKG_NAME }}
repositoryOwner: 'hashicorp'
metadataFileName: ${{ env.METADATA_FILE_NAME }}
- uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: metadata.json
path: ${{ env.METADATA_FILE_NAME }}
build:
name: Go Linux ${{ matrix.arch }} build
needs: [set-product-version]
runs-on: ubuntu-latest
outputs:
go-version: ${{ steps.set-up-go.outputs.go-version }}
strategy:
matrix:
arch: ["amd64", "arm64"]
steps:
- name: Checkout repository
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- name: Setup Go
id: set-up-go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version-file: 'go.mod'
- name: Go build
uses: hashicorp/actions-go-build@37358f6098ef21b09542d84a9814ebb843aa4e3e # v1
env:
CGO_ENABLED: 0
LD_FLAGS: "-X '${{ env.PKG_PATH }}/version.Version=${{ needs.set-product-version.outputs.product-version }}'"
with:
product_name: ${{ env.PKG_NAME }}
product_version: ${{ needs.set-product-version.outputs.product-version }}
bin_name: ${{ vars.BIN_NAME }}
go_version: ${{ steps.set-up-go.outputs.go-version }}
os: linux
arch: ${{ matrix.arch }}
reproducible: report
instructions: |
go build -a -ldflags="${{ env.LD_FLAGS }}" -trimpath -o $BIN_PATH main.go
build-docker:
name: Docker ${{ matrix.arch }} build
needs: [build, set-product-version]
runs-on: ubuntu-latest
strategy:
matrix:
arch: ["amd64", "arm64"]
steps:
- name: Checkout repository
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- name: Docker build
uses: hashicorp/actions-docker-build@11d43ef520c65f58683d048ce9b47d6617893c9a # v2
env:
VERSION: ${{ needs.set-product-version.outputs.product-version }}
GO_VERSION: ${{ needs.build.outputs.go-version }}
with:
version: ${{ env.VERSION }}
bin_name: ${{ vars.BIN_NAME }}
target: release-default
arch: ${{ matrix.arch }}
tags: |
docker.io/${{ env.DOCKER_HUB_REPO }}:${{ env.VERSION }}
dev_tags: |
docker.io/${{ env.DOCKER_HUB_DEV_REPO }}:${{ env.VERSION }}
docker.io/${{ env.DOCKER_HUB_DEV_REPO }}:${{ env.VERSION }}-${{ github.sha }}
build-docker-ubi:
name: Docker build UBI
needs: [build, set-product-version]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- name: Docker build
uses: hashicorp/actions-docker-build@11d43ef520c65f58683d048ce9b47d6617893c9a # v2
env:
VERSION: ${{ needs.set-product-version.outputs.product-version }}
GO_VERSION: ${{ needs.build.outputs.go-version }}
with:
version: ${{ env.VERSION }}
bin_name: ${{ vars.BIN_NAME }}
target: release-ubi
arch: amd64
tags: |
docker.io/${{ env.DOCKER_HUB_REPO }}:${{ env.VERSION }}-ubi
dev_tags: |
docker.io/${{ env.DOCKER_HUB_DEV_REPO }}:${{ env.VERSION }}-ubi
docker.io/${{ env.DOCKER_HUB_DEV_REPO }}:${{ env.VERSION }}-ubi-${{ github.sha }}
redhat_tag: quay.io/redhat-isv-containers/671273c6fbc31c69e20237c0:${{ env.VERSION }}