-
Notifications
You must be signed in to change notification settings - Fork 0
137 lines (123 loc) · 3.82 KB
/
image.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
name: Container Image
on:
pull_request:
branches:
- main
push:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
ARTIFACT_REGISTRY: europe-north1-docker.pkg.dev
ARTIFACT_REPO: nais-io/nais/images
SERVICE_ACCOUNT: [email protected]
jobs:
meta:
name: Metadata
runs-on: ubuntu-latest
outputs:
"version": ${{ steps.version.outputs.version }}
"name": ${{ steps.name.outputs.name }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- id: version
run: echo "version=$(date +'%Y%m%d')-$(git rev-parse --short HEAD)" >> ${GITHUB_OUTPUT}
- id: name
run: echo "name=${{ github.event.repository.name }}" >> ${GITHUB_OUTPUT}
lint:
name: Lint code
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go environment
uses: actions/setup-go@v5
with:
go-version: "1.23"
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
args: --timeout=5m
build:
name: Build and Test code
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Restore cached binaries
uses: actions/cache/restore@v4
with:
path: ${{ github.workspace }}/bin
key: ${{ runner.os }}-bin-${{ hashFiles('Makefile', 'go.mod') }}
- name: Set up Go environment
uses: actions/setup-go@v5
with:
go-version: "1.23"
check-latest: true
- name: Install make
run: sudo apt-get update && sudo apt-get install make
- run: make fmt
- run: make vet
- run: make check
- run: make test
- run: make build
- name: Cache installed binaries
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/bin
key: ${{ runner.os }}-bin-${{ hashFiles('Makefile', 'go.mod') }}
docker:
name: Build and push Docker image
permissions:
contents: read
id-token: write
runs-on: ubuntu-latest-16-cores
needs: meta
steps:
- name: Checkout
uses: actions/checkout@v4
- id: "auth"
if: github.actor != 'dependabot[bot]'
name: "Authenticate to Google Cloud"
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ secrets.NAIS_IO_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ env.SERVICE_ACCOUNT }}
token_format: "access_token"
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Login to registry
if: github.actor != 'dependabot[bot]'
uses: docker/login-action@v3
with:
registry: ${{ env.ARTIFACT_REGISTRY }}/${{ env.ARTIFACT_REPO }}
username: "oauth2accesstoken"
password: "${{ steps.auth.outputs.access_token }}"
- name: Docker meta
id: metadata
uses: docker/metadata-action@v5
with:
images: ${{ env.ARTIFACT_REGISTRY }}/${{ env.ARTIFACT_REPO }}/${{ needs.meta.outputs.name }}
# Docker tags based on the following events/attributes
tags: |
type=schedule
type=ref,event=branch
type=sha
type=raw,value=${{ needs.meta.outputs.version }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
push: ${{ github.ref == 'refs/heads/main' }}
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max