Skip to content

Commit

Permalink
CI: introduce container online builds
Browse files Browse the repository at this point in the history
  • Loading branch information
KFERMercer committed Jan 19, 2025
1 parent f37ce84 commit dfced3f
Showing 1 changed file with 195 additions and 0 deletions.
195 changes: 195 additions & 0 deletions .github/workflows/Build-Push-Containers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
name: Build Push Containers

on:
push:
branches:
- master
tags:
- '*'
schedule:
- cron: '0 0 * * MON' # Every Monday at 00:00 (UTC) .

env:
IMAGE_NAME: ctbcap

jobs:
build:
strategy:
matrix:
include: [
{ platform: 'linux/386', archname: 'x86', buildtype: 'minimal' },
{ platform: 'linux/amd64', archname: 'x86_64', buildtype: 'minimal' },
{ platform: 'linux/arm/v6', archname: 'armhf', buildtype: 'minimal' },
{ platform: 'linux/arm/v7', archname: 'armv7', buildtype: 'minimal' },
{ platform: 'linux/arm64/v8', archname: 'aarch64', buildtype: 'minimal' },
{ platform: 'linux/loong64', archname: 'loongarch64', buildtype: 'minimal' },
{ platform: 'linux/ppc64le', archname: 'ppc64le', buildtype: 'minimal' },
{ platform: 'linux/riscv64', archname: 'riscv64', buildtype: 'minimal' },
{ platform: 'linux/s390x', archname: 's390x', buildtype: 'fat' } # Free Actions Runner are not enough to run minimal build for s390x.
]

name: Build Container for ${{ matrix.platform }}
runs-on: ubuntu-latest

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
with:
driver: docker-container

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: kfermercer
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}

- name: Special Setup for Loongarch64
if: ${{ matrix.platform == 'linux/loong64' }}
run: |
docker run -t --rm --privileged ${{ secrets.LOONGARCH64_QEMU }} --reset -p yes
sed -i 's|FROM alpine:latest|FROM lcr.loongnix.cn/library/alpine:latest|g' ./Dockerfile
echo
echo "8================== Dockerfile ==================D"
echo
cat ./Dockerfile
- name: Minimal build for ${{ matrix.archname }}
if: ${{ matrix.buildtype == 'minimal' }}
uses: docker/build-push-action@v6
with:
context: .
platforms: ${{ matrix.platform }}
provenance: false
push: true
tags: |
kfermercer/${{ env.IMAGE_NAME }}:latest-${{ matrix.archname }}
ghcr.io/kfermercer/${{ env.IMAGE_NAME }}:latest-${{ matrix.archname }}
target: minimal

- name: Fat build for ${{ matrix.archname }}
if: ${{ matrix.buildtype == 'fat' }}
uses: docker/build-push-action@v6
with:
build-args: BUILD_TARGET=fat
context: .
platforms: ${{ matrix.platform }}
provenance: false
push: true
tags: |
kfermercer/${{ env.IMAGE_NAME }}:latest-${{ matrix.archname }}
ghcr.io/kfermercer/${{ env.IMAGE_NAME }}:latest-${{ matrix.archname }}
target: fat

push:
name: Pushing merged manifest
runs-on: ubuntu-latest
needs: build

steps:
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: kfermercer
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}

- name: Create and push latest manifest image to Docker Hub
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
uses: Noelware/docker-manifest-action@master
with:
inputs: |
kfermercer/${{ env.IMAGE_NAME }}:latest,
kfermercer/${{ env.IMAGE_NAME }}:snapshot
images: |
kfermercer/${{ env.IMAGE_NAME }}:latest-x86,
kfermercer/${{ env.IMAGE_NAME }}:latest-x86_64,
kfermercer/${{ env.IMAGE_NAME }}:latest-armhf,
kfermercer/${{ env.IMAGE_NAME }}:latest-armv7,
kfermercer/${{ env.IMAGE_NAME }}:latest-aarch64,
kfermercer/${{ env.IMAGE_NAME }}:latest-loongarch64,
kfermercer/${{ env.IMAGE_NAME }}:latest-ppc64le,
kfermercer/${{ env.IMAGE_NAME }}:latest-riscv64,
kfermercer/${{ env.IMAGE_NAME }}:latest-s390x
push: true

