Skip to content

Commit 552da65

Browse files
committed
feat(ci/github/operator): add ci to build operator container to github
1 parent 932fed2 commit 552da65

File tree

3 files changed

+113
-30
lines changed

3 files changed

+113
-30
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Build when operator code changes
2+
name: Build and push operator container image
3+
4+
on:
5+
pull_request:
6+
branches:
7+
- main
8+
paths:
9+
- operator/**/*.go
10+
- containers/operator.Dockerfile
11+
- .github/workflows/operator-container.yaml
12+
push:
13+
branches:
14+
- main
15+
tags:
16+
- operator/*
17+
paths:
18+
- operator/**/*.go
19+
- containers/operator.Dockerfile
20+
- .github/workflows/operator-container.yaml
21+
22+
# NOTE: we may want to switch to matrix build for multi-platform support if this is taking too long
23+
# https://docs.docker.com/build/ci/github-actions/multi-platform/#distribute-build-across-multiple-runners
24+
25+
26+
# 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.
27+
env:
28+
REGISTRY: ghcr.io
29+
IMAGE_NAME: ${{ github.repository }}
30+
GO_VERSION: 1.23.4
31+
32+
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
33+
jobs:
34+
build-and-push-operator:
35+
runs-on: ubuntu-latest
36+
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
37+
permissions:
38+
contents: read
39+
packages: write
40+
attestations: write
41+
id-token: write
42+
#
43+
steps:
44+
- name: Checkout repository
45+
uses: actions/checkout@v4
46+
# 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.
47+
- name: Log in to the Container registry
48+
uses: docker/login-action@v3
49+
with:
50+
registry: ${{ env.REGISTRY }}
51+
username: ${{ github.actor }}
52+
password: ${{ secrets.GITHUB_TOKEN }}
53+
54+
# Setup for multi-platform
55+
- name: Set up QEMU
56+
uses: docker/setup-qemu-action@v3
57+
58+
- name: Set up Docker Buildx
59+
uses: docker/setup-buildx-action@v3
60+
61+
/kaniko/executor
62+
--build-arg GIT_SHA="${CI_COMMIT_SHORT_SHA}"
63+
--build-arg VERSION="${CI_COMMIT_TAG}"
64+
--build-arg GO_VERSION="${GO_VERSION}"
65+
--context "${CI_PROJECT_DIR}"
66+
--dockerfile "${CI_PROJECT_DIR}/containers/operator.Dockerfile"
67+
--destination "${REGISTRY_IMAGE}:latest"
68+
--destination "${REGISTRY_IMAGE}:${VERSION}"
69+
70+
- name: Build the operator container image
71+
id: build
72+
run: |
73+
apt-get update && apt-get install -y make git jq
74+
cd operator
75+
# if this is a tag build, use the tag as the version, otherwise use the sha
76+
TAGS="-t ${REGISTRY@L}/${{env.IMAGE_NAME}}/operator:${{ github.sha }} -t ${REGISTRY@L}/${{env.IMAGE_NAME}}/operator:latest"
77+
case ${{ github.ref_type }} in
78+
branch)
79+
# The last tag + current git sha
80+
export OPERATOR_VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0")+${{ github.sha }}
81+
;;
82+
tag)
83+
# The version part of the tag
84+
export OPERATOR_VERSION=$(echo "${{ github.ref_name }}" | cut -f 2 -d /)
85+
TAGS="$TAGS -t ${REGISTRY@L}/${{env.IMAGE_NAME}}/operator:${OPERATOR_VERSION}"
86+
;;
87+
*)
88+
echo "Unkown type ${{ github.ref_type }}"
89+
exit 1
90+
;;
91+
esac
92+
export TAGS=$TAGS
93+
export REGISTRY=${REGISTRY@L}
94+
export BUILD_ARGS="--push"
95+
docker buildx build \
96+
--build-arg GIT_SHA=$${{ github.sha }} \
97+
--build-arg VERSION=${OPERATOR_VERSION} \
98+
--build-arg GO_VERSION=${GO_VERSION} \
99+
--platform linux/amd64,linux/arm64 ${TAGS} \
100+
--metadata-file=metadata.json \
101+
-f ../containers/operator.Dockerfile .
102+
cat metadata.json
103+
echo "digest=$(cat metadata.json | jq -r .\"containerimage.digest\")" >> $GITHUB_OUTPUT
104+
cat $GITHUB_OUTPUT
105+
106+
# 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).
107+
- name: Generate artifact attestation
108+
uses: actions/attest-build-provenance@v2
109+
with:
110+
subject-name: ${{ env.REGISTRY }}/${{env.IMAGE_NAME}}/operator
111+
subject-digest: ${{ steps.build.outputs.digest }}
112+
push-to-registry: true
113+
File renamed without changes.

operator/runtime_required.md

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)