Skip to content

Commit

Permalink
Merge pull request #16 from docksal/develop
Browse files Browse the repository at this point in the history
Release 1.2.1
  • Loading branch information
lmakarov authored Mar 13, 2021
2 parents 7fa1c9a + ccb5fb3 commit 99c3644
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 33 deletions.
51 changes: 29 additions & 22 deletions .github/scripts/docker-tags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,50 @@

# Generates docker images tags for the docker/build-push-action@v2 action depending on the branch/tag.

declare -a IMAGE_TAGS
declare -a registryArr
registryArr+=("docker.io") # Docker Hub
registryArr+=("ghcr.io") # GitHub Container Registry

declare -a imageTagArr

# feature/* => sha-xxxxxxx
# Note: disabled
#if [[ "${GITHUB_REF}" =~ "refs/heads/feature/" ]]; then
# GIT_SHA7=$(echo ${GITHUB_SHA} | cut -c1-7) # Short SHA (7 characters)
# IMAGE_TAGS+=("${IMAGE}:sha-${GIT_SHA7}-${VERSION}")
# IMAGE_TAGS+=("ghcr.io/${IMAGE}:sha-${GIT_SHA7}-${VERSION}")
# imageTagArr+=("${IMAGE}:sha-${GIT_SHA7}-${VERSION}")
# imageTagArr+=("ghcr.io/${IMAGE}:sha-${GIT_SHA7}-${VERSION}")
#fi

# develop => edge
# develop => version-edge
if [[ "${GITHUB_REF}" == "refs/heads/develop" ]]; then
IMAGE_TAGS+=("${IMAGE}:edge-${VERSION}")
IMAGE_TAGS+=("ghcr.io/${IMAGE}:edge-${VERSION}")
imageTagArr+=("${IMAGE}:${VERSION}-edge")
fi

# master => stable
# master => version
if [[ "${GITHUB_REF}" == "refs/heads/master" ]]; then
IMAGE_TAGS+=("${IMAGE}:stable-${VERSION}")
IMAGE_TAGS+=("ghcr.io/${IMAGE}:stable-${VERSION}")
imageTagArr+=("${IMAGE}:${VERSION}")
fi