- name: Create and push latest manifest image to GHCR
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
uses: Noelware/docker-manifest-action@master
with:
inputs: |
ghcr.io/kfermercer/${{ env.IMAGE_NAME }}:latest,
ghcr.io/kfermercer/${{ env.IMAGE_NAME }}:snapshot
images: |
ghcr.io/kfermercer/${{ env.IMAGE_NAME }}:latest-x86,
ghcr.io/kfermercer/${{ env.IMAGE_NAME }}:latest-x86_64,
ghcr.io/kfermercer/${{ env.IMAGE_NAME }}:latest-armhf,
ghcr.io/kfermercer/${{ env.IMAGE_NAME }}:latest-armv7,
ghcr.io/kfermercer/${{ env.IMAGE_NAME }}:latest-aarch64,
ghcr.io/kfermercer/${{ env.IMAGE_NAME }}:latest-loongarch64,
ghcr.io/kfermercer/${{ env.IMAGE_NAME }}:latest-ppc64le,
ghcr.io/kfermercer/${{ env.IMAGE_NAME }}:latest-riscv64,
ghcr.io/kfermercer/${{ env.IMAGE_NAME }}:latest-s390x
push: true

- name: Store release version to env
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: echo "RELEASE_VERSION=${GITHUB_REF:10}" >> $GITHUB_ENV

- name: Create and push release manifest to Docker Hub
if: ${{ startsWith(github.ref, 'refs/tags/') }}
uses: Noelware/docker-manifest-action@master
with:
inputs: |
kfermercer/${{ env.IMAGE_NAME }}:latest,
kfermercer/${{ env.IMAGE_NAME }}:latest-release,
kfermercer/${{ env.IMAGE_NAME }}:${{ env.RELEASE_VERSION }}
images: |
kfermercer/${{ env.IMAGE_NAME }}:latest-x86,
kfermercer/${{ env.IMAGE_NAME }}:latest-x86_64,
kfermercer/${{ env.IMAGE_NAME }}:latest-armhf,
kfermercer/${{ env.IMAGE_NAME }}:latest-armv7,
kfermercer/${{ env.IMAGE_NAME }}:latest-aarch64,
kfermercer/${{ env.IMAGE_NAME }}:latest-loongarch64,
kfermercer/${{ env.IMAGE_NAME }}:latest-ppc64le,
kfermercer/${{ env.IMAGE_NAME }}:latest-riscv64,
kfermercer/${{ env.IMAGE_NAME }}:latest-s390x
push: true

- name: Create and push release manifest to GHCR
if: ${{ startsWith(github.ref, 'refs/tags/') }}
uses: Noelware/docker-manifest-action@master
with:
inputs: |
ghcr.io/kfermercer/${{ env.IMAGE_NAME }}:latest,
ghcr.io/kfermercer/${{ env.IMAGE_NAME }}:latest-release,
ghcr.io/kfermercer/${{ env.IMAGE_NAME }}:${{ env.RELEASE_VERSION }}
images: |
ghcr.io/kfermercer/${{ env.IMAGE_NAME }}:latest-x86,
ghcr.io/kfermercer/${{ env.IMAGE_NAME }}:latest-x86_64,
ghcr.io/kfermercer/${{ env.IMAGE_NAME }}:latest-armhf,
ghcr.io/kfermercer/${{ env.IMAGE_NAME }}:latest-armv7,
ghcr.io/kfermercer/${{ env.IMAGE_NAME }}:latest-aarch64,
ghcr.io/kfermercer/${{ env.IMAGE_NAME }}:latest-loongarch64,
ghcr.io/kfermercer/${{ env.IMAGE_NAME }}:latest-ppc64le,
ghcr.io/kfermercer/${{ env.IMAGE_NAME }}:latest-riscv64,
ghcr.io/kfermercer/${{ env.IMAGE_NAME }}:latest-s390x
push: true

0 comments on commit dfced3f

Please sign in to comment.