Skip to content

Build Docker Images and Release #170

Build Docker Images and Release

Build Docker Images and Release #170

Workflow file for this run

name: Build Docker Images and Release
on:
schedule:
- cron: "0 13 * * *"
workflow_dispatch:
env:
REGISTRY: docker.io
IMAGE_NAME: spiritlhl
jobs:
build-and-release:
runs-on: ${{ matrix.runner }}
permissions:
contents: write
packages: write
strategy:
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: Build Docker image
run: |
docker build \
-f dockerfiles/${{ matrix.dockerfile }} \
-t ${{ env.IMAGE_NAME }}:${{ matrix.tag_suffix }}-${{ matrix.arch }} \
--platform linux/${{ 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-releases:
needs: build-and-release
runs-on: ubuntu-latest
permissions:
contents: write
strategy:
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
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"
git push origin "$TAG"
gh release create "$TAG" \
--title "$TAG" \
--notes "Docker images for $TAG system.
Available architectures:
- AMD64: $AMD64_FILE
- ARM64: $ARM64_FILE" \
--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 }}