Skip to content

Commit 22e20c3

Browse files
committed
refactor(ci): use buildah binary instead of external actions
1 parent d90f1a0 commit 22e20c3

6 files changed

Lines changed: 89 additions & 65 deletions

File tree

.github/workflows/_reusable-build.yaml

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ on:
1515

1616
env:
1717
REGISTRY: ghcr.io
18+
GO_VERSION: '1.26.5'
1819

1920
permissions:
2021
contents: read
@@ -31,39 +32,52 @@ jobs:
3132
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
3233
with:
3334
ref: ${{ inputs.checkout_ref || github.ref }}
35+
fetch-depth: 0
3436

35-
- name: Log in to GHCR
36-
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
37+
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
3738
with:
38-
registry: ${{ env.REGISTRY }}
39-
username: ${{ github.actor }}
40-
password: ${{ secrets.GITHUB_TOKEN }}
39+
go-version: ${{ env.GO_VERSION }}
40+
41+
- name: Log in to GHCR
42+
uses: ./.github/actions/ghcr-login
43+
44+
- name: Compute build metadata
45+
id: meta
46+
run: |
47+
VERSION=$(git describe --tags)
48+
COMMIT=$(git log --format="%h" -n 1)
49+
TREE_STATE=$(git diff --quiet && echo 'clean' || echo 'dirty')
50+
IMAGE="${{ env.REGISTRY }}/${{ github.repository }}${{ inputs.image_suffix }}"
51+
echo "version=${VERSION}" >> "${GITHUB_OUTPUT}"
52+
echo "commit=${COMMIT}" >> "${GITHUB_OUTPUT}"
53+
echo "tree_state=${TREE_STATE}" >> "${GITHUB_OUTPUT}"
54+
echo "image=${IMAGE}" >> "${GITHUB_OUTPUT}"
4155
4256
- name: Build image
4357
id: build-image
44-
uses: aardbol/buildah-build@14762338941c54f8835374e1844663c745dadb2a # v3.0.3
45-
with:
46-
image: ${{ github.repository }}${{ inputs.image_suffix }}
47-
tags: ${{ inputs.tags }}
48-
context: .
49-
containerfiles: cmd/upcloud-csi-plugin/Containerfile
50-
platforms: linux/amd64
51-
extra-args: --pull=always
58+
env:
59+
VERSION: ${{ steps.meta.outputs.version }}
60+
COMMIT: ${{ steps.meta.outputs.commit }}
61+
TREE_STATE: ${{ steps.meta.outputs.tree_state }}
62+
IMAGE: ${{ steps.meta.outputs.image }}
63+
IMAGE_TAG: ${{ inputs.tags }}
64+
run: ./build-image.sh
5265

5366
- name: Push image
5467
id: push-image
55-
uses: aardbol-actions/push-to-registry@5402e3869fc3a6b2c0de9f078dbfe87f82f2fe76 # v3.0.3
56-
with:
57-
image: ${{ steps.build-image.outputs.image }}
58-
tags: ${{ inputs.tags }}
59-
registry: ${{ env.REGISTRY }}
68+
run: |
69+
DIGESTFILE=$(mktemp)
70+
buildah push --digestfile "${DIGESTFILE}" \
71+
"${{ steps.meta.outputs.image }}:${{ inputs.tags }}" \
72+
"docker://${{ steps.meta.outputs.image }}:${{ inputs.tags }}"
73+
echo "digest=$(cat "${DIGESTFILE}")" >> "${GITHUB_OUTPUT}"
6074
6175
- name: Build summary
6276
run: |
6377
echo "## Container image" >> "$GITHUB_STEP_SUMMARY"
6478
echo "" >> "$GITHUB_STEP_SUMMARY"
6579
echo "| Field | Value |" >> "$GITHUB_STEP_SUMMARY"
6680
echo "|---|---|" >> "$GITHUB_STEP_SUMMARY"
67-
echo "| Image | \`${{ steps.build-image.outputs.image }}\` |" >> "$GITHUB_STEP_SUMMARY"
81+
echo "| Image | \`${{ steps.meta.outputs.image }}\` |" >> "$GITHUB_STEP_SUMMARY"
6882
echo "| Tags | \`${{ inputs.tags }}\` |" >> "$GITHUB_STEP_SUMMARY"
6983
echo "| Digest | \`${{ steps.push-image.outputs.digest }}\` |" >> "$GITHUB_STEP_SUMMARY"

.github/workflows/trivy-scan.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
- "**/*.go"
99
- go.mod
1010
- go.sum
11-
- cmd/upcloud-csi-plugin/Containerfile
11+
- build-image.sh
1212
- '.github/workflows/trivy-scan.yaml'
1313
- '.trivyignore.yaml'
1414
pull_request:
@@ -39,7 +39,7 @@ jobs:
3939
- '**/*.go'
4040
- go.mod
4141
- go.sum
42-
- 'cmd/upcloud-csi-plugin/Containerfile'
42+
- 'build-image.sh'
4343
- '.github/workflows/trivy-scan.yaml'
4444
- '.trivyignore.yaml'
4545

