-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuilder.sh
40 lines (34 loc) · 1.1 KB
/
builder.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
# Usage:
# PUSH=1/<empty> MULTIARCH=1/<empty> REGISTRY=registry.example.com/<empty> builder.sh <directory> <image name> <Dockerfile file> [image tag]
CONTAINER_DIR=$1
IM_NAME=$2
IM_FILE=$3
IM_VARIANT=$4
if [ ! -z ${IM_VARIANT} ]; then
IM_VARIANT=":${IM_VARIANT}"
fi
# optional
IM_REGISTRY=$REGISTRY
if [ ! -z ${IM_REGISTRY} ]; then
IM_REGISTRY_INTAG="${IM_REGISTRY}/"
fi
# Build tag
IM_TAG=${IM_REGISTRY_INTAG}${IM_NAME}${IM_VARIANT}
echo "Building container in '${CONTAINER_DIR}' to ${IM_TAG} (multi-architecture?: ${MULTIARCH})"
if [ ! -z ${MULTIARCH} ]; then
BUILDX_ARGS=""
if [ ! -z ${PUSH} ]; then
BUILDX_ARGS="--push"
else
BUILDX_ARGS="--output type=image"
fi
docker buildx build --platform ${IM_PLATFORMS:-linux/amd64,linux/aarch64} $BUILDX_ARGS --build-arg INTERMEDIATE_REPO=$IM_REGISTRY \
-t ${IM_TAG} -f $CONTAINER_DIR/$IM_FILE $CONTAINER_DIR
else
docker build --build-arg INTERMEDIATE_REPO=$IM_REGISTRY \
-t ${IM_TAG} -f $CONTAINER_DIR/$IM_FILE $CONTAINER_DIR
if [ ! -z ${PUSH} ]; then
docker push ${IM_TAG}
fi
fi