From df7b5416e68c0a4935de1a3eff5b08bbd27c3ec9 Mon Sep 17 00:00:00 2001 From: Benjamin Elder Date: Thu, 16 Jul 2020 23:28:19 -0700 Subject: [PATCH 1/2] automatically tag docker image based on hugo version and dockerfile version --- Dockerfile | 5 +++++ Makefile | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 3e3335076c..2ff4db8602 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,11 @@ # change is that the Hugo version is now an overridable argument rather than a fixed # environment variable. +# Bump this by 1 whenever you change the Dockerfile below, e.g. if +# `DOCKERFFILE_VERSION=1` then change this to `DOCKERFILE_VERSION=2` when you +# change something else in this file. +# DOCKERFILE_VERSION=0 + FROM alpine:latest LABEL maintainer="Luc Perkins " diff --git a/Makefile b/Makefile index c6a411ddd2..149dc9c57e 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,8 @@ NETLIFY_FUNC = $(NODE_BIN)/netlify-lambda # but this can be overridden when calling make, e.g. # CONTAINER_ENGINE=podman make container-image CONTAINER_ENGINE ?= docker -CONTAINER_IMAGE = kubernetes-hugo +DOCKERFILE_VERSION = $(shell grep DOCKERFILE_VERSION Dockerfile | tail -n 1 | cut -d '=' -f 2 | tr -d " \"\n") +CONTAINER_IMAGE = kubernetes-hugo:v$(HUGO_VERSION)-$(DOCKERFILE_VERSION) CONTAINER_RUN = $(CONTAINER_ENGINE) run --rm --interactive --tty --volume $(CURDIR):/src CCRED=\033[0;31m From 7d62be1781f677a909791be3787f77e8963c96e5 Mon Sep 17 00:00:00 2001 From: Benjamin Elder Date: Sun, 19 Jul 2020 23:53:40 -0700 Subject: [PATCH 2/2] automatically derive image version --- Dockerfile | 5 ----- Makefile | 4 ++-- scripts/hash-files.sh | 10 ++++++++++ 3 files changed, 12 insertions(+), 7 deletions(-) create mode 100755 scripts/hash-files.sh diff --git a/Dockerfile b/Dockerfile index 2ff4db8602..3e3335076c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,11 +4,6 @@ # change is that the Hugo version is now an overridable argument rather than a fixed # environment variable. -# Bump this by 1 whenever you change the Dockerfile below, e.g. if -# `DOCKERFFILE_VERSION=1` then change this to `DOCKERFILE_VERSION=2` when you -# change something else in this file. -# DOCKERFILE_VERSION=0 - FROM alpine:latest LABEL maintainer="Luc Perkins " diff --git a/Makefile b/Makefile index 149dc9c57e..56ec8410f4 100644 --- a/Makefile +++ b/Makefile @@ -6,8 +6,8 @@ NETLIFY_FUNC = $(NODE_BIN)/netlify-lambda # but this can be overridden when calling make, e.g. # CONTAINER_ENGINE=podman make container-image CONTAINER_ENGINE ?= docker -DOCKERFILE_VERSION = $(shell grep DOCKERFILE_VERSION Dockerfile | tail -n 1 | cut -d '=' -f 2 | tr -d " \"\n") -CONTAINER_IMAGE = kubernetes-hugo:v$(HUGO_VERSION)-$(DOCKERFILE_VERSION) +IMAGE_VERSION=$(shell scripts/hash-files.sh Dockerfile Makefile | cut -c 1-12) +CONTAINER_IMAGE = kubernetes-hugo:v$(HUGO_VERSION)-$(IMAGE_VERSION) CONTAINER_RUN = $(CONTAINER_ENGINE) run --rm --interactive --tty --volume $(CURDIR):/src CCRED=\033[0;31m diff --git a/scripts/hash-files.sh b/scripts/hash-files.sh new file mode 100755 index 0000000000..0040f4355b --- /dev/null +++ b/scripts/hash-files.sh @@ -0,0 +1,10 @@ +#!/bin/sh +# this script emits as hash for the files listed in $@ +if command -v shasum >/dev/null 2>&1; then + cat "$@" | shasum -a 256 | cut -d' ' -f1 +elif command -v sha256sum >/dev/null 2>&1; then + cat "$@" | sha256sum | cut -d' ' -f1 +else + echo "missing shasum tool" 1>&2 + exit 1 +fi