Skip to content

Commit

Permalink
Update docker build (#3)
Browse files Browse the repository at this point in the history
This copies the docker build script from dockernetes, and changes the name of the docker image from flytetools to just swagger-codegen-cli.
  • Loading branch information
wild-endeavor authored Jul 8, 2019
1 parent 673100c commit 48cdd0e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
5 changes: 3 additions & 2 deletions flytetools/swagger-codegen-cli/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export REPOSITORY=swagger-codegen-cli

.PHONY: docker_build
docker_build:
@docker build -f swagger-codegen-cli/Dockerfile --tag docker.io/lyft/flytetools:swagger-codegen-cli swagger-codegen-cli

IMAGE_NAME=$$REPOSITORY ./docker_build.sh
50 changes: 50 additions & 0 deletions flytetools/swagger-codegen-cli/docker_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
set -e

echo ""
echo "------------------------------------"
echo " DOCKER BUILD"
echo "------------------------------------"
echo ""

GIT_SHA=$(git rev-parse HEAD)
RELEASE_SEMVER=$(git describe --tags --exact-match "$GIT_SHA" 2>/dev/null) || true

if [ -n "$REGISTRY" ]; then
# Do not push if there are unstaged git changes
CHANGED=$(git status --porcelain)
if [ -n "$CHANGED" ]; then
echo "Please commit git changes before pushing to a registry"
exit 1
fi
fi

docker build -t "$IMAGE_NAME:latest" .
echo "$IMAGE_NAME:latest built locally."


if [ -n "$REGISTRY" ]; then

if [ -n "${DOCKER_REGISTRY_PASSWORD}" ]; then
docker login --username="$DOCKER_REGISTRY_USERNAME" --password="$DOCKER_REGISTRY_PASSWORD"
fi

SHA_IMAGE_TAG="${REGISTRY}/${IMAGE_NAME}:${GIT_SHA}"

docker tag "${IMAGE_NAME}:latest" "$SHA_IMAGE_TAG"

docker push "$SHA_IMAGE_TAG"
echo "${SHA_IMAGE_TAG} pushed to remote"

if [ -n "$RELEASE_SEMVER" ]; then

SEMVER_IMAGE_TAG="${REGISTRY}/${IMAGE_NAME}:${RELEASE_SEMVER}"

docker tag "${IMAGE_NAME}:latest" "$SEMVER_IMAGE_TAG"
docker push "$SEMVER_IMAGE_TAG"
echo "${SEMVER_IMAGE_TAG} pushed to remote"
fi

fi

echo ""
echo "success"

0 comments on commit 48cdd0e

Please sign in to comment.