diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index d3f6c640a..0b0eea8cf 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -7,10 +7,11 @@ on: branches: - "**" tags: - - "v*.*.*" + - "*.*.*" 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 }} @@ -67,29 +68,36 @@ 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: 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 }} + # 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 @@ -104,6 +112,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 }} diff --git a/Makefile b/Makefile index ed107f209..d2e3c85e0 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