-
Notifications
You must be signed in to change notification settings - Fork 16
184 lines (157 loc) · 5.65 KB
/
build.yaml
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
name: Build
permissions:
contents: read
packages: write
on:
push:
branches:
- main
release:
types:
- published
pull_request:
branches:
- main
jobs:
build:
name: Build
runs-on: ubuntu-20.04
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.22.4
- name: Cache Go modules
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-build-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-build-
- name: Get release tag
if: github.event_name == 'release'
run: echo "RELEASE_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Get merge request latest commit
if: ${{ github.event_name == 'pull_request' }}
id: parse-commit-sha
run: |
head=$(git rev-parse HEAD)
echo "head_commit_sha=${head}" >> $GITHUB_ENV
echo "Head commit sha ${head}"
- name: Secret Scanning
uses: trufflesecurity/trufflehog@main
with:
extra_args: --only-verified
- name: Build Go binary amd64
run: go build -ldflags "-s -w -X main.GitCommit=$GITHUB_SHA -X main.GitRef=$GITHUB_REF -X main.Version=${RELEASE_TAG:-commit-$GITHUB_SHA}" -o bin/castai-agent-amd64 .
env:
GOOS: linux
GOARCH: amd64
CGO_ENABLED: 0
- name: Build Go binary arm64
run: go build -ldflags "-s -w -X main.GitCommit=$GITHUB_SHA -X main.GitRef=$GITHUB_REF -X main.Version=${RELEASE_TAG:-commit-$GITHUB_SHA}" -o bin/castai-agent-arm64 .
env:
GOOS: linux
GOARCH: arm64
CGO_ENABLED: 0
- name: Test
run: go test -race ./...
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Google Artifact Registry
if: github.event_name == 'release'
uses: docker/login-action@v3
with:
registry: us-docker.pkg.dev
username: _json_key
password: ${{ secrets.ARTIFACT_BUILDER_JSON_KEY }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
if: ${{ github.event_name == 'pull_request' }}
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push pr
if: ${{ github.event_name == 'pull_request' }}
uses: docker/build-push-action@v3
with:
context: .
push: true
platforms: linux/arm64,linux/amd64
tags: ghcr.io/castai/k8s-agent:${{ env.head_commit_sha }}
- name: Build and push main
if: github.event_name != 'release'
uses: docker/build-push-action@v3
with:
context: .
push: false
platforms: linux/arm64,linux/amd64
tags: us-docker.pkg.dev/castai-hub/library/agent:${{ github.sha }}
- name: Build and push main RedHat UBI
if: github.event_name != 'release'
uses: docker/build-push-action@v3
with:
context: .
file: ./redhat/Dockerfile
push: false
platforms: linux/arm64,linux/amd64
tags: us-docker.pkg.dev/castai-hub/library/agent-rh-ubi:${{ github.sha }}
- name: Build and push release
if: github.event_name == 'release'
uses: docker/build-push-action@v3
with:
context: .
push: true
platforms: linux/arm64,linux/amd64
tags: |
us-docker.pkg.dev/castai-hub/library/agent:${{ env.RELEASE_TAG }}
us-docker.pkg.dev/castai-hub/library/agent:latest
- name: Build and push release RedHat UBI
if: github.event_name == 'release'
uses: docker/build-push-action@v3
with:
context: .
file: ./redhat/Dockerfile
push: true
platforms: linux/arm64,linux/amd64
tags: |
us-docker.pkg.dev/castai-hub/library/agent-rh-ubi:${{ env.RELEASE_TAG }}
us-docker.pkg.dev/castai-hub/library/agent-rh-ubi:latest
- name: Docker pull for fossa main
if: github.event_name == 'release'
run: docker pull us-docker.pkg.dev/castai-hub/library/agent:${{ env.RELEASE_TAG }}
- name: Docker pull for fossa main RedHat UBI
if: github.event_name == 'release'
run: docker pull us-docker.pkg.dev/castai-hub/library/agent-rh-ubi:${{ env.RELEASE_TAG }}
- name: FOSSA scan docker image
if: github.event_name == 'release'
continue-on-error: true
uses: fossas/fossa-action@v1
with:
api-key: ${{ secrets.FOSSA_API_KEY }}
container: us-docker.pkg.dev/castai-hub/library/agent:${{ env.RELEASE_TAG }}
- name: FOSSA scan docker image RedHat UBI
if: github.event_name == 'release'
continue-on-error: true
uses: fossas/fossa-action@v1
with:
api-key: ${{ secrets.FOSSA_API_KEY }}
container: us-docker.pkg.dev/castai-hub/library/agent-rh-ubi:${{ env.RELEASE_TAG }}
- name: Release
uses: softprops/action-gh-release@v2
if: github.event_name == 'release'
with:
files: |
bin/castai-agent-amd64
bin/castai-agent-arm64
- name: Summary
if: ${{ github.event_name == 'pull_request' }}
run: |
echo "**Pushed docker images:**" >> $GITHUB_STEP_SUMMARY
echo "ghcr.io/castai/k8s-agent:${{ github.sha }}" >> $GITHUB_STEP_SUMMARY