Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.

Commit b442e23

Browse files
✨ use new builder image approach (#133)
* use new builder image approach this commit updates builder images and adds a make target so that we copy the static executables right from the container image. it's fast and we don't have to pull it from the internet again and again if we have the builder image present locally. This commit also updates go to 1.21.8 patch version. Signed-off-by: kranurag7 <[email protected]> * bump dev cluster to 1.27.3 and bump trivy Signed-off-by: kranurag7 <[email protected]> --------- Signed-off-by: kranurag7 <[email protected]> Co-authored-by: Roman Hros <[email protected]>
1 parent 9065b8a commit b442e23

File tree

6 files changed

+81
-69
lines changed

6 files changed

+81
-69
lines changed

.envrc.sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export PATH="$(pwd)/hack/tools/bin/:$PATH"
12
export KUBECONFIG=$PWD/.mgt-cluster-kubeconfig.yaml
23
export CLUSTER_TOPOLOGY=true
34
export CLUSTER_NAME=test-dfkhje

.github/workflows/release.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,16 @@ jobs:
121121
release:
122122
name: Create draft release
123123
runs-on: ubuntu-latest
124+
permissions:
125+
packages: read
126+
defaults:
127+
run:
128+
shell: bash
124129
needs:
125130
- manager-image
126131
steps:
127132
- name: Set env
133+
shell: bash
128134
run: echo "RELEASE_TAG=${GITHUB_REF:10}" >> $GITHUB_ENV
129135

130136
- name: checkout code

Makefile

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ IMAGE_PREFIX ?= ghcr.io/sovereigncloudstack
1919
STAGING_IMAGE = $(CONTROLLER_SHORT)-staging
2020
BUILDER_IMAGE = $(IMAGE_PREFIX)/$(CONTROLLER_SHORT)-builder
2121
BUILDER_IMAGE_VERSION = $(shell cat .builder-image-version.txt)
22+
HACK_TOOLS_BIN_VERSION = $(shell cat ./hack/tools/bin/version.txt)
2223

2324
SHELL = /usr/bin/env bash -o pipefail
2425
.SHELLFLAGS = -ec
@@ -117,27 +118,9 @@ $(CTLPTL):
117118
go install github.com/tilt-dev/ctlptl/cmd/[email protected]
118119

119120
CLUSTERCTL := $(abspath $(TOOLS_BIN_DIR)/clusterctl)
120-
clusterctl: $(CLUSTERCTL) ## Build a local copy of clusterctl
121-
$(CLUSTERCTL):
122-
curl -sSLf https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.5.3/clusterctl-$$(go env GOOS)-$$(go env GOARCH) -o $(CLUSTERCTL)
123-
chmod a+rx $(CLUSTERCTL)
124-
125121
KIND := $(abspath $(TOOLS_BIN_DIR)/kind)
126-
kind: $(KIND) ## Build a local copy of kind
127-
$(KIND):
128-
go install sigs.k8s.io/[email protected]
129-
130122
KUBECTL := $(abspath $(TOOLS_BIN_DIR)/kubectl)
131-
kubectl: $(KUBECTL) ## Build a local copy of kubectl
132-
$(KUBECTL):
133-
curl -fsSL "https://dl.k8s.io/release/v1.27.3/bin/$$(go env GOOS)/$$(go env GOARCH)/kubectl" -o $(KUBECTL)
134-
chmod a+rx $(KUBECTL)
135-
136123
TRIVY := $(abspath $(TOOLS_BIN_DIR)/trivy)
137-
trivy: $(TRIVY) ## Build a local copy of trivy
138-
$(TRIVY):
139-
curl -sSL https://github.com/aquasecurity/trivy/releases/download/v0.45.1/trivy_0.45.1_Linux-64bit.tar.gz | tar xz -C $(TOOLS_BIN_DIR) trivy
140-
chmod a+rx $(TRIVY)
141124

142125
go-binsize-treemap := $(abspath $(TOOLS_BIN_DIR)/go-binsize-treemap)
143126
go-binsize-treemap: $(go-binsize-treemap) # Build go-binsize-treemap from tools folder.
@@ -154,7 +137,7 @@ gotestsum: $(GOTESTSUM) # Build gotestsum from tools folder.
154137
$(GOTESTSUM):
155138
go install gotest.tools/[email protected]
156139

157-
all-tools: $(GOTESTSUM) $(go-cover-treemap) $(go-binsize-treemap) $(KIND) $(PACKER) $(KUBECTL) $(CLUSTERCTL) $(CTLPTL) $(SETUP_ENVTEST) $(ENVSUBST) $(KUSTOMIZE) $(CONTROLLER_GEN) $(TRIVY)
140+
all-tools: get-dependencies $(GOTESTSUM) $(go-cover-treemap) $(go-binsize-treemap) $(CTLPTL) $(SETUP_ENVTEST) $(ENVSUBST)
158141
echo 'done'
159142

160143
##@ Development
@@ -169,7 +152,7 @@ else
169152
endif
170153

171154
.PHONY: cluster
172-
cluster: $(CTLPTL) $(KUBECTL) ## Creates kind-dev Cluster
155+
cluster: get-dependencies $(CTLPTL) ## Creates kind-dev Cluster
173156
./hack/kind-dev.sh
174157

175158
.PHONY: delete-bootstrap-cluster
@@ -327,18 +310,6 @@ endif
327310
format-starlark: ## Format the Starlark codebase
328311
./hack/verify-starlark.sh fix
329312

330-
.PHONY: format-yaml
331-
format-yaml: ## Lint YAML files
332-
ifeq ($(BUILD_IN_CONTAINER),true)
333-
docker run --rm -t -i \
334-
-v $(shell go env GOPATH)/pkg:/go/pkg$(MOUNT_FLAGS) \
335-
-v $(shell pwd):/src/cluster-stack-provider-openstack$(MOUNT_FLAGS) \
336-
$(BUILDER_IMAGE):$(BUILDER_IMAGE_VERSION) $@;
337-
else
338-
yamlfixer --version
339-
yamlfixer -c .yamllint.yaml .
340-
endif
341-
342313
##@ Lint
343314
########
344315
# Lint #
@@ -556,7 +527,7 @@ test-integration-openstack: $(SETUP_ENVTEST) $(GOTESTSUM)
556527
lint: lint-golang lint-yaml lint-dockerfile lint-links ## Lint Codebase
557528

558529
.PHONY: format
559-
format: format-starlark format-golang format-yaml ## Format Codebase
530+
format: format-starlark format-golang ## Format Codebase
560531

561532
.PHONY: generate
562533
generate: generate-manifests generate-go-deepcopy generate-boilerplate generate-modules ## Generate Files
@@ -594,5 +565,31 @@ get-kubeconfig-workload-cluster:
594565
./hack/get-kubeconfig-of-workload-cluster.sh
595566

596567
.PHONY: tilt-up
597-
tilt-up: env-vars-for-wl-cluster $(ENVSUBST) $(KUBECTL) $(KUSTOMIZE) $(TILT) cluster ## Start a mgt-cluster & Tilt. Installs the CRDs and deploys the controllers
568+
tilt-up: env-vars-for-wl-cluster get-dependencies $(ENVSUBST) $(TILT) cluster ## Start a mgt-cluster & Tilt. Installs the CRDs and deploys the controllers
598569
$(TILT) up --port=10351
570+
571+
BINARIES = clusterctl controller-gen kind kubectl kustomize trivy
572+
get-dependencies:
573+
ifeq ($(BUILD_IN_CONTAINER),true)
574+
docker run --rm -t -i \
575+
-v $(shell pwd):/src/cluster-stack-provider-openstack \
576+
$(BUILDER_IMAGE):$(BUILDER_IMAGE_VERSION) $@;
577+
else
578+
@if [ "$(HACK_TOOLS_BIN_VERSION)" != "$(BUILDER_IMAGE_VERSION)" ]; then \
579+
echo "Updating binaries"; \
580+
rm -rf hack/tools/bin; \
581+
mkdir -p $(TOOLS_BIN_DIR); \
582+
cp ./.builder-image-version.txt $(TOOLS_BIN_DIR)/version.txt; \
583+
for tool in $(BINARIES); do \
584+
if command -v $$tool > /dev/null; then \
585+
cp `command -v $$tool` $(TOOLS_BIN_DIR); \
586+
echo "copied $$tool to $(TOOLS_BIN_DIR)"; \
587+
else \
588+
echo "$$tool not found"; \
589+
fi; \
590+
done; \
591+
else \
592+
echo "No action required"; \
593+
echo "Binaries are up to date"; \
594+
fi
595+
endif

hack/kind-dev.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ set -o errexit
1818
set -o pipefail
1919
set -x
2020

21-
K8S_VERSION=v1.27.2
21+
K8S_VERSION=v1.27.3
2222

2323
REPO_ROOT=$(git rev-parse --show-toplevel)
2424
cd "${REPO_ROOT}" || exit 1

images/builder/Dockerfile

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 The Kubernetes Authors.
1+
# Copyright 2024 The Kubernetes Authors.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -17,43 +17,47 @@
1717
# If you make changes to this Dockerfile run `make builder-image-push`.
1818

1919
# Install Lychee
20-
FROM docker.io/library/alpine:3.19.1@sha256:6457d53fb065d6f250e1504b9bc42d5b6c65941d57532c072d929dd0628977d0 as lychee
21-
# update: datasource=github-tags depName=lycheeverse/lychee versioning=semver
22-
ENV LYCHEE_VERSION="v0.14.3"
23-
# hadolint ignore=DL3018
24-
RUN apk add --no-cache curl && \
25-
curl -L -o /tmp/lychee-${LYCHEE_VERSION}.tgz https://github.com/lycheeverse/lychee/releases/download/${LYCHEE_VERSION}/lychee-${LYCHEE_VERSION}-x86_64-unknown-linux-gnu.tar.gz && \
26-
tar -xz -C /tmp -f /tmp/lychee-${LYCHEE_VERSION}.tgz && \
27-
mv /tmp/lychee /usr/bin/lychee && \
28-
rm -rf /tmp/linux-amd64 /tmp/lychee-${LYCHEE_VERSION}.tgz
20+
FROM docker.io/lycheeverse/lychee:0.14.3 as lychee
21+
# Install Hadolint
22+
FROM docker.io/hadolint/hadolint:v2.12.0-alpine@sha256:7dba9a9f1a0350f6d021fb2f6f88900998a4fb0aaf8e4330aa8c38544f04db42 as hadolint
2923

30-
# Install Golang CI Lint
31-
FROM docker.io/library/alpine:3.19.1@sha256:6457d53fb065d6f250e1504b9bc42d5b6c65941d57532c072d929dd0628977d0 as golangci
32-
# update: datasource=github-tags depName=golangci/golangci-lint versioning=semver
24+
FROM cgr.dev/chainguard/wolfi-base:latest as wolfi
25+
26+
# update: datasource=github-tags depName=kubernetes-sigs/cluster-api
27+
ARG CLUSTERCTL_VERSION="v1.6.3"
28+
# update: datasource=github-tags depName=golangci/golangci-lint
3329
ENV GOLANGCI_VERSION="v1.56.2"
34-
WORKDIR /
35-
# hadolint ignore=DL3018,DL4006
36-
RUN apk add --no-cache curl && \
37-
curl -L -o /tmp/golangci.tgz https://github.com/golangci/golangci-lint/releases/download/${GOLANGCI_VERSION}/golangci-lint-${GOLANGCI_VERSION#v}-linux-amd64.tar.gz && \
38-
ls -la /tmp && \
39-
tar -xz -C /tmp -f /tmp/golangci.tgz && \
40-
mv /tmp/golangci-lint-${GOLANGCI_VERSION#v}-linux-amd64/golangci-lint /bin/golangci-lint
30+
# update: datasource=github-tags depName=kubernetes-sigs/kind
31+
ARG KIND_VERSION="v0.22.0"
32+
# update: datasource=github-tags depName=kubernetes/kubernetes
33+
ARG KUBECTL_VERSION="v1.27.3"
34+
# update: datasource=github-tags depName=kubernetes-sigs/kustomize extractVersion=^kustomize\/v(?<version>.+)$
35+
ARG KUSTOMIZE_VERSION="v5.3.0"
36+
# update: datasource=github-tags depName=aquasecurity/trivy
37+
ARG TRIVY_VERSION="v0.49.1"
38+
# update: datasource=github-tags depName=kubernetes-sigs/controller-tools
39+
ARG CONTROLLER_GEN_VERSION="v0.14.0"
4140

42-
# Install Hadolint
43-
FROM docker.io/hadolint/hadolint:v2.12.0-alpine@sha256:7dba9a9f1a0350f6d021fb2f6f88900998a4fb0aaf8e4330aa8c38544f04db42 as hadolint
41+
# hadolint ignore=DL3018
42+
RUN apk add -U --no-cache \
43+
curl \
44+
clusterctl=~${CLUSTERCTL_VERSION#v} \
45+
controller-gen=~${CONTROLLER_GEN_VERSION#v} \
46+
kind=~${KIND_VERSION#v} \
47+
kubectl=~${KUBECTL_VERSION#v} \
48+
kustomize=~${KUSTOMIZE_VERSION#v} \
49+
trivy=~${TRIVY_VERSION#v}
4450

45-
# Install Trivy
46-
FROM docker.io/aquasec/trivy:0.49.1@sha256:026a1ab5714dd19ffde0aed18ac034d1d354f119d6e62330cd6522081dd74628 as trivy
51+
WORKDIR /
52+
RUN curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s ${GOLANGCI_VERSION}
4753

4854
############################
49-
# Cspo Build Image Base #
55+
# CSPO Build Image Base #
5056
############################
51-
FROM docker.io/library/golang:1.21.6-bullseye@sha256:a8712f27d9ac742e7bded8f81f7547c5635e855e8b80302e8fc0ce424f559295
57+
FROM docker.io/library/golang:1.21.8-bullseye
5258

5359
# update: datasource=github-tags depName=adrienverge/yamllint versioning=semver
5460
ENV YAMLLINT_VERSION="v1.35.1"
55-
# update: datasource=github-tags depName=opt-nc/yamlfixer versioning=semver
56-
ENV YAMLFIXER_VERSION="0.9.15"
5761

5862
# hadolint ignore=DL3008
5963
RUN apt-get update && \
@@ -64,13 +68,17 @@ RUN apt-get update && \
6468
libsystemd-dev jq && \
6569
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
6670
pip install --no-cache-dir \
67-
yamllint==${YAMLLINT_VERSION} \
68-
yamlfixer-opt-nc==${YAMLFIXER_VERSION}
71+
yamllint==${YAMLLINT_VERSION}
6972

70-
COPY --from=lychee /usr/bin/lychee /usr/bin/lychee
71-
COPY --from=golangci /bin/golangci-lint /usr/local/bin
73+
COPY --from=wolfi /usr/bin/clusterctl /usr/bin/clusterctl
74+
COPY --from=wolfi /usr/bin/controller-gen /usr/bin/controller-gen
75+
COPY --from=wolfi /bin/golangci-lint /usr/bin/golangci-lint
76+
COPY --from=wolfi /usr/bin/kubectl /usr/bin/kubectl
77+
COPY --from=wolfi /usr/bin/kind /usr/bin/kind
78+
COPY --from=wolfi /usr/bin/kustomize /usr/bin/kustomize
79+
COPY --from=wolfi /usr/bin/trivy /usr/bin/trivy
80+
COPY --from=lychee /usr/local/bin/lychee /usr/bin/lychee
7281
COPY --from=hadolint /bin/hadolint /usr/bin/hadolint
73-
COPY --from=trivy /usr/local/bin/trivy /usr/bin/trivy
7482

7583
ENV GOCACHE=/go/cache
7684

images/cspo/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
# Build the manager binary
16-
FROM --platform=${BUILDPLATFORM} docker.io/library/golang:1.21.6-bullseye as build
16+
FROM --platform=${BUILDPLATFORM} docker.io/library/golang:1.21.8-bullseye as build
1717
ARG TARGETOS TARGETARCH
1818

1919
COPY . /src/cluster-stack-provider-openstack

0 commit comments

Comments
 (0)