From 2af304b84441ad090ffc20568384e2426dbdb148 Mon Sep 17 00:00:00 2001 From: Shyam Sunder Date: Sat, 28 Sep 2019 16:49:01 -0400 Subject: [PATCH] docker: add hooks to autotag images --- client/hooks/build | 2 +- client/hooks/post_push | 19 +++++++++++++++++++ server/hooks/post_push | 19 +++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100755 client/hooks/post_push create mode 100755 server/hooks/post_push diff --git a/client/hooks/build b/client/hooks/build index 8434e52..86d0c78 100755 --- a/client/hooks/build +++ b/client/hooks/build @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh BUILD_INFO=docker-$(echo $SOURCE_COMMIT | cut -c1-7)-auto echo "Using BUILD_INFO=$BUILD_INFO" docker build --build-arg BUILD_INFO=$BUILD_INFO -f $DOCKERFILE_PATH -t $IMAGE_NAME . diff --git a/client/hooks/post_push b/client/hooks/post_push new file mode 100755 index 0000000..74c19dd --- /dev/null +++ b/client/hooks/post_push @@ -0,0 +1,19 @@ +#!/bin/sh + +add_tag() { + echo "Also tagging image as ${DOCKER_REPO}:${1}" + docker tag $IMAGE_NAME $DOCKER_REPO:$1 + docker push $DOCKER_REPO:$1 +} + +CLOSEST_VER=$(git describe --tags --abbrev=0) +CLOSEST_MAJOR_VER=$(echo ${CLOSEST_VER} | cut -d'.' -f1) +CLOSEST_MINOR_VER=$(echo ${CLOSEST_VER} | cut -d'.' -f2) + +add_tag "${CLOSEST_MAJOR_VER}-edge" +add_tag "${CLOSEST_MAJOR_VER}.${CLOSEST_MINOR_VER}-edge" + +if git describe --exact-match --abbrev=0 2> /dev/null; then + add_tag "${CLOSEST_MAJOR_VER}" + add_tag "${CLOSEST_MAJOR_VER}.${CLOSEST_MINOR_VER}" +fi \ No newline at end of file diff --git a/server/hooks/post_push b/server/hooks/post_push new file mode 100755 index 0000000..74c19dd --- /dev/null +++ b/server/hooks/post_push @@ -0,0 +1,19 @@ +#!/bin/sh + +add_tag() { + echo "Also tagging image as ${DOCKER_REPO}:${1}" + docker tag $IMAGE_NAME $DOCKER_REPO:$1 + docker push $DOCKER_REPO:$1 +} + +CLOSEST_VER=$(git describe --tags --abbrev=0) +CLOSEST_MAJOR_VER=$(echo ${CLOSEST_VER} | cut -d'.' -f1) +CLOSEST_MINOR_VER=$(echo ${CLOSEST_VER} | cut -d'.' -f2) + +add_tag "${CLOSEST_MAJOR_VER}-edge" +add_tag "${CLOSEST_MAJOR_VER}.${CLOSEST_MINOR_VER}-edge" + +if git describe --exact-match --abbrev=0 2> /dev/null; then + add_tag "${CLOSEST_MAJOR_VER}" + add_tag "${CLOSEST_MAJOR_VER}.${CLOSEST_MINOR_VER}" +fi \ No newline at end of file