From 93e4cdaa740ee4d69d21a2d54d8e2e3ecc785a13 Mon Sep 17 00:00:00 2001 From: Piotr Biernat Date: Sat, 3 Dec 2022 23:36:59 +0100 Subject: [PATCH] fixes --- Dockerfile.target | 6 ++++-- deploy/image-build.sh | 24 +++++++++++++----------- deploy/image-push.sh | 9 +++++++-- src/go.mod | 3 +-- src/go.sum | 6 ++---- 5 files changed, 27 insertions(+), 21 deletions(-) diff --git a/Dockerfile.target b/Dockerfile.target index 8047221..faa703b 100644 --- a/Dockerfile.target +++ b/Dockerfile.target @@ -1,19 +1,21 @@ # Builder -ARG BUILDER_IMAGE="git.pbiernat.dev/egommerce/identity-builder:latest" +ARG BUILDER_IMAGE FROM ${BUILDER_IMAGE} AS builder # Destination image - server # FROM gcr.io/distroless/base-debian10 FROM alpine:3.17 -ARG BIN_OUTPUT ARG SVC_NAME ARG SVC_VER +ARG BIN_OUTPUT +ARG BUILD_TIME LABEL dev.egommerce.image.author="Piotr Biernat" LABEL dev.egommerce.image.vendor="Egommerce" LABEL dev.egommerce.image.service=${SVC_NAME} LABEL dev.egommerce.image.version=${SVC_VER} +LABEL dev.egommerce.image.build_time=${BUILD_TIME} WORKDIR / COPY --from=builder $BIN_OUTPUT /app diff --git a/deploy/image-build.sh b/deploy/image-build.sh index e6ae076..92a72ae 100755 --- a/deploy/image-build.sh +++ b/deploy/image-build.sh @@ -2,39 +2,41 @@ # RUN IN REPO ROOT DIR !! export IMAGE_PREFIX="git.pbiernat.dev/egommerce/identity" -export BUILDER_IMAGE="$IMAGE_PREFIX-builder:tmp" +export BUILDER_IMAGE="egommerce-builder:identity" +export BUILD_TIME=$(date +"%Y%m%d%H%M%S") export SERVER_IMAGE="$IMAGE_PREFIX-svc" # export WORKER_IMAGE="$IMAGE_PREFIX-worker" +export DOCKER_BUILDKIT=1 TARGET=${1:-latest} [ ! -d \"src/vendor\" ] && sh -c "cd src; go mod vendor" -export DOCKER_BUILDKIT=1 +echo "Building tmp $BUILDER_IMAGE image..." +docker build --rm -t $BUILDER_IMAGE -f Dockerfile.builder . -docker build -t "$BUILDER_IMAGE" -f Dockerfile.builder . && echo "Successfully tagged $BUILDER_IMAGE" - -echo "Building target $IMAGE_PREFIX images..." if [ $TARGET = "latest" ] then # SERVER docker build --build-arg SVC_NAME=identity-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" & + --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" + # docker tag $SERVER_IMAGE:$TARGET $SERVER_IMAGE:$TARGET # WORKER # docker build --build-arg SVC_NAME=identity-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" \ + # --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" else # SERVER docker build --build-arg SVC_NAME=identity-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" & + --build-arg BUILDER_IMAGE=$BUILDER_IMAGE --build-arg BUILD_TIME --rm --no-cache -t $SERVER_IMAGE:$TARGET \ + -f Dockerfile.target . && echo "Successfully tagged $SERVER_IMAGE:$TARGET" + # docker tag $SERVER_IMAGE:$TARGET $SERVER_IMAGE:$TARGET # WORKER # docker build --build-arg SVC_NAME=identity-worker --build-arg SVC_VER="dev" --build-arg BIN_OUTPUT=/go/bin/worker \ - # --rm --build-arg BUILDER_IMAGE --no-cache -t "$WORKER_IMAGE:$TARGET" \ + # --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" fi diff --git a/deploy/image-push.sh b/deploy/image-push.sh index 8dec694..e894638 100755 --- a/deploy/image-push.sh +++ b/deploy/image-push.sh @@ -1,7 +1,12 @@ #!/bin/sh # RUN IN REPO ROOT DIR !! -export IMAGE_NAME="git.pbiernat.dev/egommerce/identity-svc" +export IMAGE_BASE="git.pbiernat.dev/egommerce/identity" +export SERVER_IMAGE="$IMAGE_BASE-svc" +# export WORKER_IMAGE="$IMAGE_BASE-worker" + +TARGET=${1:-latest} echo $DOCKER_PASSWORD | docker login git.pbiernat.dev -u $DOCKER_USERNAME --password-stdin -docker push "$IMAGE_NAME:latest" +docker push "$SERVER_IMAGE:$TARGET" +# docker push "$WORKER_IMAGE:$TARGET" diff --git a/src/go.mod b/src/go.mod index 855f370..258248a 100644 --- a/src/go.mod +++ b/src/go.mod @@ -3,13 +3,12 @@ module git.pbiernat.dev/egommerce/identity-service go 1.18 require ( - git.pbiernat.dev/egommerce/go-api-pkg v0.0.101 + git.pbiernat.dev/egommerce/go-api-pkg v0.0.103 github.com/gofiber/fiber/v2 v2.40.1 github.com/gofiber/jwt/v2 v2.2.7 github.com/golang-jwt/jwt v3.2.2+incompatible github.com/jackc/pgx/v4 v4.17.2 github.com/joho/godotenv v1.4.0 - github.com/streadway/amqp v1.0.0 ) require ( diff --git a/src/go.sum b/src/go.sum index d32c6f9..88f5c3d 100644 --- a/src/go.sum +++ b/src/go.sum @@ -1,5 +1,5 @@ -git.pbiernat.dev/egommerce/go-api-pkg v0.0.101 h1:NZCFAAlC94+LcN1gjrENnWUHvpWgaNksyB2N4Fiy8C4= -git.pbiernat.dev/egommerce/go-api-pkg v0.0.101/go.mod h1:nAwcw2MZtn/54YKq8VQK6RJAsiuoLUtPuazXg8JcqK8= +git.pbiernat.dev/egommerce/go-api-pkg v0.0.103 h1:tVSHVQOBDe1Ofcbodaa/R5gHRD4gYO/d1tw7rVuLJuA= +git.pbiernat.dev/egommerce/go-api-pkg v0.0.103/go.mod h1:nAwcw2MZtn/54YKq8VQK6RJAsiuoLUtPuazXg8JcqK8= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= github.com/andybalholm/brotli v1.0.2/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= @@ -209,8 +209,6 @@ github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXY github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= -github.com/streadway/amqp v1.0.0 h1:kuuDrUJFZL1QYL9hUNuCxNObNzB0bV/ZG5jV3RWAQgo= -github.com/streadway/amqp v1.0.0/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=