AGENTS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
- Pin to a specific release like `ubuntu-24.04`. Never use `ubuntu-latest`.
66
- Pin every action by commit SHA with a comment containing the readable version, e.g. `actions/checkout@df4cb1c0... # v6.0.3`.
77
- Do NOT add install steps for tools that ship with the base image (`kubectl`, `docker`, `git`, `curl`, etc.). Check the [current image contents](https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2404-Readme.md) before adding an install step.
8-
- Container builds use `buildah` via `redhat-actions/buildah-build` + `redhat-actions/push-to-registry`. Containerfile at `cmd/upcloud-csi-plugin/Containerfile`.
8+
- Container builds use `buildah` binary on runner image.
99

1010
## Versioning and changelogs
1111

@@ -18,7 +18,7 @@
1818

1919
## Go
2020

21-
- Version: `1.26` (must match `go.mod` and Containerfile)
21+
- Version: `1.26` (must match `go.mod` and `build-image.sh`)
2222
- Test: `make test` runs `go vet ./... && go test -race ./...`
2323
- Lint: `golangci-lint` with config in `.golangci.yml`. Run via `cd test/e2e && golangci-lint run --timeout=2m ./testruns/` or pre-commit.
2424

Makefile

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
TAG ?= $(shell git describe --tags)
22
COMMIT = $(shell git log --format="%h" -n 1)
33
TREE_STATE = $(shell git diff --quiet && echo 'clean' || echo 'dirty')
4+
TARGETARCH ?= amd64
45

56
CONTAINER_REPO ?= ghcr.io/upcloud-tools/upcloud-csi-test
67
IMAGE_TAG ?= $(shell git rev-parse HEAD)
78

89

910
.PHONY: container-build
1011
container-build:
11-
buildah build --platform linux/amd64 \
12-
--build-arg VERSION=$(TAG) \
13-
--build-arg COMMIT=$(COMMIT) \
14-
--build-arg TREE_STATE=$(TREE_STATE) \
15-
-t $(CONTAINER_REPO):$(IMAGE_TAG) \
16-
-f cmd/upcloud-csi-plugin/Containerfile .
12+
TARGETARCH=$(TARGETARCH) VERSION=$(TAG) COMMIT=$(COMMIT) TREE_STATE=$(TREE_STATE) \
13+
IMAGE=$(CONTAINER_REPO) IMAGE_TAG=$(IMAGE_TAG) ./build-image.sh
1714

1815
.PHONY: push-image
1916
push-image: container-build

build-image.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
VERSION="${VERSION:-unknown}"
5+
COMMIT="${COMMIT:-unknown}"
6+
TREE_STATE="${TREE_STATE:-unknown}"
7+
TARGETARCH="${TARGETARCH:-amd64}"
8+
IMAGE="${IMAGE:-upcloud-csi}"
9+
IMAGE_TAG="${IMAGE_TAG:-latest}"
10+
11+
ALPINE_VERSION="3.23.5"
12+
13+
echo "Building ${IMAGE}:${IMAGE_TAG} (arch=${TARGETARCH}, version=${VERSION})"
14+
15+
CGO_ENABLED=0 GOOS=linux GOARCH="${TARGETARCH}" \
16+
go build -ldflags="-s -w \
17+
-X github.com/upcloud-tools/upcloud-csi/internal/plugin.version=${VERSION} \
18+
-X github.com/upcloud-tools/upcloud-csi/internal/plugin.commit=${COMMIT} \
19+
-X github.com/upcloud-tools/upcloud-csi/internal/plugin.gitTreeState=${TREE_STATE}" \
20+
-o upcloud-csi-plugin ./cmd/upcloud-csi-plugin
21+
22+
CTR=$(buildah from docker.io/alpine:${ALPINE_VERSION})
23+
24+
buildah run "${CTR}" -- apk add --no-cache \
25+
ca-certificates \
26+
cloud-utils-growpart \
27+
e2fsprogs \
28+
e2fsprogs-extra \
29+
eudev \
30+
nfs-utils \
31+
parted \
32+
util-linux \
33+
xfsprogs \
34+
xfsprogs-extra
35+
36+
buildah copy "${CTR}" upcloud-csi-plugin /bin/upcloud-csi-plugin
37+
38+
buildah config --os linux --arch "${TARGETARCH}" "${CTR}"
39+
buildah config --label "org.opencontainers.image.source=https://github.com/upcloud-tools/upcloud-csi" "${CTR}"
40+
buildah config --label "org.opencontainers.image.description=UpCloud CSI Driver" "${CTR}"
41+
buildah config --label "org.opencontainers.image.version=${VERSION}" "${CTR}"
42+
buildah config --entrypoint '["/bin/upcloud-csi-plugin"]' "${CTR}"
43+
44+
buildah commit --format docker "${CTR}" "${IMAGE}:${IMAGE_TAG}"
45+
buildah rm "${CTR}"
46+
47+
rm -f upcloud-csi-plugin
48+
49+
echo "Built ${IMAGE}:${IMAGE_TAG}"

cmd/upcloud-csi-plugin/Containerfile

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

0 commit comments

Comments
 (0)