# tags/v1.0.0 => 1.0
if [[ "${GITHUB_REF}" =~ "refs/tags/" ]]; then
# Extract version parts from release tag
IFS='.' read -a ver_arr <<< "${GITHUB_REF#refs/tags/}"
VERSION_MAJOR=${ver_arr[0]#v*} # 2.7.0 => "2"
VERSION_MINOR=${ver_arr[1]} # "2.7.0" => "7"
IMAGE_TAGS+=("${IMAGE}:stable-${VERSION}")
IMAGE_TAGS+=("${IMAGE}:${VERSION_MAJOR}-${VERSION}")
IMAGE_TAGS+=("${IMAGE}:${VERSION_MAJOR}.${VERSION_MINOR}-${VERSION}")
IMAGE_TAGS+=("ghcr.io/${IMAGE}:stable-${VERSION}")
IMAGE_TAGS+=("ghcr.io/${IMAGE}:${VERSION_MAJOR}-${VERSION}")
IMAGE_TAGS+=("ghcr.io/${IMAGE}:${VERSION_MAJOR}.${VERSION_MINOR}-${VERSION}")
IFS='.' read -a release_arr <<< "${GITHUB_REF#refs/tags/}"
releaseMajor=${release_arr[0]#v*} # 2.7.0 => "2"
releaseMinor=${release_arr[1]} # "2.7.0" => "7"
imageTagArr+=("${IMAGE}:${VERSION}")
imageTagArr+=("${IMAGE}:${VERSION}-${releaseMajor}")
imageTagArr+=("${IMAGE}:${VERSION}-${releaseMajor}.${releaseMinor}")
fi

# Output a comma concatenated list of image tags
IMAGE_TAGS_STR=$(IFS=,; echo "${IMAGE_TAGS[*]}")
echo "${IMAGE_TAGS_STR}"
echo "::set-output name=tags::${IMAGE_TAGS_STR}"
# Build an array of registry/image:tag values
declare -a repoImageTagArr
for registry in ${registryArr[@]}; do
for imageTag in ${imageTagArr[@]}; do
repoImageTagArr+=("${registry}/${imageTag}")
done
done

# Print with new lines for output in build logs
(IFS=$'\n'; echo "${repoImageTagArr[*]}")
# Using newlines in outputs variables does not seem to work, so we'll use comas
(IFS=$','; echo "::set-output name=tags::${repoImageTagArr[*]}")
43 changes: 32 additions & 11 deletions .github/workflows/docker-build-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,40 @@ jobs:
id: docker_tags
run: make tags
-
# Build for local use + registry cache (ghcr.io)
name: Build and cache image (local)
id: docker_build_local
# Build for local use
name: Build image (amd64)
id: docker_build_amd64
uses: docker/build-push-action@v2
env:
IMAGE_CACHE: ghcr.io/${{ env.IMAGE }}:build-${{ env.VERSION }}
with:
context: .
file: ./Dockerfile
build-args: |
UPSTREAM_IMAGE=${{ env.UPSTREAM_IMAGE }}
VERSION=${{ env.VERSION }}
#platforms: linux/amd64,linux/arm64 # Note: cannot use multi-platform with local image caching ("load: true")
platforms: linux/amd64 # Note: cannot use multi-platform with local image caching ("load: true")
tags: ${{ env.IMAGE }}:build-${{ env.VERSION }}
load: true # cache image locally for use by other steps
cache-from: type=registry,ref=ghcr.io/${{ env.DOCKER_IMAGE }}:build-${{ matrix.version }}
cache-from: type=registry,ref=${{ env.IMAGE_CACHE }}
cache-to: type=inline # Write the cache metadata into the image configuration
-
# Build for local use
name: Build image (arm64)
id: docker_build_arm64
uses: docker/build-push-action@v2
env:
IMAGE_CACHE: ghcr.io/${{ env.IMAGE }}:build-${{ env.VERSION }}
with:
context: .
file: ./Dockerfile
build-args: |
UPSTREAM_IMAGE=${{ env.UPSTREAM_IMAGE }}
VERSION=${{ env.VERSION }}
platforms: linux/arm64 # Note: cannot use multi-platform with local image caching ("load: true")
tags: ${{ env.IMAGE }}:build-${{ env.VERSION }}
load: true # cache image locally for use by other steps
cache-from: type=registry,ref=${{ env.IMAGE_CACHE }}
cache-to: type=inline # Write the cache metadata into the image configuration
-
# Print image info
Expand All @@ -117,18 +137,19 @@ jobs:
docker image inspect "${{ env.IMAGE }}:build-${{ env.VERSION }}"
-
# Cache image layers in the registry
# This will pick-up the build cache from the local build step
name: Build and push image cache (ghcr.io)
id: docker_build_cache
name: Push image cache (ghcr.io)
id: docker_push_cache
uses: docker/build-push-action@v2
env:
IMAGE_CACHE: ghcr.io/${{ env.IMAGE }}:build-${{ env.VERSION }}
with:
context: .
file: ./Dockerfile
build-args: |
UPSTREAM_IMAGE=${{ env.UPSTREAM_IMAGE }}
VERSION=${{ env.VERSION }}
platforms: linux/amd64,linux/arm64
tags: ghcr.io/${{ env.IMAGE }}:build-${{ env.VERSION }} # Build cache tag in ghcr.io
tags: ${{ env.IMAGE_CACHE }} # Build cache tag in ghcr.io
push: ${{ github.event_name != 'pull_request' }} # Don't push for PRs
cache-to: type=inline # Write the cache metadata into the image configuration
-
Expand All @@ -138,8 +159,8 @@ jobs:
-
# Push final image to the registry
# This will pick-up the build cache from the local build step
name: Build and push image
id: docker_build_push
name: Push image
id: docker_push_image
# Don't run if the list of tags is empty
# Note: using tags from docker_tags (custom)
if: ${{ steps.docker_tags.outputs.tags != '' }}
Expand Down

0 comments on commit 99c3644

Please sign in to comment.