Update Docker workflow inputs and tag logic

Refactor Docker workflow to include version and production inputs, and streamline tag determination.
This commit is contained in:
Luke Gustafson
2025-10-20 16:07:55 -05:00
committed by GitHub
parent 4f91984032
commit 1a37888a4e

View File

@@ -3,19 +3,13 @@ name: Build and Push Docker Image
on: on:
workflow_dispatch: workflow_dispatch:
inputs: inputs:
tag_name: version:
description: "Comma-separated list of tags, e.g. latest,release-1.8.0,release-1.8.1" description: "Version to build, e.g. 1.8.0"
required: false
default: ""
registry:
description: "Docker registry to push to"
required: true required: true
default: "both" production:
type: choice description: "Set true for prod build, false for dev build"
options: required: true
- "ghcr" default: false
- "dockerhub"
- "both"
jobs: jobs:
build: build:
@@ -31,71 +25,30 @@ jobs:
- uses: useblacksmith/setup-docker-builder@v1 - uses: useblacksmith/setup-docker-builder@v1
- uses: actions/cache@v4
with:
path: |
~/.npm
node_modules
*/*/node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.ref_name }}-${{ hashFiles('docker/Dockerfile') }}
restore-keys: |
${{ runner.os }}-buildx-${{ github.ref_name }}-
${{ runner.os }}-buildx-
- uses: docker/login-action@v3 - uses: docker/login-action@v3
if: ${{ github.event.inputs.registry == 'ghcr' || github.event.inputs.registry == 'both' }}
with: with:
registry: ghcr.io registry: ghcr.io
username: lukegus username: lukegus
password: ${{ secrets.GHCR_TOKEN }} password: ${{ secrets.GHCR_TOKEN }}
- uses: docker/login-action@v3 - uses: docker/login-action@v3
if: ${{ github.event.inputs.registry == 'dockerhub' || github.event.inputs.registry == 'both' }} if: ${{ github.event.inputs.production == 'true' }}
with: with:
username: bugattiguy527 username: bugattiguy527
password: ${{ secrets.DOCKERHUB_TOKEN }} password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Determine Docker image tags - name: Determine Docker tags
id: vars id: tags
run: | run: |
if [ "${{ github.event.inputs.tag_name }}" != "" ]; then VERSION="${{ github.event.inputs.version }}"
IFS=',' read -ra RAW_TAGS <<< "${{ github.event.inputs.tag_name }}" PRODUCTION="${{ github.event.inputs.production }}"
TAGS=() if [ "$PRODUCTION" == "true" ]; then
for t in "${RAW_TAGS[@]}"; do TAGS="ghcr.io/lukegus/termix:release-$VERSION ghcr.io/lukegus/termix:latest docker.io/bugattiguy527/termix:release-$VERSION docker.io/bugattiguy527/termix:latest"
tt="$(echo "$t" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
if [ -n "$tt" ]; then
TAGS+=("$tt")
fi
done
elif [ "${{ github.ref }}" == "refs/heads/main" ]; then
TAGS=("latest")
elif [ "${{ github.ref }}" == "refs/heads/development" ]; then
TAGS=("development-latest")
else else
TAGS=("${{ github.ref_name }}") TAGS="ghcr.io/lukegus/termix:dev-$VERSION"
fi fi
echo "TAGS=$TAGS" >> $GITHUB_ENV
TAG_ARRAY=() echo "Docker tags: $TAGS"
for tag in "${TAGS[@]}"; do
if [ "${{ github.event.inputs.registry }}" = "ghcr" ]; then
TAG_ARRAY+=("ghcr.io/lukegus/termix:${tag}")
elif [ "${{ github.event.inputs.registry }}" = "dockerhub" ]; then
TAG_ARRAY+=("docker.io/bugattiguy527/termix:${tag}")
else
TAG_ARRAY+=("ghcr.io/lukegus/termix:${tag}")
TAG_ARRAY+=("docker.io/bugattiguy527/termix:${tag}")
fi
done
JSON_TAGS=$(printf '%s\n' "${TAG_ARRAY[@]}" | jq -R -s -c 'split("\n")[:-1]')
echo "tags=$JSON_TAGS" >> $GITHUB_OUTPUT
- uses: useblacksmith/build-push-action@v2 - uses: useblacksmith/build-push-action@v2
with: with:
@@ -103,7 +56,7 @@ jobs:
file: ./docker/Dockerfile file: ./docker/Dockerfile
push: true push: true
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6
tags: ${{ fromJSON(steps.vars.outputs.tags) }} tags: ${{ env.TAGS }}
labels: | labels: |
org.opencontainers.image.source=https://github.com/${{ github.repository }} org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }} org.opencontainers.image.revision=${{ github.sha }}