basket-service/deploy/image-build.sh
Piotr Biernat 34d04efaf8
Some checks failed
continuous-integration/drone/push Build is failing
update
2022-12-02 14:40:39 +01:00

42 lines
1.8 KiB
Bash
Executable File

#!/bin/sh
# RUN IN REPO ROOT DIR !!
export IMAGE_PREFIX="git.pbiernat.dev/egommerce/basket"
export BUILDER_IMAGE="$IMAGE_PREFIX-builder:tmp"
export SERVER_IMAGE="$IMAGE_PREFIX-svc"
export WORKER_IMAGE="$IMAGE_PREFIX-worker"
TARGET=${1:-latest}
[ ! -d \"src/vendor\" ] && sh -c "cd src; go mod vendor"
export DOCKER_BUILDKIT=1
docker build -t "$BUILDER_IMAGE" -f Dockerfile.builder . >/dev/null 2>&1 && echo "Successfully tagged $BUILDER_IMAGE"
echo "Building target $IMAGE_PREFIX images..."
if [ $TARGET = "latest" ]
then
# SERVER
docker build --build-arg SVC_NAME=basket-svc --build-arg SVC_VER="1.0" --build-arg BIN_OUTPUT=/go/bin/server \
--rm --build-arg BUILDER_IMAGE --cache-from "$SERVER_IMAGE:$TARGET" -t "$SERVER_IMAGE:$TARGET" \
-f Dockerfile.target . >/dev/null 2>&1 && echo "Successfully tagged $SERVER_IMAGE:$TARGET" &
# WORKER
docker build --build-arg SVC_NAME=basket-worker --build-arg SVC_VER="1.0" --build-arg BIN_OUTPUT=/go/bin/worker \
--rm --build-arg BUILDER_IMAGE --cache-from "$WORKER_IMAGE:$TARGET" -t "$WORKER_IMAGE:$TARGET" \
-f Dockerfile.target . >/dev/null 2>&1 && echo "Successfully tagged $WORKER_IMAGE:$TARGET"
else
# SERVER
docker build --build-arg SVC_NAME=basket-svc --build-arg SVC_VER="dev" --build-arg BIN_OUTPUT=/go/bin/server \
--rm --build-arg BUILDER_IMAGE --no-cache -t "$SERVER_IMAGE:$TARGET" \
-f Dockerfile.target . >/dev/null 2>&1 && echo "Successfully tagged $SERVER_IMAGE:$TARGET" &
# WORKER
docker build --build-arg SVC_NAME=basket-worker --build-arg SVC_VER="dev" --build-arg BIN_OUTPUT=/go/bin/worker \
--rm --build-arg BUILDER_IMAGE --no-cache -t "$WORKER_IMAGE:$TARGET" \
-f Dockerfile.target . >/dev/null 2>&1 && echo "Successfully tagged $WORKER_IMAGE:$TARGET"
fi
echo "Done."