From c865c44e0dc172ffcf32af5f3f8f6141a53c5285 Mon Sep 17 00:00:00 2001 From: David Gerchikov Date: Mon, 6 Jan 2025 17:58:23 +0200 Subject: [PATCH] Allow customization of base Docker image locations (#301) --- Dockerfile | 9 ++++++--- Makefile | 7 +++++-- build/docker-build/docker-bake.hcl | 13 +++++++++++++ build/scripts/docker-buildx.sh | 14 ++++++++++++++ 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index b9940547..cce9b980 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,10 @@ # syntax=docker/dockerfile:1.12.0 ARG GO_VERSION=1.23.4 -FROM --platform=$BUILDPLATFORM tonistiigi/xx AS xx -FROM --platform=$BUILDPLATFORM golang:${GO_VERSION} AS builder +ARG REGISTRY="docker.io" +ARG RH_REGISTRY="registry.access.redhat.com" + +FROM --platform=$BUILDPLATFORM ${REGISTRY}/tonistiigi/xx AS xx +FROM --platform=$BUILDPLATFORM ${REGISTRY}/golang:${GO_VERSION} AS builder ARG TARGETOS ARG TARGETARCH @@ -17,7 +20,7 @@ RUN <<-EOF xx-verify /app/aerospike-backup-service/build/target/aerospike-backup-service_${TARGETOS}_${TARGETARCH} EOF -FROM registry.access.redhat.com/ubi9/ubi-minimal:latest +FROM ${RH_REGISTRY}/ubi9/ubi-minimal:latest ARG TARGETOS ARG TARGETARCH COPY --from=builder /app/aerospike-backup-service/build/target/aerospike-backup-service_${TARGETOS}_${TARGETARCH} /usr/bin/aerospike-backup-service diff --git a/Makefile b/Makefile index 9c43af96..d997ff0b 100644 --- a/Makefile +++ b/Makefile @@ -26,12 +26,15 @@ GO ?= $(shell which go || echo "/usr/local/go/bin/go") NFPM ?= $(shell which nfpm) OS ?= $($(GO) env GOOS) ARCH ?= $($(GO) env GOARCH) +REGISTRY ?= "docker.io" +RH_REGISTRY ?= "registry.access.redhat.com" GOBUILD = GOOS=$(OS) GOARCH=$(ARCH) $(GO) build \ -ldflags="-X main.commit=$(GIT_COMMIT) -X main.buildTime=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')" GOTEST = $(GO) test GOCLEAN = $(GO) clean GOBIN_VERSION = $(shell $(GO) version 2>/dev/null) + .PHONY: submodules submodules: git submodule update --init --recursive @@ -82,11 +85,11 @@ checksums: .PHONY: docker-build docker-build: - docker build --tag aerospike/aerospike-backup-service:$(TAG) --file $(WORKSPACE)/Dockerfile . + docker build --tag aerospike/aerospike-backup-service:$(TAG) --build-arg REGISTRY=$(REGISTRY) --build-arg RH_REGISTRY=$(RH_REGISTRY) --file $(WORKSPACE)/Dockerfile . .PHONY: docker-buildx docker-buildx: - cd ./build/scripts && ./docker-buildx.sh --tag $(TAG) + cd ./build/scripts && ./docker-buildx.sh --tag $(TAG) --registry $(REGISTRY) --rh-registry $(RH_REGISTRY) .PHONY: test test: diff --git a/build/docker-build/docker-bake.hcl b/build/docker-build/docker-bake.hcl index e3ba5894..bc609832 100644 --- a/build/docker-build/docker-bake.hcl +++ b/build/docker-build/docker-bake.hcl @@ -40,6 +40,14 @@ variable PLATFORMS { default = "linux/amd64,linux/arm64" } +variable REGISTRY { + default = "docker.io" +} + +variable RH_REGISTRY { + default = "registry.access.redhat.com" +} + function tags { params = [service] result = LATEST == true ? [ @@ -63,6 +71,11 @@ target aerospike-backup-service { "org.opencontainers.image.created" = "${ISO8601}" } + args = { + REGISTRY = "${REGISTRY}" + RH_REGISTRY = "${RH_REGISTRY}" + } + context = "${CONTEXT}" dockerfile = "Dockerfile" platforms = split(",", "${PLATFORMS}") diff --git a/build/scripts/docker-buildx.sh b/build/scripts/docker-buildx.sh index 54689713..73d246c4 100755 --- a/build/scripts/docker-buildx.sh +++ b/build/scripts/docker-buildx.sh @@ -1,6 +1,8 @@ #!/bin/bash -e WORKSPACE="$(git rev-parse --show-toplevel)" CHANNEL="dev" +REGISTRY="docker.io" +RH_REGISTRY="registry.access.redhat.com" TAG_LATEST=false TAG="" PLATFORMS="linux/amd64,linux/arm64" @@ -29,6 +31,16 @@ while [[ $# -gt 0 ]]; do shift shift ;; + --registry) + REGISTRY="$2" + shift + shift + ;; + --rh-registry) + RH_REGISTRY="$2" + shift + shift + ;; -* | --*) echo "Unknown option $1" exit 1 @@ -59,6 +71,8 @@ docker login aerospike.jfrog.io -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD" PLATFORMS="$PLATFORMS" \ TAG="$TAG" \ HUB="$HUB" \ +REGISTRY="$REGISTRY" \ +RH_REGISTRY="$RH_REGISTRY" \ LATEST="$TAG_LATEST" \ GIT_BRANCH="$(git rev-parse --abbrev-ref HEAD)" \ GIT_COMMIT_SHA="$(git rev-parse HEAD)" \