Skip to content

Docker Image CI - Pre-built base images #32

Docker Image CI - Pre-built base images

Docker Image CI - Pre-built base images #32

name: Docker Image CI - Pre-built base images
on:
workflow_dispatch:
workflow_call:
schedule:
- cron: "0 6 * * *" # everyday at 6 AM
env:
REGISTRY: "ghcr.io"
IMAGE_NAME: "${{ github.repository }}"
jobs:
init:
runs-on: ubuntu-latest
steps:
- name: Show context values
run: |
echo "github.event_name: ${{ github.event_name }}"
echo "github.event_path: ${{ github.event_path }}"
echo "github.ref_name : ${{ github.ref_name }}"
echo "github.ref : ${{ github.ref }}"
build-base-dev:
needs: init
strategy:
matrix:
runner: ["ubuntu-latest", "self-hosted"]
runs-on: ${{ matrix.runner }}
permissions: write-all
steps:
- name: Generate build-args for docker image - amd64
id: gen_docker_build_args_amd64
if: matrix.runner == 'ubuntu-latest'
run: |
echo "APP_ARCH=amd64" >> $GITHUB_OUTPUT
- name: Generate build-args for docker image - arm64
id: gen_docker_build_args_arm64
if: matrix.runner == 'self-hosted'
run: |
echo "APP_ARCH=arm64" >> $GITHUB_OUTPUT
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image - base-dev
id: push_gh_hosted_base_dev
uses: docker/build-push-action@v6
with:
context: .
file: base.Dockerfile
target: base-dev
build-args: |
APP_VERSION=base-dev-${{ steps.gen_docker_build_args_amd64.outputs.APP_ARCH }}${{ steps.gen_docker_build_args_arm64.outputs.APP_ARCH }}
APP_ARCH=${{ steps.gen_docker_build_args_amd64.outputs.APP_ARCH }}${{ steps.gen_docker_build_args_arm64.outputs.APP_ARCH }}
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:base-dev-${{ steps.gen_docker_build_args_amd64.outputs.APP_ARCH }}${{ steps.gen_docker_build_args_arm64.outputs.APP_ARCH }}
provenance: false
build-base-live:
needs: init
strategy:
matrix:
runner: ["ubuntu-latest", "self-hosted"]
runs-on: ${{ matrix.runner }}
permissions: write-all
steps:
- name: Generate build-args for docker image - amd64
id: gen_docker_build_args_amd64
if: matrix.runner == 'ubuntu-latest'
run: |
echo "APP_ARCH=amd64" >> $GITHUB_OUTPUT
- name: Generate build-args for docker image - arm64
id: gen_docker_build_args_arm64
if: matrix.runner == 'self-hosted'
run: |
echo "APP_ARCH=arm64" >> $GITHUB_OUTPUT
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image - base-live
id: push_gh_hosted_base_live
uses: docker/build-push-action@v6
with:
context: .
file: base.Dockerfile
target: base-live
build-args: |
APP_VERSION=base-dev-${{ steps.gen_docker_build_args_amd64.outputs.APP_ARCH }}${{ steps.gen_docker_build_args_arm64.outputs.APP_ARCH }}
APP_ARCH=${{ steps.gen_docker_build_args_amd64.outputs.APP_ARCH }}${{ steps.gen_docker_build_args_arm64.outputs.APP_ARCH }}
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:base-live-${{ steps.gen_docker_build_args_amd64.outputs.APP_ARCH }}${{ steps.gen_docker_build_args_arm64.outputs.APP_ARCH }}
provenance: false
clean-untagged-images:
needs:
- build-base-dev
- build-base-live
permissions: write-all
secrets: inherit
uses:
./.github/workflows/clean-ghcr-packages-untagged.yml