Skip to content

build-and-push

build-and-push #4

name: build-and-push
on:
workflow_dispatch:
inputs:
tag:
description: "Image tag (optional override)"
required: false
default: ""
jobs:
build:
runs-on: self-hosted # testing self-hosted runner
permissions:
contents: read
packages: write
env:
IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/rsafd-docker
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set lowercase image name
run: |
echo "IMAGE_NAME_LOWERCASE=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')/rsafd-docker" >> $GITHUB_ENV
- name: Compute tags
id: meta
run: |
DATE_TAG=$(date +'%Y%m%d')
SHA_TAG=${GITHUB_SHA::12}
BASE_TAG=latest
USER_TAG="${{ github.event.inputs.tag }}"
TAGS="ghcr.io/${{ env.IMAGE_NAME_LOWERCASE }}:${BASE_TAG},ghcr.io/${{ env.IMAGE_NAME_LOWERCASE }}:${DATE_TAG},ghcr.io/${{ env.IMAGE_NAME_LOWERCASE }}:${SHA_TAG}"
if [ -n "$USER_TAG" ]; then
TAGS+=" ,ghcr.io/${{ env.IMAGE_NAME_LOWERCASE }}:${USER_TAG}"
fi
echo "tags=$TAGS" >> $GITHUB_OUTPUT
- name: Build & Push (multi-arch)
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
provenance: false
sbom: false
build-args: |
GH_OWNER=${{ github.repository_owner }}
- name: Summary
run: |
echo "Pushed: ${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY