-
Notifications
You must be signed in to change notification settings - Fork 0
117 lines (110 loc) · 3.3 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
name: Build and push knorten image to GAR
on:
push:
env:
IMAGE_NAME: europe-north1-docker.pkg.dev/knada-gcp/knada-north/knorten
jobs:
golangci:
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.55.2
staticchecks:
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
- uses: dominikh/staticcheck-action@v1
with:
version: "latest"
install-go: false
tests:
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
- run: go test -v ./...
build:
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
- run: CGO_ENABLED=0 go build -ldflags "-w -s" -o knorten main.go
- uses: actions/upload-artifact@v4
with:
name: knorten
path: knorten
push:
permissions:
contents: write
id-token: write
runs-on: ubuntu-latest
needs: [build,golangci,tests,staticchecks]
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Google auth
id: auth
uses: google-github-actions/auth@v2
with:
token_format: access_token
workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }}
service_account: ci-knada-images@knada-gcp.iam.gserviceaccount.com
- name: Login to Google Artifact Registry
uses: docker/login-action@v3
with:
registry: europe-north1-docker.pkg.dev
username: oauth2accesstoken
password: ${{ steps.auth.outputs.access_token }}
- name: Create image tag
run: |
echo "IMAGE=$IMAGE_NAME:$(git --no-pager log -1 --pretty=format:%H)" >> $GITHUB_ENV
- name: Download knorten binary
uses: actions/download-artifact@v4
with:
name: knorten
- name: Build and push Dockerimage
uses: docker/build-push-action@v6
with:
file: Dockerfile-ci
context: .
push: true
tags: ${{ env.IMAGE }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Update imagetag in dev k8s manifest
if: github.ref == 'refs/heads/main'
working-directory: k8s/overlays/dev
run: |
kustomize edit set image ${{ env.IMAGE }}
- name: Update imagetag in prod k8s manifest
if: github.ref == 'refs/heads/main'
working-directory: k8s/overlays/prod
run: |
kustomize edit set image ${{ env.IMAGE }}
- name: Commit tag changes
if: github.ref == 'refs/heads/main'
run: |
git config --global user.email ${{ github.actor }}@users.noreply.github.com
git config --global user.name ${{ github.actor }}
git add k8s/overlays
git commit -m "Updated image tag"
git push