Skip to content

Commit

Permalink
create hooks for docker hub
Browse files Browse the repository at this point in the history
  • Loading branch information
Turgon37 committed Nov 3, 2018
1 parent 684372e commit 5b295ec
Showing 1 changed file with 10 additions and 37 deletions.
47 changes: 10 additions & 37 deletions build.sh → hooks/build
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ DOCKER_USERNAME="${DOCKERHUB_REGISTRY_USERNAME:-turgon37}"
# image name
DOCKER_IMAGE="${DOCKER_USERNAME}/${DOCKER_IMAGE:-smtp-relay}"
# "production" branch
MASTER_BRANCH=${MASTER_BRANCH:-master}
PRODUCTION_BRANCH=${PRODUCTION_BRANCH:-master}

## Local settings
build_tags_file="${PWD}/build.sh~tags"
docker_tag_prefix=
alpine_version=`cat Dockerfile | grep --perl-regexp --only-matching '(?<=FROM alpine:)[0-9.]+'`
arch=`uname --machine`

Expand All @@ -21,9 +19,6 @@ set -x
# If empty version, fetch the latest from repository
if [ -z "$POSTFIX_VERSION" ]; then
POSTFIX_VERSION=`curl -s "https://pkgs.alpinelinux.org/packages?name=postfix&branch=v${alpine_version}&repo=main&arch=${arch}" | grep --perl-regexp --only-matching '(?<=<td class="version">)[a-z0-9.-]+' | uniq`
if [ -z "$DOCKER_IMAGE_TAGS" ]; then
DOCKER_IMAGE_TAGS="${DOCKER_IMAGE_TAGS} latest"
fi
fi
echo "-> selected Postfix version ${POSTFIX_VERSION}"

Expand All @@ -34,42 +29,20 @@ fi
echo "-> selected Rsyslog version ${RSYSLOG_VERSION}"

# If empty version, fetch the latest from repository
if [ -z "$VCS_REF" ]; then
if [ -n "$SOURCE_COMMIT" ]; then
VCS_REF=$SOURCE_COMMIT
else
VCS_REF=`git rev-parse --short HEAD`
fi
echo "-> current vcs reference ${VCS_REF}"

# Set the docker image tag prefix
if [ "${VCS_BRANCH}" != "${MASTER_BRANCH}" ]; then
docker_tag_prefix="${VCS_BRANCH}-"
# set the docker image version
if [ -n "${SOURCE_BRANCH}" ]; then
DOCKER_IMAGE_VERSION="${SOURCE_BRANCH}"
else
DOCKER_IMAGE_VERSION="`git rev-parse --abbrev-ref HEAD`"
fi
echo "-> working with tags prefix ${docker_tag_prefix}"

echo "-> working with tags ${DOCKER_IMAGE_TAGS}"
echo "-> use image version ${DOCKER_IMAGE_VERSION}"

image_version=`cat VERSION`
echo "-> building ${DOCKER_IMAGE} with image version: ${image_version}"

## Build image
docker build --build-arg VCS_REF="${VCS_REF}" \
--build-arg IMAGE_VERSION="$image_version" \
--build-arg POSTFIX_VERSION="$POSTFIX_VERSION" \
--build-arg RSYSLOG_VERSION="$RSYSLOG_VERSION" \
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
--tag "${DOCKER_IMAGE}:${docker_tag_prefix}${POSTFIX_VERSION}" \
--file Dockerfile \
.

## Image taaging
echo "${DOCKER_IMAGE}:${docker_tag_prefix}${POSTFIX_VERSION}" > ${build_tags_file}

# Tag images
for tag in $DOCKER_IMAGE_TAGS; do
if [ -n "$tag" ]; then
docker tag "${DOCKER_IMAGE}:${docker_tag_prefix}${POSTFIX_VERSION}" "${DOCKER_IMAGE}:${docker_tag_prefix}${tag}"
echo "${DOCKER_IMAGE}:${docker_tag_prefix}${tag}" >> ${build_tags_file}
fi
done

echo "-> produced following image names"
cat "${build_tags_file}"

0 comments on commit 5b295ec

Please sign in to comment.