From 3da7adb4d2c4c7acaf6c55e7a5c9319e9544d2fd Mon Sep 17 00:00:00 2001 From: Markus Pesch Date: Fri, 13 Sep 2019 16:46:43 +0200 Subject: [PATCH] fix(Makefile, ci): update readme on hub.docker.io automatically --- .travis.yml | 3 ++- Makefile | 62 ++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 54 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index f9ebbfb..fca3956 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,4 +2,5 @@ services: - docker script: - - make image-push + - make push + - make update/readme diff --git a/Makefile b/Makefile index 75f781b..553a5c3 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,58 @@ -# VERSION -# If no version is specified as a parameter of make, the value latest -# is taken. -VERSION:=$(or ${TRAVIS_TAG}, latest) +# CONTAINER_IMAGE_VERSION +# Defines the version of the container image which has included the executable +# binary. This is somethimes different to the variable CONTAINER_IMAGE_VERSION, because the +# container image version should be latest instead contains the latest git tag +# and hash sum. +CONTAINER_IMAGE_VERSION:=$(or ${TRAVIS_TAG}, latest) + +# CONTAINER_RUNTIME +# The CONTAINER_RUNTIME variable will be used to specified the path to a +# container runtime. This is needed to build the container image. +CONTAINER_RUNTIME:=$(shell which docker) # DOCKER_USER +# It's the username from hub.docker.io. The name in addition with the password +# is necessary to upload the container image. DOCKER_USER:=volkerraschek -image-build: - docker build \ - --tag ${DOCKER_USER}/build-image:${VERSION} \ +# IMAGE_NAME +# The name of the container image. +IMAGE_NAME:=build-image + + +# BUILD CONTAINER IMAGE +# ============================================================================== +PHONY:=build +build: + ${CONTAINER_RUNTIME} build \ + --file Dockerfile \ + --no-cache \ + --tag ${DOCKER_USER}/${IMAGE_NAME}:${CONTAINER_IMAGE_VERSION} \ . -image-push: image-build - docker login --username ${DOCKER_USER} --password ${DOCKER_PASSWORD} - docker push ${DOCKER_USER}/build-image:${VERSION} \ No newline at end of file +# PUSH CONTAINER IMAGE +# ============================================================================== +PHONY+=push +push: build + ${CONTAINER_RUNTIME} login docker.io --username ${DOCKER_USER} --password ${DOCKER_PASSWORD} + ${CONTAINER_RUNTIME} push ${DOCKER_USER}/${IMAGE_NAME}:${CONTAINER_IMAGE_VERSION} + +# UPDATE HUB.DOCKER.IO README +# ============================================================================== +PHONY+=update/readme +update/readme: + ${CONTAINER_RUNTIME} run \ + --rm \ + --env DOCKERHUB_USERNAME=${DOCKER_USER} \ + --env DOCKERHUB_PASSWORD=${DOCKER_PASSWORD} \ + --env DOCKERHUB_REPOSITORY=${DOCKER_USER}/${IMAGE_NAME} \ + --env README_FILEPATH=./README.md \ + --volume $(shell pwd):/workspace:ro \ + --workdir=/workspace \ + peterevans/dockerhub-description:latest + +# PHONY +# ============================================================================== +# Declare the contents of the PHONY variable as phony. We keep that information +# in a variable so we can use it in if_changed. +.PHONY: ${PHONY} \ No newline at end of file