Skip to content

Commit

Permalink
APPS-934 Add support for multi-platform Docker build using Bake
Browse files Browse the repository at this point in the history
  • Loading branch information
edramaspk authored Oct 17, 2023
1 parent e5c5deb commit f1e63b6
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ RUN make shared EVENT_LIB=libuv
RUN ../../scripts/copy_shared.sh

ARG GOOS linux
ARG GOARCH amd64
ARG GOARCH=$BUILDARCH

WORKDIR /app/cmd/backup
RUN go mod download
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ CGO_CFLAGS="-I/app/modules/aerospike-tools-backup/modules/c-client/target/Linux-
It's therefore recommended to always set CGO_ENABLED=0 or CGO_ENABLED=1 when cross-compiling depending on whether you need to use CGO or not.

### Build Docker image
#### AMD64
```
docker build -t backup-service .
docker build --build-arg GOARCH=amd64 -t backup-service .
```

#### ARM64
Expand Down
44 changes: 44 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

BUILDER_NAME="aerospike-builder"
TAG_LATEST=false
TAG=""
PLATFORMS="linux/amd64,linux/arm64"

POSITIONAL_ARGS=()

while [[ $# -gt 0 ]]; do
case $1 in
--tag)
TAG="$2"
shift
shift
;;
--tag-latest)
TAG_LATEST=true
shift
;;
--platforms)
PLATFORMS="$2"
shift
shift
;;
-* | --*)
echo "Unknown option $1"
exit 1
;;
*)
POSITIONAL_ARGS+=("$1") # save positional arg
shift # past argument
;;
esac
done

set -- "${POSITIONAL_ARGS[@]}"

docker buildx create --name "$BUILDER_NAME" --use

docker login aerospike.jfrog.io -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD"
PLATFORMS="$PLATFORMS" TAG="$TAG" LATEST="$TAG_LATEST" docker buildx bake --no-cache --file docker-bake.hcl

docker buildx rm "$BUILDER_NAME"
44 changes: 44 additions & 0 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
group "default" {
targets = [
"backup-service"
]
}

variable LATEST {
default = false
}

variable TAG {
default = ""
}

variable "HUB" {
default = "aerospike.jfrog.io/ecosystem-container-dev-local"
}

variable "PREFIX" {
default = "aerospike"
}

variable SETTINGS {
default = ""
}

variable PLATFORMS {
default = "linux/amd64,linux/arm64"
}

function "tags" {
params = [service]
result = LATEST == true ? [
"${HUB}/${PREFIX}-${service}:${TAG}",
"${HUB}/${PREFIX}-${service}:latest"] : ["${HUB}/${PREFIX}-${service}:${TAG}"]
}

target "backup-service" {
dockerfile = "./Dockerfile"
platforms = split(",", "${PLATFORMS}")
tags = tags("backup-service")

output = ["type=image,push=true"]
}

0 comments on commit f1e63b6

Please sign in to comment.