Skip to content

Build Docker Images and Release #238

Build Docker Images and Release

Build Docker Images and Release #238

Workflow file for this run

name: Build Docker Images and Release
on:
schedule:
- cron: "0 13 * * *"
workflow_dispatch:
env:
IMAGE_NAME: spiritlhl
GHCR_IMAGE: ghcr.io/oneclickvirt/docker
jobs:
build-and-push:
runs-on: ${{ matrix.runner }}
permissions:
contents: write
packages: write
strategy:
fail-fast: false
matrix:
include:
# Alpine builds
- dockerfile: Dockerfile_alpine
tag_suffix: alpine
arch: amd64
runner: ubuntu-latest
- dockerfile: Dockerfile_alpine
tag_suffix: alpine
arch: arm64
runner: ubuntu-24.04-arm
# Ubuntu builds
- dockerfile: Dockerfile_ubuntu
tag_suffix: ubuntu
arch: amd64
runner: ubuntu-latest
- dockerfile: Dockerfile_ubuntu
tag_suffix: ubuntu
arch: arm64
runner: ubuntu-24.04-arm
# Debian builds
- dockerfile: Dockerfile_debian
tag_suffix: debian
arch: amd64
runner: ubuntu-latest
- dockerfile: Dockerfile_debian
tag_suffix: debian
arch: arm64
runner: ubuntu-24.04-arm
# AlmaLinux builds
- dockerfile: Dockerfile_almalinux
tag_suffix: almalinux
arch: amd64
runner: ubuntu-latest
- dockerfile: Dockerfile_almalinux
tag_suffix: almalinux
arch: arm64
runner: ubuntu-24.04-arm
# Rocky Linux builds
- dockerfile: Dockerfile_rockylinux
tag_suffix: rockylinux
arch: amd64
runner: ubuntu-latest
- dockerfile: Dockerfile_rockylinux
tag_suffix: rockylinux
arch: arm64
runner: ubuntu-24.04-arm
# OpenEuler builds
- dockerfile: Dockerfile_openeuler
tag_suffix: openeuler
arch: amd64
runner: ubuntu-latest
- dockerfile: Dockerfile_openeuler
tag_suffix: openeuler
arch: arm64
runner: ubuntu-24.04-arm
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Docker image
run: |
docker build \
-f dockerfiles/${{ matrix.dockerfile }} \
-t ${{ env.IMAGE_NAME }}:${{ matrix.tag_suffix }}-${{ matrix.arch }} \
--platform linux/${{ matrix.arch }} \
.
- name: Push arch-specific image to GHCR
run: |
docker tag \
${{ env.IMAGE_NAME }}:${{ matrix.tag_suffix }}-${{ matrix.arch }} \
${{ env.GHCR_IMAGE }}:${{ matrix.tag_suffix }}-${{ matrix.arch }}
docker push ${{ env.GHCR_IMAGE }}:${{ matrix.tag_suffix }}-${{ matrix.arch }}
- name: Save Docker image as tar
run: |
FILENAME=${{ env.IMAGE_NAME }}_${{ matrix.tag_suffix }}_${{ matrix.arch }}.tar.gz
docker save ${{ env.IMAGE_NAME }}:${{ matrix.tag_suffix }}-${{ matrix.arch }} | gzip > $FILENAME
ls -lh *.tar.gz
- name: Upload artifact for release
uses: actions/upload-artifact@v4
with:
name: ${{ env.IMAGE_NAME }}_${{ matrix.tag_suffix }}_${{ matrix.arch }}
path: ${{ env.IMAGE_NAME }}_${{ matrix.tag_suffix }}_${{ matrix.arch }}.tar.gz
retention-days: 1
create-manifests:
needs: build-and-push
runs-on: ubuntu-latest
permissions:
packages: write
strategy:
fail-fast: false
matrix:
tag_suffix: [alpine, ubuntu, debian, almalinux, rockylinux, openeuler]
steps:
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create and push multi-arch manifest to GHCR
run: |
docker manifest create \
${{ env.GHCR_IMAGE }}:${{ matrix.tag_suffix }} \
${{ env.GHCR_IMAGE }}:${{ matrix.tag_suffix }}-amd64 \
${{ env.GHCR_IMAGE }}:${{ matrix.tag_suffix }}-arm64
docker manifest push ${{ env.GHCR_IMAGE }}:${{ matrix.tag_suffix }}
create-releases:
needs: build-and-push
runs-on: ubuntu-latest
permissions:
contents: write
strategy:
fail-fast: false
matrix:
tag_suffix: [alpine, ubuntu, debian, almalinux, rockylinux, openeuler]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download all artifacts for this OS
uses: actions/download-artifact@v4
with:
pattern: ${{ env.IMAGE_NAME }}_${{ matrix.tag_suffix }}_*
merge-multiple: true
- name: Create GitHub Release and upload assets
run: |
TAG=${{ matrix.tag_suffix }}
AMD64_FILE=${{ env.IMAGE_NAME }}_${{ matrix.tag_suffix }}_amd64.tar.gz
ARM64_FILE=${{ env.IMAGE_NAME }}_${{ matrix.tag_suffix }}_arm64.tar.gz
if ! gh release view "$TAG" >/dev/null 2>&1; then
git tag "$TAG" 2>/dev/null || true
git push origin "$TAG" 2>/dev/null || true
RELEASE_NOTES=$(printf 'Docker images for %s system.\n\nAvailable architectures:\n- AMD64: `%s`\n- ARM64: `%s`\n\nGHCR images (multi-arch):\n```\ndocker pull %s:%s\n```' \
"$TAG" "$AMD64_FILE" "$ARM64_FILE" "${{ env.GHCR_IMAGE }}" "$TAG")
gh release create "$TAG" \
--title "$TAG" \
--notes "$RELEASE_NOTES" \
--prerelease=false \
--draft=false
fi
EXISTING_FILES=$(gh release view "$TAG" --json assets --jq '.assets[].name')
for FILE in "$AMD64_FILE" "$ARM64_FILE"; do
if echo "$EXISTING_FILES" | grep -q "^$FILE$"; then
echo "File $FILE already exists in release $TAG. Deleting it..."
gh release delete-asset "$TAG" "$FILE" -y
sleep 12
fi
done
gh release upload "$TAG" "$AMD64_FILE" "$ARM64_FILE"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
IMAGE_NAME: ${{ env.IMAGE_NAME }}