Skip to content

container-images

container-images #7

Workflow file for this run

name: container-images
on:
push:
branches: [ "main" ]
tags: [ "v*" ]
jobs:
build-container-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- 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
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- 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
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ env.ALL_TAGS }}