Skip to content

Commit

Permalink
Allow customization of base Docker image locations (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
davi17g authored Jan 6, 2025
1 parent 1215614 commit c865c44
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
13 changes: 13 additions & 0 deletions build/docker-build/docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? [
Expand All @@ -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}")
Expand Down
14 changes: 14 additions & 0 deletions build/scripts/docker-buildx.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)" \
Expand Down

0 comments on commit c865c44

Please sign in to comment.