forked from xingjiudong/docker-smtp-relay
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
59 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,78 @@ | ||
#!/usr/bin/env bash | ||
|
||
## Global settings | ||
# docker hub username | ||
DOCKER_USERNAME="${DOCKERHUB_REGISTRY_USERNAME:-turgon37}" | ||
# image name | ||
DOCKER_IMAGE="${DOCKER_USERNAME}/${DOCKER_IMAGE:-smtp-relay}" | ||
DOCKER_IMAGE="${DOCKER_REPO:-smtp-relay}" | ||
# "production" branch | ||
PRODUCTION_BRANCH=${PRODUCTION_BRANCH:-master} | ||
|
||
## Local settings | ||
alpine_version=`cat Dockerfile | grep --perl-regexp --only-matching '(?<=FROM alpine:)[0-9.]+'` | ||
arch=`uname --machine` | ||
|
||
## Settings initialization | ||
## Initialization | ||
set -e | ||
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` | ||
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` | ||
test -n "$POSTFIX_VERSION" | ||
fi | ||
echo "-> selected Postfix version ${POSTFIX_VERSION}" | ||
|
||
# If empty version, fetch the latest from repository | ||
if [ -z "$RSYSLOG_VERSION" ]; then | ||
RSYSLOG_VERSION=`curl -s "https://pkgs.alpinelinux.org/packages?name=rsyslog&branch=v${alpine_version}&repo=main&arch=${arch}" | grep --perl-regexp --only-matching '(?<=<td class="version">)[a-z0-9.-]+' | uniq` | ||
RSYSLOG_VERSION=`curl -s "https://pkgs.alpinelinux.org/packages?name=rsyslog&branch=v${alpine_version}&repo=main&arch=${arch}" \ | ||
| grep --perl-regexp --only-matching '(?<=<td class="version">)[a-z0-9.-]+' | uniq` | ||
test -n "$RSYSLOG_VERSION" | ||
fi | ||
echo "-> selected Rsyslog version ${RSYSLOG_VERSION}" | ||
|
||
# If empty version, fetch the latest from repository | ||
if [ -n "$SOURCE_COMMIT" ]; then | ||
VCS_REF=$SOURCE_COMMIT | ||
# If empty commit, fetch the current from local git rpo | ||
if [ -n "${SOURCE_COMMIT}" ]; then | ||
VCS_REF="${SOURCE_COMMIT}" | ||
else | ||
VCS_REF=`git rev-parse --short HEAD` | ||
VCS_REF="`git rev-parse --short HEAD`" | ||
fi | ||
test -n "$VCS_REF" | ||
echo "-> current vcs reference ${VCS_REF}" | ||
|
||
# set the docker image version | ||
# If empty branch, fetch the current from local git rpo | ||
if [ -n "${SOURCE_BRANCH}" ]; then | ||
DOCKER_IMAGE_VERSION="${SOURCE_BRANCH}" | ||
VCS_BRANCH="${SOURCE_BRANCH}" | ||
else | ||
DOCKER_IMAGE_VERSION="`git rev-parse --abbrev-ref HEAD`" | ||
VCS_BRANCH="`git rev-parse --abbrev-ref HEAD`" | ||
fi | ||
test -n "$VCS_BRANCH" | ||
echo "-> current vcs branch ${VCS_BRANCH}" | ||
|
||
# set the docker tag prefix if needed | ||
if [ "${VCS_BRANCH}" != "${PRODUCTION_BRANCH}" ]; then | ||
docker_tag_prefix="${VCS_BRANCH}-" | ||
fi | ||
echo "-> use image version ${DOCKER_IMAGE_VERSION}" | ||
echo "-> use tag prefix ${docker_tag_prefix}" | ||
|
||
# Get the current image static version | ||
image_version=`cat VERSION` | ||
echo "-> use image version ${image_version}" | ||
|
||
## Build image | ||
echo "-> building ${DOCKER_IMAGE} with image version: ${image_version}" | ||
docker build --build-arg "POSTFIX_VERSION=${POSTFIX_VERSION}" \ | ||
--build-arg "RSYSLOG_VERSION=${RSYSLOG_VERSION}" \ | ||
--label 'maintainer=Pierre GINDRAUD <pgindraud@gmail.com>' \ | ||
--label "org.label-schema.build-date=`date -u +'%Y-%m-%dT%H:%M:%SZ'`" \ | ||
--label 'org.label-schema.name=smtp-relay' \ | ||
--label 'org.label-schema.description=SMTP server configured as a email relay' \ | ||
--label 'org.label-schema.url=https://github.com/Turgon37/docker-smtp-relay' \ | ||
--label "org.label-schema.vcs-ref=${VCS_REF}" \ | ||
--label 'org.label-schema.vcs-url=https://github.com/Turgon37/docker-smtp-relay' \ | ||
--label 'org.label-schema.vendor=Pierre GINDRAUD' \ | ||
--label "org.label-schema.version=${image_version}" \ | ||
--label 'org.label-schema.schema-version=1.0' \ | ||
--label "application.postfix.version=${POSTFIX_VERSION}" \ | ||
--label "application.rsyslog.version="${RSYSLOG_VERSION}" \ | ||
--tag "${DOCKER_IMAGE}:${CACHE_TAG}" \ | ||
--file Dockerfile \ | ||
. |