2022-11-29 22:40:58 +01:00
|
|
|
#!/bin/sh
|
|
|
|
# RUN IN REPO ROOT DIR !!
|
|
|
|
|
2024-12-05 16:57:56 +01:00
|
|
|
export IMAGE_PREFIX="git.ego.cloudns.be/egommerce/catalog"
|
2022-12-05 23:25:56 +01:00
|
|
|
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"
|
2022-12-05 23:25:56 +01:00
|
|
|
export DOCKER_BUILDKIT=1
|
2022-11-29 22:40:58 +01:00
|
|
|
|
|
|
|
TARGET=${1:-latest}
|
|
|
|
|
2022-12-05 23:25:56 +01:00
|
|
|
[ ! -d "src/vendor" ] && sh -c "cd src; go mod vendor"
|
2022-11-30 02:08:36 +01:00
|
|
|
|
|
|
|
echo "Building target $IMAGE_PREFIX images..."
|
2022-12-05 23:25:56 +01:00
|
|
|
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 \
|
2022-12-05 23:25:56 +01:00
|
|
|
--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 \
|
2022-12-05 23:25:56 +01:00
|
|
|
--build-arg BUILDER_IMAGE=$BUILDER_IMAGE --build-arg BUILD_TIME --rm --cache-from "$WORKER_IMAGE:$TARGET" -t "$WORKER_IMAGE:$TARGET" \
|
2022-12-01 05:08:54 +01:00
|
|
|
-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 \
|
2022-12-05 23:25:56 +01:00
|
|
|
--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 \
|
2022-12-05 23:25:56 +01:00
|
|
|
--build-arg BUILDER_IMAGE=$BUILDER_IMAGE --build-arg BUILD_TIME --rm --no-cache -t "$WORKER_IMAGE:$TARGET" \
|
2022-12-01 05:08:54 +01:00
|
|
|
-f Dockerfile.target . >/dev/null 2>&1 && echo "Successfully tagged $WORKER_IMAGE:$TARGET"
|
2022-11-29 22:40:58 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Done."
|