Skip to content

Commit

Permalink
feat: update github workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
janezicmatej committed Jan 8, 2025
1 parent c3c250e commit 6e108d5
Showing 1 changed file with 29 additions and 34 deletions.
63 changes: 29 additions & 34 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: container-images


on:
workflow_dispatch:
push:
branches: [ "main" ]
tags: [ "v*" ]
Expand All @@ -20,10 +18,32 @@ jobs:
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3

- run: echo "IMAGE_TAG=main" >> $GITHUB_ENV
if: github.ref_name == 'main'
- run: echo "IMAGE_TAG=${GITHUB_REF##*/}" >> $GITHUB_ENV
if: startsWith(github.ref, 'refs/tags/v')
- name: Set ALL_TAGS
env:
REPOSITORY: '${{ github.repository }}'
run: |
# tag main if main branch
if [[ "${{ github.ref_name }}" == "main" ]]; then
image_tags=("main")
# tag with tag name if tag
elif [[ "${{ github.ref }}" == refs/tags/v* ]]; then
image_tags=("${{ github.ref_name }}")
# tag with latest if tag is a new major, minor or patch version
if [[ "${{ github.ref_name}}" =~ ^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]]; then
image_tags+=("latest")
fi
fi
lc_repo=${REPOSITORY,,}
image_paths=()
for tag in ${image_tags[@]}; do
image_paths+=("ghcr.io/$lc_repo:$tag")
done
# join with ',' and then skip first character
ALL_TAGS=$(printf ',%s' "${image_paths[@]}")
echo "ALL_TAGS=${ALL_TAGS:1}" >>$GITHUB_ENV
- name: Login to ghcr.io
uses: docker/login-action@v3
Expand All @@ -32,35 +52,10 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# TODO:(matej) upload images to dockerhub?
# - name: Login to docker.io
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKER_HUB_UID }}
# password: ${{ secrets.DOCKER_HUB_PAT }}

- name: Build and push image for tags
uses: docker/build-push-action@v6
if: startsWith(github.ref, 'refs/tags/v')
with:
context: . # Because GH actions are for kids and put protection on everything; https://stackoverflow.com/a/71159809/11276254
file: Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
ghcr.io/${{ github.repository }}:${{ env.IMAGE_TAG }}
ghcr.io/${{ github.repository }}:latest
# ${{ secrets.DOCKER_HUB_REPO }}:${{ env.IMAGE_TAG }}
# ${{ secrets.DOCKER_HUB_REPO }}:latest
- name: Build and push image for main
uses: docker/build-push-action@v6
if: github.ref_name == 'main'
- name: Build and push default image
uses: docker/build-push-action@v5
with:
context: . # Because GH actions are for kids and put protection on everything; https://stackoverflow.com/a/71159809/11276254
file: Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
ghcr.io/${{ github.repository }}:${{ env.IMAGE_TAG }}
tags: ${{ env.ALL_TAGS }}

0 comments on commit 6e108d5

Please sign in to comment.