name: Build and Push Docker Image on: workflow_dispatch: inputs: tag_name: description: "Comma-separated list of tags, e.g. latest,release-1.8.0,release-1.8.1" required: false default: "" registry: description: "Docker registry to push to" required: true default: "both" type: choice options: - "ghcr" - "dockerhub" - "both" jobs: build: runs-on: blacksmith-4vcpu-ubuntu-2404 steps: - uses: actions/checkout@v5 with: fetch-depth: 1 - uses: docker/setup-qemu-action@v3 with: platforms: arm64,arm/v7,arm/v6 - 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 if: ${{ github.event.inputs.registry == 'ghcr' || github.event.inputs.registry == 'both' }} with: registry: ghcr.io username: lukegus password: ${{ secrets.GHCR_TOKEN }} - uses: docker/login-action@v3 if: ${{ github.event.inputs.registry == 'dockerhub' || github.event.inputs.registry == 'both' }} with: username: bugattiguy527 password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Determine Docker image tags id: vars run: | if [ "${{ github.event.inputs.tag_name }}" != "" ]; then IFS=',' read -ra RAW_TAGS <<< "${{ github.event.inputs.tag_name }}" TAGS=() for t in "${RAW_TAGS[@]}"; do 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 TAGS=("${{ github.ref_name }}") fi TAG_ARRAY=() 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 with: context: . file: ./docker/Dockerfile push: true platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 tags: ${{ fromJSON(steps.vars.outputs.tags) }} labels: | org.opencontainers.image.source=https://github.com/${{ github.repository }} org.opencontainers.image.revision=${{ github.sha }} build-args: | BUILDKIT_INLINE_CACHE=1 BUILDKIT_CONTEXT_KEEP_GIT_DIR=1 outputs: type=registry,compression=zstd,compression-level=19 - run: | docker image prune -af docker system prune -af --volumes if: always()