Skip to content

build docker images: scratch #20

build docker images: scratch

build docker images: scratch #20

name: 'build docker images: scratch'
on:
#push:
# branches:
# - 'main'
# - 'master'
# paths:
# - 'scratch.multiarch.release.Dockerfile'
# - '.github/workflows/build_docker_images-scratch.yaml'
workflow_dispatch:
schedule:
- cron: '0 3 */7 * *' # At 03:00 on every 7th day-of-month.
defaults:
run:
shell: bash
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Shell-Script
id: script
run: |
BUILD_DATE="$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
BUILD_DATE_NUMERIC="${BUILD_DATE//[^[:digit:]]/}"
COMMIT_HASH=${GITHUB_SHA::8}
GIT_URL=$(echo "${GITHUB_SERVER_URL}" | awk -F/ '{print $3}' | sed 's/\/*$//')
GIT_URL=$(echo "$GIT_URL" | sed 's/github\.com/ghcr\.io/g') # GIT_URL switch to ghcr.io registry for GitHub
GIT_REPO=${GITHUB_REPOSITORY,,}
GIT_REPO_SHORT=${GIT_REPO#*/}
GIT_REPO_SHORT=${GIT_REPO_SHORT#"docker-"}
DOCKER_REPO=${{ secrets.DOCKER_USERNAME }}/${GIT_REPO_SHORT}
REDHAT_QUAY_REPO=${{ secrets.REDHAT_QUAY_USERNAME }}/${GIT_REPO_SHORT}
echo "ENVs: BUILD_DATE=${BUILD_DATE}, BUILD_DATE_NUMERIC=${BUILD_DATE_NUMERIC}, COMMIT_HASH=${COMMIT_HASH}, GIT_URL=${GIT_URL}, GIT_REPO=${GIT_REPO}"
#echo "ENVs (by Git) for Owner: GITHUB_REPOSITORY_OWNER=${GITHUB_REPOSITORY_OWNER} and github.repository_owner=${{ github.repository_owner }} are the same!"
# MinIO
MINIO_RELEASE_VERSION=$(curl -s https://api.github.com/repos/minio/minio/releases/latest | grep 'tag_name' | cut -d\" -f4)
echo "MINIO_RELEASE_VERSION=${MINIO_RELEASE_VERSION}"
# MinIO
MC_RELEASE_VERSION=$(curl -s https://api.github.com/repos/minio/mc/releases/latest | grep 'tag_name' | cut -d\" -f4)
echo "MC_RELEASE_VERSION=${MC_RELEASE_VERSION}"
# Set output parameters to action.
echo "build_date=${BUILD_DATE}" >> "$GITHUB_OUTPUT"
echo "build_date_numeric=${BUILD_DATE_NUMERIC}" >> "$GITHUB_OUTPUT"
echo "commit_hash=${COMMIT_HASH}" >> "$GITHUB_OUTPUT"
echo "git_url=${GIT_URL}" >> "$GITHUB_OUTPUT"
echo "git_repo=${GIT_REPO}" >> "$GITHUB_OUTPUT"
echo "docker_repo=${DOCKER_REPO}" >> "$GITHUB_OUTPUT"
echo "redhat_quay_repo=${REDHAT_QUAY_REPO}" >> "$GITHUB_OUTPUT"
# MinIO
echo "minio_release_version=${MINIO_RELEASE_VERSION}" >> "$GITHUB_OUTPUT"
echo "mc_release_version=${MC_RELEASE_VERSION}" >> "$GITHUB_OUTPUT"
# TOKEN workarround for Gitea/Forgejo
if [[ $GIT_URL == "github.com" || $GIT_URL == "ghcr.io" ]]; then GIT_REGISTRY_TOKEN="${{ secrets.GITHUB_TOKEN }}"; else GIT_REGISTRY_TOKEN="${{ secrets.GIT_USER_PASSWD }}"; fi
echo "git_registry_token=${GIT_REGISTRY_TOKEN}" >> "$GITHUB_OUTPUT"
# add "GIT_USER_PASSWD" to Settings->Actions->Secrets in Repository,
# because ${{ secrets.GITHUB_TOKEN }}, ${GITHUB_TOKEN}, ${{ github.token }} or ${{ env.GITHUB_TOKEN }} not working :-(
# see: https://github.com/go-gitea/gitea/issues/23642 for ${{ secrets.GITEA_TOKEN}} and other.
#- name: Shell-Script-echo-outputs
# id: script-echo
# run: |
# echo ${{steps.script.outputs.build_date}}
# echo ${{steps.script.outputs.build_date_numeric}}
# echo ${{steps.script.outputs.commit_hash}}
# echo ${{steps.script.outputs.git_url}}
# echo ${{steps.script.outputs.git_repo}}
# echo ${{steps.script.outputs.docker_repo}}
- name: Install Docker
run: |
if ! command -v docker &> /dev/null; then
curl -fsSL https://get.docker.com | sh
else
echo "skip -> Docker is already installed!"
fi
- name: Set up QEMU
id: qemu
uses: docker/setup-qemu-action@v3
with:
image: tonistiigi/binfmt:latest
platforms: all
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
with:
config-inline: |
[registry."${{steps.script.outputs.git_url}}"]
#insecure = true
ca=["/etc/ssl/certs/ca-certificates.crt"]
- name: Login to GIT Container Registry
uses: docker/login-action@v3
with:
registry: ${{ steps.script.outputs.git_url }}
username: ${{ github.repository_owner }}
password: ${{ steps.script.outputs.git_registry_token }} # ${{ secrets.GITHUB_TOKEN }}
- name: Login to DockerHub Container Registry
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Login to RED HAT Quay.io Container Registry
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.REDHAT_QUAY_USERNAME }}
password: ${{ secrets.REDHAT_QUAY_PASSWORD }}
- name: Build
uses: docker/build-push-action@v5
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./scratch.multiarch.release.Dockerfile
platforms: linux/amd64,linux/arm64/v8,linux/arm/v7
push: true
build-args: |
BUILD_DATE=${{steps.script.outputs.build_date}}
VCS_REF=${{steps.script.outputs.commit_hash}}
MINIO_RELEASE_VERSION=${{steps.script.outputs.minio_release_version}}
MC_RELEASE_VERSION=${{steps.script.outputs.mc_release_version}}
tags: |
${{steps.script.outputs.git_url}}/${{steps.script.outputs.git_repo}}:scratch-${{steps.script.outputs.minio_release_version}}
${{steps.script.outputs.git_url}}/${{steps.script.outputs.git_repo}}:scratch
docker.io/${{steps.script.outputs.docker_repo}}:scratch-${{steps.script.outputs.minio_release_version}}
docker.io/${{steps.script.outputs.docker_repo}}:scratch
quay.io/${{steps.script.outputs.redhat_quay_repo}}:scratch-${{steps.script.outputs.minio_release_version}}
quay.io/${{steps.script.outputs.redhat_quay_repo}}:scratch
- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: ${{steps.script.outputs.docker_repo}}
short-description: ${{ github.event.repository.description }}
readme-filepath: README.md