-
Notifications
You must be signed in to change notification settings - Fork 6
171 lines (160 loc) · 6.03 KB
/
operator-ci.yaml
File metadata and controls
171 lines (160 loc) · 6.03 KB
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
#
# LICENSE START
#
# Copyright (c) NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# LICENSE END
#
# Build when operator code changes
name: Operator CI
on:
pull_request:
branches:
- main
paths:
- operator/**
- containers/operator.Dockerfile
- .github/workflows/operator-ci.yaml
- k8s-tests/**
push:
branches:
- main
tags:
- operator/*
paths:
- operator/**/*.go
- containers/operator.Dockerfile
- .github/workflows/operator-ci.yaml
- k8s-tests/**
# NOTE: we may want to switch to matrix build for multi-platform support if this is taking too long
# https://docs.docker.com/build/ci/github-actions/multi-platform/#distribute-build-across-multiple-runners
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
GO_VERSION: 1.23.7
PLATFORMS: linux/amd64,linux/arm64
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
jobs:
unit-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Go 1.23
uses: actions/setup-go@v5
with:
go-version: 1.23
- name: Unit tests
run: |
cd operator
make unit-tests
k8s-tests:
runs-on: ubuntu-latest
needs: [unit-test] # Don't run the k8s tests if the unit tests fail
steps:
- uses: actions/checkout@v4
with:
fetch-tags: true
fetch-depth: 0
- name: Setup Go 1.23
uses: actions/setup-go@v5
with:
go-version: 1.23
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Kubernetes KinD Cluster
id: kind
uses: helm/kind-action@v1
with:
version: v0.26.0
install_only: true
- name: end-to-end-tests
run: |
cd operator
GITHUB_TOKEN=${{ secrets.github_token }} make create-kind-cluster
make e2e-tests
build-and-push-operator:
runs-on: ubuntu-latest
needs: [k8s-tests] # Don't run the build and push if the k8s tests fail
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
permissions:
contents: read
packages: write
attestations: write
id-token: write
#
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Uses the `docker/login-action` action to log in to the Container registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Setup for multi-platform
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build the operator container image
id: build
env:
platforms: ${{ env.PLATFORMS }}
run: |
apt-get update && apt-get install -y make git jq
cd operator
# if this is a tag build, use the tag as the version, otherwise use the sha
TAGS="-t ${REGISTRY@L}/${{env.IMAGE_NAME}}/operator:${{ github.sha }}"
case ${{ github.ref_type }} in
branch)
# The last tag + current git sha
export OPERATOR_VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0")+${{ github.sha }}
;;
tag)
# The version part of the tag
export OPERATOR_VERSION=$(echo "${{ github.ref_name }}" | cut -f 2 -d /)
TAGS="$TAGS -t ${REGISTRY@L}/${{env.IMAGE_NAME}}/operator:${OPERATOR_VERSION} -t ${REGISTRY@L}/${{env.IMAGE_NAME}}/operator:latest"
;;
*)
echo "Unkown type ${{ github.ref_type }}"
exit 1
;;
esac
set -x
docker buildx build \
--build-arg GIT_SHA=$${{ github.sha }} \
--build-arg VERSION=${OPERATOR_VERSION} \
--build-arg GO_VERSION=${GO_VERSION} \
--push \
--platform ${{ env.PLATFORMS }} \
${TAGS@L} \
--metadata-file=metadata.json \
-f ../containers/operator.Dockerfile .
cat metadata.json
echo "digest=$(cat metadata.json | jq -r .\"containerimage.digest\")" >> $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
# This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see [AUTOTITLE](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds).
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v2
with:
subject-name: ${{ env.REGISTRY }}/${{env.IMAGE_NAME}}/operator
subject-digest: ${{ steps.build.outputs.digest }}
push-to-registry: true