Skip to content

Commit

Permalink
Add support for arm64 container build
Browse files Browse the repository at this point in the history
Support the container image build on `arm64` architectures.
  • Loading branch information
afritzler committed Feb 20, 2025
1 parent 101feae commit c5f0a01
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/publish-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ jobs:
uses: docker/build-push-action@v6
with:
context: .
#TODO: Fix linux/arm64 build
platforms: linux/amd64 #,linux/arm64
platforms: linux/amd64, linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Expand Down
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ FROM gcr.io/distroless/base-debian11 AS distroless-base
FROM distroless-base AS distroless-amd64
ENV LIB_DIR_PREFIX=x86_64
ENV LIB_DIR_PREFIX_MINUS=x86-64
ENV LIB_DIR_SUFFIX_NUMBER=2
ENV LIB_DIR=lib64

# The distroless arm64 image has a target triplet of aarch64
FROM distroless-base AS distroless-arm64
ENV LIB_DIR_PREFIX=aarch64
ENV LIB_DIR_PREFIX_MINUS=aarch64

ENV LIB_DIR_SUFFIX_NUMBER=1
ENV LIB_DIR=lib

FROM busybox:1.37.0-uclibc AS busybox
FROM distroless-$TARGETARCH AS libvirt-provider
Expand Down Expand Up @@ -84,8 +87,8 @@ COPY --from=builder /lib/${LIB_DIR_PREFIX}-linux-gnu/librados.so.2 \
/lib/${LIB_DIR_PREFIX}-linux-gnu/libselinux.so.1 \
/lib/${LIB_DIR_PREFIX}-linux-gnu/libpthread.so.0 \
/lib/${LIB_DIR_PREFIX}-linux-gnu/libpcre2-8.so.0 /lib/${LIB_DIR_PREFIX}-linux-gnu/
RUN mkdir -p /lib64
COPY --from=builder /lib64/ld-linux-${LIB_DIR_PREFIX_MINUS}.so.2 /lib64/
RUN mkdir -p /${LIB_DIR}
COPY --from=builder /${LIB_DIR}/ld-linux-${LIB_DIR_PREFIX_MINUS}.so.${LIB_DIR_SUFFIX_NUMBER} /${LIB_DIR}/
RUN mkdir -p /usr/lib/${LIB_DIR_PREFIX}-linux-gnu/ceph/
COPY --from=builder /usr/lib/${LIB_DIR_PREFIX}-linux-gnu/ceph/libceph-common.so.2 /usr/lib/${LIB_DIR_PREFIX}-linux-gnu/ceph
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
Expand Down
24 changes: 5 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,9 @@ ENVTEST_K8S_VERSION = 1.28
# Docker image name for the mkdocs based local development setup
MKDOCS_IMG=onmetal/libvirt-provider-docs

# Code depend on OS
TARGET_OS ?= linux
TARGET_ARCH ?= amd64
CGO_ENABLED ?= 1

LIBVIRT_PROVIDER_BIN=$(LOCALBIN)/libvirt-provider
LIBVIRT_PROVIDER_BIN_SOURCE=./cmd/libvirt-provider

GITHUB_PAT_PATH ?=
ifeq (,$(GITHUB_PAT_PATH))
GITHUB_PAT_MOUNT ?=
else
GITHUB_PAT_MOUNT ?= --secret id=github_pat,src=$(GITHUB_PAT_PATH)
endif

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
Expand All @@ -35,8 +23,6 @@ endif
# tools. (i.e. podman)
CONTAINER_TOOL ?= docker

CONTAINER_BUILDARGS ?= --platform $(TARGET_OS)/$(TARGET_ARCH)

# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
Expand Down Expand Up @@ -86,15 +72,15 @@ fmt: ## Run go fmt against code.

.PHONY: vet
vet: ## Run go vet against code.
GOOS=$(TARGET_OS) CGO_ENABLED=$(CGO_ENABLED) go vet ./...
go vet ./...

.PHONY: lint
lint: golangci-lint ## Run golangci-lint against code.
GOOS=$(TARGET_OS) CGO_ENABLED=$(CGO_ENABLED) $(GOLANGCI_LINT) run
CGO_ENABLED=1 $(GOLANGCI_LINT) run

.PHONY: lint-fix
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
GOOS=$(TARGET_OS) CGO_ENABLED=$(CGO_ENABLED) $(GOLANGCI_LINT) run --fix
CGO_ENABLED=1 $(GOLANGCI_LINT) run --fix

.PHONY: check
check: manifests generate fmt check-license lint test ## Generate manifests, code, lint, check licenses, test
Expand Down Expand Up @@ -122,7 +108,7 @@ clean-docs: ## Remove all local mkdocs Docker images (cleanup).

.PHONY: build
build: manifests generate fmt vet add-license lint ## Build the binary
GOOS=$(TARGET_OS) GOARCH=$(TARGET_ARCH) CGO_ENABLED=$(CGO_ENABLED) go build -o $(LIBVIRT_PROVIDER_BIN) $(LIBVIRT_PROVIDER_BIN_SOURCE)
CGO_ENABLED=1 go build -o $(LIBVIRT_PROVIDER_BIN) $(LIBVIRT_PROVIDER_BIN_SOURCE)

.PHONY: run
run: manifests generate fmt vet ## Run the binary
Expand All @@ -133,7 +119,7 @@ run: manifests generate fmt vet ## Run the binary

.PHONY: docker-build
docker-build: ## Build docker image with partitionlet
$(CONTAINER_TOOL) build $(CONTAINER_BUILDARGS) -t ${IMG} $(GITHUB_PAT_MOUNT) .
$(CONTAINER_TOOL) build -t ${IMG} .

.PHONY: docker-push
docker-push: ## Push docker image with the manager.
Expand Down

0 comments on commit c5f0a01

Please sign in to comment.