catalog-service/deploy/image-build.sh

42 lines
1.9 KiB
Bash
Raw Normal View History

2022-11-29 22:40:58 +01:00
#!/bin/sh
# RUN IN REPO ROOT DIR !!
2024-05-31 19:37:41 +02:00
export IMAGE_PREFIX="git.pbiernat.io/egommerce/catalog"
export BUILDER_IMAGE="egommerce-builder:catalog"
export BUILD_TIME=$(date +"%Y%m%d%H%M%S")
2022-11-30 02:08:36 +01:00
export SERVER_IMAGE="$IMAGE_PREFIX-svc"
export WORKER_IMAGE="$IMAGE_PREFIX-worker"
export DOCKER_BUILDKIT=1
2022-11-29 22:40:58 +01:00
TARGET=${1:-latest}
[ ! -d "src/vendor" ] && sh -c "cd src; go mod vendor"
2022-11-30 02:08:36 +01:00
echo "Building target $IMAGE_PREFIX images..."
docker build --rm -t "$BUILDER_IMAGE" -f Dockerfile.builder .
2022-11-30 02:08:36 +01:00
if [ $TARGET = "latest" ]
then
# SERVER
docker build --build-arg SVC_NAME=catalog-svc --build-arg SVC_VER="1.0" --build-arg BIN_OUTPUT=/go/bin/server \
--build-arg BUILDER_IMAGE=$BUILDER_IMAGE --build-arg BUILD_TIME --rm --cache-from "$SERVER_IMAGE:$TARGET" -t "$SERVER_IMAGE:$TARGET" \
-f Dockerfile.target . >/dev/null 2>&1 && echo "Successfully tagged $SERVER_IMAGE:$TARGET"
2022-11-30 02:08:36 +01:00
# WORKER
docker build --build-arg SVC_NAME=catalog-worker --build-arg SVC_VER="1.0" --build-arg BIN_OUTPUT=/go/bin/worker \
--build-arg BUILDER_IMAGE=$BUILDER_IMAGE --build-arg BUILD_TIME --rm --cache-from "$WORKER_IMAGE:$TARGET" -t "$WORKER_IMAGE:$TARGET" \
-f Dockerfile.target . >/dev/null 2>&1 && echo "Successfully tagged $WORKER_IMAGE:$TARGET"
2022-11-30 02:08:36 +01:00
else
# SERVER
docker build --build-arg SVC_NAME=catalog-svc --build-arg SVC_VER="dev" --build-arg BIN_OUTPUT=/go/bin/server \
--build-arg BUILDER_IMAGE=$BUILDER_IMAGE --build-arg BUILD_TIME --rm --no-cache -t "$SERVER_IMAGE:$TARGET" \
-f Dockerfile.target . >/dev/null 2>&1 && echo "Successfully tagged $SERVER_IMAGE:$TARGET"
2022-11-29 22:40:58 +01:00
2022-11-30 02:08:36 +01:00
# WORKER
docker build --build-arg SVC_NAME=catalog-worker --build-arg SVC_VER="dev" --build-arg BIN_OUTPUT=/go/bin/worker \
--build-arg BUILDER_IMAGE=$BUILDER_IMAGE --build-arg BUILD_TIME --rm --no-cache -t "$WORKER_IMAGE:$TARGET" \
-f Dockerfile.target . >/dev/null 2>&1 && echo "Successfully tagged $WORKER_IMAGE:$TARGET"
2022-11-29 22:40:58 +01:00
fi
echo "Done."