Skip to content

Commit 75c0811

Browse files
refactor: publish process and improve multi-arch build (#36)
* refactor multi arch build * build and push releases using docker * package and push helm chart * optimize build * fix white space * fix: typo & add comments --------- Co-authored-by: Maximilian Techritz <maximilian.techritz@sap.com>
1 parent 73f1f7e commit 75c0811

File tree

3 files changed

+49
-23
lines changed

3 files changed

+49
-23
lines changed

.github/workflows/publish.yaml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ jobs:
4242
echo "SKIP=true" >> $GITHUB_ENV
4343
exit 0
4444
45+
- name: Set up Docker
46+
uses: docker/setup-docker-action@v4
47+
with:
48+
daemon-config: |
49+
{
50+
"features": {
51+
"containerd-snapshotter": true
52+
}
53+
}
54+
4555
- name: Set up QEMU
4656
uses: docker/setup-qemu-action@v2
4757

@@ -73,9 +83,13 @@ jobs:
7383
make reviewable
7484
make build-docker-binary
7585
76-
- name: Build Images
86+
- name: Build and push Images
87+
run: |
88+
IMG=ghcr.io/openmcp-project/metrics-operator:${{ env.version }} make docker-buildx docker-push
89+
90+
- name: Package and push helm chart
7791
run: |
78-
IMG=ghcr.io/openmcp-project/metrics-operator:${{ env.version }} make docker-buildx
92+
make helm-package helm-push
7993
8094
- name: setup OCM
8195
uses: open-component-model/ocm-setup-action@main

Makefile

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
6161
ENVTEST ?= $(LOCALBIN)/setup-envtest
6262
GOTESTSUM ?= $(LOCALBIN)/gotestsum
6363
GOLANGCILINT ?= $(LOCALBIN)/golangci-lint
64-
65-
64+
HELM ?= $(LOCALBIN)/helm
6665

6766
## Tool Versions
6867
KUSTOMIZE_VERSION ?= v5.4.1
@@ -144,7 +143,7 @@ build-docker-binary: manifests generate fmt vet ## Build manager binary for Dock
144143
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o bin/manager-linux.amd64 cmd/main.go
145144

146145
.PHONY: docker-build
147-
docker-build: build-docker-binary test ## Build docker image with the manager.
146+
docker-build: test build-docker-binary ## Build docker image with the manager.
148147
$(CONTAINER_TOOL) build -t ${IMG} .
149148

150149
.PHONY: docker-push
@@ -154,22 +153,14 @@ docker-push: ## Push docker image with the manager.
154153
# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
155154
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
156155
# - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
156+
# - be using containerd image store with docker. More Info: https://docs.docker.com/engine/storage/containerd/
157157
# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
158-
# - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
159-
# To properly provided solutions that supports more than one platform you should use this option.
160-
PLATFORMS ?= linux/arm64 linux/amd64
158+
159+
PLATFORMS ?= linux/arm64,linux/amd64
160+
161161
.PHONY: docker-buildx
162-
docker-buildx: ## Build and tag docker image for each platform locally using --load
163-
sed '1 s/^FROM/FROM --platform=$${BUILDPLATFORM}/' Dockerfile > Dockerfile.cross
164-
$(CONTAINER_TOOL) buildx create --name project-v3-builder || true
165-
$(CONTAINER_TOOL) buildx use project-v3-builder
166-
@for platform in $(PLATFORMS); do \
167-
tag="$(IMG)-$$(echo $$platform | tr / -)"; \
168-
echo "Building $$tag for $$platform"; \
169-
$(CONTAINER_TOOL) buildx build --platform=$$platform --tag $$tag --load -f Dockerfile.cross .; \
170-
done
171-
$(CONTAINER_TOOL) buildx rm project-v3-builder
172-
rm Dockerfile.cross
162+
docker-buildx: test
163+
$(CONTAINER_TOOL) buildx build --platform=$(PLATFORMS) --tag $(IMG) --load -f Dockerfile .
173164

174165
#----------------------------------------------------------------------------------------------
175166
##@ Deployment
@@ -269,14 +260,36 @@ dev-apply-metric-dynatrace-prod: ## Apply metric using Dynatrace production exam
269260

270261
#----------------------------------------------------------------------------------------------
271262
##@ Helm
263+
264+
HELM_VERSION ?= v3.18.0
265+
OCI_REGISTRY ?= ghcr.io/openmcp-project/charts
266+
267+
$(HELM): $(LOCALBIN)
268+
@if test -x $(LOCALBIN)/helm && ! $(LOCALBIN)/helm version --short | grep -q $(HELM_VERSION); then \
269+
echo "$(LOCALBIN)/helm version is not expected $(HELM_VERSION). Removing it before installing."; \
270+
rm -rf $(LOCALBIN)/helm; \
271+
fi
272+
test -s $(LOCALBIN)/helm || (curl -sSL https://get.helm.sh/helm-$(HELM_VERSION)-$(shell uname | tr '[:upper:]' '[:lower:]')-amd64.tar.gz | tar xz -C /tmp && \
273+
mv /tmp/$(shell uname | tr '[:upper:]' '[:lower:]')-amd64/helm $(LOCALBIN)/helm && \
274+
chmod +x $(LOCALBIN)/helm && \
275+
rm -rf /tmp/$(shell uname | tr '[:upper:]' '[:lower:]')-amd64)
276+
277+
.PHONY: helm-package
278+
helm-package: $(HELM) helm-chart ## Package the Helm chart.
279+
$(LOCALBIN)/helm package charts/$(PROJECT_FULL_NAME)/ -d ./ --version $(shell cat VERSION)
280+
281+
.PHONY: helm-push
282+
helm-push: $(HELM) ## Push the Helm chart to the OCI registry.
283+
$(LOCALBIN)/helm push $(PROJECT_FULL_NAME)-$(shell cat VERSION).tgz oci://$(OCI_REGISTRY)
284+
272285
.PHONY: helm-chart
273286
helm-chart: ## Generate Helm chart files from templates.
274287
OPERATOR_VERSION=$(shell cat VERSION) envsubst < charts/$(PROJECT_FULL_NAME)/Chart.yaml.tpl > charts/$(PROJECT_FULL_NAME)/Chart.yaml
275288
OPERATOR_VERSION=$(shell cat VERSION) envsubst < charts/$(PROJECT_FULL_NAME)/values.yaml.tpl > charts/$(PROJECT_FULL_NAME)/values.yaml
276289

277290
.PHONY: helm-install-local
278-
helm-install-local: ## Install the Helm chart locally using the Docker image
279-
helm upgrade --install $(PROJECT_FULL_NAME) charts/$(PROJECT_FULL_NAME)/ --set image.repository=$(IMG_BASE) --set image.tag=$(IMG_VERSION) --set image.pullPolicy=Never
291+
helm-install-local: $(HELM) ## Install the Helm chart locally using the Docker image
292+
$(LOCALBIN)/helm upgrade --install $(PROJECT_FULL_NAME) charts/$(PROJECT_FULL_NAME)/ --set image.repository=$(IMG_BASE) --set image.tag=$(IMG_VERSION) --set image.pullPolicy=Never
280293
$(KIND) load docker-image ${IMG} --name=$(PROJECT_FULL_NAME)-dev
281294

282295
#----------------------------------------------------------------------------------------------

component-constructor.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,4 @@ components:
1717
type: dockermulti
1818
repository: images/${COMPONENT_NAME}
1919
variants:
20-
- "${COMPONENT_REPO_PREFIX}:${VERSION}-linux-amd64"
21-
- "${COMPONENT_REPO_PREFIX}:${VERSION}-linux-arm64"
20+
- "${COMPONENT_REPO_PREFIX}:${VERSION}"

0 commit comments

Comments
 (0)