From 7ff976428527f54ab45b8bf39b67691bdd62bb69 Mon Sep 17 00:00:00 2001 From: Felix Bartels <1257835+fbartels@users.noreply.github.com> Date: Wed, 23 Oct 2019 11:22:23 +0200 Subject: [PATCH] Provide version information through labels (#1256) * Provide version information through labels Can be retrieved by calling e.g. `docker inspect -f {{.Config.Labels}} tvial/docker-mailserver:testing` Signed-off-by: Felix Bartels * add build hook so that Docker Hub can work with the build args Signed-off-by: Felix Bartels * remove obsolete build-no-cache build args invalidate build cache already Signed-off-by: Felix Bartels * adapt travis file Signed-off-by: Felix Bartels * shellcheck Signed-off-by: Felix Bartels --- .travis.yml | 2 +- Dockerfile | 13 ++++++++++++- Makefile | 14 +++++++------- hooks/build | 8 ++++++++ test/mail_with_ldap.bats | 4 ++-- 5 files changed, 30 insertions(+), 11 deletions(-) create mode 100755 hooks/build diff --git a/.travis.yml b/.travis.yml index 48f41d0c..83e51626 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ before_install: - sudo chmod +rx /usr/local/bin/hadolint install: - make lint -- travis_retry travis_wait make build-no-cache +- travis_retry travis_wait make build script: - make generate-accounts run generate-accounts-after-run fixtures tests after_script: diff --git a/Dockerfile b/Dockerfile index ba10696a..93124365 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,16 @@ FROM debian:stretch-slim -LABEL maintainer="Thomas VIAL" + +ARG VCS_REF +ARG VCS_VERSION + +LABEL maintainer="Thomas VIAL" \ + org.label-schema.name="docker-mailserver" \ + org.label-schema.description="A fullstack but simple mailserver (smtp, imap, antispam, antivirus, ssl...)" \ + org.label-schema.url="https://github.com/tomav/docker-mailserver" \ + org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.vcs-url="https://github.com/tomav/docker-mailserver" \ + org.label-schema.version=$VCS_VERSION \ + org.label-schema.schema-version="1.0" ARG DEBIAN_FRONTEND=noninteractive ENV VIRUSMAILS_DELETE_DELAY=7 diff --git a/Makefile b/Makefile index 749a99eb..6140ce73 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,15 @@ NAME = tvial/docker-mailserver:testing +VCS_REF := $(shell git rev-parse --short HEAD) +VCS_VERSION := $(shell git describe) -all: build-no-cache backup generate-accounts run generate-accounts-after-run fixtures tests clean -all-fast: build backup generate-accounts run generate-accounts-after-run fixtures tests clean +all: build backup generate-accounts run generate-accounts-after-run fixtures tests clean no-build: backup generate-accounts run generate-accounts-after-run fixtures tests clean -build-no-cache: - export DOCKER_MAIL_DOCKER_BUILD_NO_CACHE=--no-cache - docker build --no-cache -t $(NAME) . - build: - docker build -t $(NAME) . + docker build \ + --build-arg VCS_REF=$(VCS_REF) \ + --build-arg VCS_VERSION=$(VCS_VERSION) \ + -t $(NAME) . backup: # if backup directories exist, clean hasn't been called, therefore we shouldn't overwrite it. It still contains the original content. diff --git a/hooks/build b/hooks/build new file mode 100755 index 00000000..4cfbe0f0 --- /dev/null +++ b/hooks/build @@ -0,0 +1,8 @@ +#!/bin/sh +VCS_REF=$(git rev-parse --short HEAD) +VCS_VERSION=$(git describe) + +docker build \ + --build-arg VCS_REF="$VCS_REF" \ + --build-arg VCS_VERSION="$VCS_VERSION" \ + -f "$DOCKERFILE_PATH" -t "$IMAGE_NAME" . diff --git a/test/mail_with_ldap.bats b/test/mail_with_ldap.bats index 2525f11a..b1d5f151 100644 --- a/test/mail_with_ldap.bats +++ b/test/mail_with_ldap.bats @@ -10,7 +10,7 @@ function teardown() { function setup_file() { pushd test/docker-openldap/ - docker build -f Dockerfile -t ldap $DOCKER_MAIL_DOCKER_BUILD_NO_CACHE . + docker build -f Dockerfile -t ldap --no-cache . popd docker run -d --name ldap_for_mail \ @@ -219,4 +219,4 @@ function teardown_file() { @test "last" { # this test is only there to reliably mark the end for the teardown_file -} \ No newline at end of file +}