From c3d0941d9c642303e30e986f8a2876c06f31fc55 Mon Sep 17 00:00:00 2001 From: gadotroee <55343099+gadotroee@users.noreply.github.com> Date: Sun, 9 May 2021 12:05:05 +0300 Subject: [PATCH] Build push image to the right place and adjust makefile to use script (#35) * build push docker image * Update build-push-featurebranch.sh --- Makefile | 5 +---- build-push-featurebranch.sh | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) create mode 100755 build-push-featurebranch.sh diff --git a/Makefile b/Makefile index 9a6dce569..71d9533bf 100644 --- a/Makefile +++ b/Makefile @@ -17,8 +17,6 @@ help: ## This help. # Variables and lists TS_SUFFIX="$(shell date '+%s')" -DOCKER_IMG="up9inc/mizu" -DOCKER_TAG="latest" ui: ## build UI @(cd ui; npm i ; npm run build; ) @@ -38,8 +36,7 @@ tap: ## build tap binary docker: ## build Docker image @(echo "building docker image" ) - docker build -t ${DOCKER_IMG}:${DOCKER_TAG} . - docker images ${DOCKER_IMG} + ./build-push-featurebranch.sh publish: ## build and publish Mizu docker image & CLI @echo "publishing Docker image .. " diff --git a/build-push-featurebranch.sh b/build-push-featurebranch.sh new file mode 100755 index 000000000..01089010e --- /dev/null +++ b/build-push-featurebranch.sh @@ -0,0 +1,20 @@ +#!/bin/bash +set -e + +SERVER_NAME=mizu +GCP_PROJECT=up9-docker-hub +REPOSITORY=gcr.io/$GCP_PROJECT +GIT_BRANCH=$(git branch | grep \* | cut -d ' ' -f2 | tr '[:upper:]' '[:lower:]') +DOCKER_TAGGED_BUILD=$REPOSITORY/$SERVER_NAME/$GIT_BRANCH:latest + +if [ "$GIT_BRANCH" = 'develop' -o "$GIT_BRANCH" = 'master' -o "$GIT_BRANCH" = 'main' ] +then + echo "Pushing to $GIT_BRANCH is allowed only via CI" + exit 1 +fi + +echo "building $DOCKER_TAGGED_BUILD" +docker build -t "$DOCKER_TAGGED_BUILD" . + +echo pushing to "$REPOSITORY" +docker push "$DOCKER_TAGGED_BUILD"