Skip to content

Commit

Permalink
Merge pull request #57 from kikkomep/fix/docker-tags-labels
Browse files Browse the repository at this point in the history
CI update: fix Docker tags and labels
  • Loading branch information
kikkomep authored Feb 1, 2021
2 parents a15e046 + e52243b commit 35456c4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 21 deletions.
40 changes: 25 additions & 15 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down Expand Up @@ -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
Expand 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 }}
18 changes: 12 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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> <PARAM_VALUE>
# - 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 :=
Expand All @@ -27,32 +34,31 @@ ifeq ($(DOCKER_BUILDKIT),1)
endif
endif

# set cache param
ifdef CACHE_FROM
cache_from_opt = --cache-from=$(CACHE_FROM)
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
Expand Down

0 comments on commit 35456c4

Please sign in to comment.