From da18e394479aa542701236715f82f7f44cd93d15 Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Thu, 28 Jan 2021 11:54:21 +0000 Subject: [PATCH 1/8] Fix tag pattern --- .github/workflows/main.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index d3f6c640a..cb80be947 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -7,7 +7,7 @@ on: branches: - "**" tags: - - "v*.*.*" + - "*.*.*" pull_request: env: From 5e31fba2584d37ddc2b65a0f03109fb2e9c780c2 Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Fri, 29 Jan 2021 16:26:29 +0000 Subject: [PATCH 2/8] Add utility function to process multi-valued params --- Makefile | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index ed107f209..e1118d56a 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,13 @@ green := $(shell tput setaf 2) yellow := $(shell tput setaf 3) done := $(shell echo "$(green)DONE$(reset)") +# utility function to prepare multi-valued CLI parameters +# Usage: get_opts +# - PARAM_NAME: e.g., label, tag +# - PARAM_VALUE: bash array of values, e.g., (v1 v2 v3) +define get_opts + $(shell opts=""; values=($(2)); for (( i=0; i<$${#values[@]}; i++)); do opts="$$opts --$(1) '$${values[$$i]}'"; done; echo "$$opts") +endef # default Docker build options build_kit := @@ -27,6 +34,7 @@ ifeq ($(DOCKER_BUILDKIT),1) endif endif +# set cache param ifdef CACHE_FROM cache_from_opt = --cache-from=$(CACHE_FROM) endif @@ -34,25 +42,23 @@ endif # handle extra labels labels_opt := ifdef LABELS - lbs=$(shell echo ${LABELS} | tr ',' '\r') - labels_opt = $(foreach l,$(lbs),--label $(strip $(l))) + labels_opt := $(call get_opts,label,$(LABELS)) endif # handle extra tags tags_opt := ifdef TAGS - tags=$(shell echo ${TAGS} | tr ',' '\r') - tags_opt = $(foreach t,$(tags),--tag $(strip $(t))) + tags_opt := $(call get_opts,tag,$(TAGS)) endif # handle platform option platforms_opt := ifdef PLATFORMS - platforms=$(shell echo ${PLATFORMS} | tr ',' '\r') - platforms_opt = $(foreach p,$(platforms),--platform $(strip $(p))) + platforms_opt := $(call get_opts,platforms,$(PLATFORMS)) endif + all: images images: lifemonitor @@ -80,7 +86,7 @@ certs: fi lifemonitor: docker/lifemonitor.Dockerfile certs - @printf "\n$(bold)Building LifeMonitor Docker image...$(reset)\n" ; \ + printf "\n$(bold)Building LifeMonitor Docker image...$(reset)\n" ; \ $(build_kit) docker $(build_cmd) $(cache_from_opt) $(cache_to_opt) \ ${tags_opt} ${labels_opt} ${platforms_opt} \ -f docker/lifemonitor.Dockerfile -t crs4/lifemonitor . ;\ From bbc7b9c8261ad9d92534762d712aeb542155e50f Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Fri, 29 Jan 2021 16:27:34 +0000 Subject: [PATCH 3/8] Rename Docker metadata step --- .github/workflows/main.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index cb80be947..845b2893a 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -67,7 +67,7 @@ jobs: env: USER_REPO: ${{ secrets.DOCKERHUB_REPO }} # Extract Docker metadata - - name: Set up Docker metadata + - name: Extract Docker metadata id: docker_meta uses: crazy-max/ghaction-docker-meta@v1 with: From f2071a2ab9d36a44f6ed8abd3d36db43f06c048e Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Fri, 29 Jan 2021 16:29:04 +0000 Subject: [PATCH 4/8] Add steps to process Docker labels and tags --- .github/workflows/main.yaml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 845b2893a..24dab5032 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -72,11 +72,21 @@ jobs: uses: crazy-max/ghaction-docker-meta@v1 with: images: ${{ env.DOCKERHUB_REPO }} - # Build Docker image - - name: Build Docker image - run: make lifemonitor + # Set up Docker tags + - name: Set up Docker tags + run: | + IFS=$'\n' # Change IFS to new line + tags=($TAGS) # split to array + echo "DOCKER_TAGS=$(printf "'%s' " "${tags[@]}")" >> $GITHUB_ENV env: TAGS: ${{ steps.docker_meta.outputs.tags }} + # Set up Docker labels + - name: Set up Docker labels + run: | + IFS=$'\n' # Change IFS to new line + labels=($LABELS) # split to array $names + echo "DOCKER_LABELS=$(printf "'%s' " "${labels[@]}")" >> $GITHUB_ENV + env: LABELS: ${{ steps.docker_meta.outputs.labels }} # Setup testing environment - name: Set up testing environment From 364c8291c2f431b7178e57286d2a1e7dfc664d05 Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Fri, 29 Jan 2021 16:32:41 +0000 Subject: [PATCH 5/8] Inject preprocessed labels and tags to the make utility --- .github/workflows/main.yaml | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 24dab5032..f8ebadb1b 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -88,18 +88,15 @@ jobs: echo "DOCKER_LABELS=$(printf "'%s' " "${labels[@]}")" >> $GITHUB_ENV env: LABELS: ${{ steps.docker_meta.outputs.labels }} + # Build Docker image + - name: Build Docker image + run: TAGS=${DOCKER_TAGS} LABELS=${DOCKER_LABELS} make lifemonitor # Setup testing environment - name: Set up testing environment - run: make start-testing - env: - TAGS: ${{ steps.docker_meta.outputs.tags }} - LABELS: ${{ steps.docker_meta.outputs.labels }} + run: TAGS=${DOCKER_TAGS} LABELS=${DOCKER_LABELS} make start-testing # Run tests - name: Run tests - run: make run-tests - env: - TAGS: ${{ steps.docker_meta.outputs.tags }} - LABELS: ${{ steps.docker_meta.outputs.labels }} + run: TAGS=${DOCKER_TAGS} LABELS=${DOCKER_LABELS} make run-tests # Teardown testing environment - name: Teardown testing environment run: make stop-all From c74595b025f8a058e3a7e6159edf65aeb61ee303 Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Fri, 29 Jan 2021 16:35:25 +0000 Subject: [PATCH 6/8] Fix loop for pushing tagged Docker images --- .github/workflows/main.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index f8ebadb1b..120b01777 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -111,6 +111,8 @@ jobs: - name: Push Docker image if: ${{ env.ENABLE_DOCKER_PUSH == 'true' }} run: | - for t in ${{ steps.docker_meta.outputs.tags }}; do - docker push ${t} + for ((i = 0; i < ${#TAGS[@]}; i++)); do + docker push "${TAGS[$i]}" done + env: + TAGS: ${{ steps.docker_meta.outputs.tags }} From b2969fc942fc78543063973b1e7256f5a9f54f2a Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Fri, 29 Jan 2021 16:38:25 +0000 Subject: [PATCH 7/8] Set TERM env variable --- .github/workflows/main.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 120b01777..0b0eea8cf 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -11,6 +11,7 @@ on: pull_request: env: + TERM: xterm # enable Docker push only if the required secrets are defined ENABLE_DOCKER_PUSH: ${{ secrets.DOCKERHUB_USER != null && secrets.DOCKERHUB_TOKEN != null }} From e52243b4ac5d7dae85371262cf55da48510e21f2 Mon Sep 17 00:00:00 2001 From: Marco Enrico Piras Date: Fri, 29 Jan 2021 16:43:32 +0000 Subject: [PATCH 8/8] Revert to von-verbose output --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e1118d56a..d2e3c85e0 100644 --- a/Makefile +++ b/Makefile @@ -86,7 +86,7 @@ certs: fi lifemonitor: docker/lifemonitor.Dockerfile certs - printf "\n$(bold)Building LifeMonitor Docker image...$(reset)\n" ; \ + @printf "\n$(bold)Building LifeMonitor Docker image...$(reset)\n" ; \ $(build_kit) docker $(build_cmd) $(cache_from_opt) $(cache_to_opt) \ ${tags_opt} ${labels_opt} ${platforms_opt} \ -f docker/lifemonitor.Dockerfile -t crs4/lifemonitor . ;\