Skip to content

Build Runtime Docker Image #19

Build Runtime Docker Image

Build Runtime Docker Image #19

name: Build Runtime Docker Image
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
push_image:
description: 'Whether to push image to registries'
required: false
default: false
type: boolean
image_tag:
description: 'Image tag (e.g., latest, v1.0.0). Leave empty to use git tag.'
required: false
default: ''
type: string
platforms:
description: 'Target platforms (comma-separated)'
required: false
default: 'linux/amd64,linux/arm64'
type: string
permissions:
contents: read
packages: write
jobs:
build-runtime:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: arm64,amd64
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: |
image=moby/buildkit:latest
network=host
- name: Login to GitHub Container Registry
# Always login to pull base image, even if not pushing
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ secrets.GHCR_USERNAME }}
password: ${{ secrets.PAT_GITHUB_TOKEN }}
- name: Login to Docker Hub
if: github.event_name == 'push' || inputs.push_image == true
uses: docker/login-action@v3
with:
username: curvine
password: ${{ secrets.PAT_DOCKERIO_TOKEN }}
- name: Extract metadata for Docker
id: meta
run: |
# Determine tag: use git tag if triggered by push, otherwise use input or 'latest'
if [ "${{ github.event_name }}" == "push" ]; then
# Extract tag from ref (refs/tags/v1.0.0 -> v1.0.0)
TAG="${GITHUB_REF#refs/tags/}"
PUSH_IMAGE="true"
echo "Triggered by tag push: ${TAG}"
elif [ -n "${{ inputs.image_tag }}" ]; then
TAG="${{ inputs.image_tag }}"
PUSH_IMAGE="${{ inputs.push_image }}"
echo "Using manual tag: ${TAG}"
else
TAG="latest"
PUSH_IMAGE="${{ inputs.push_image }}"
echo "Using default tag: ${TAG}"
fi
echo "tag=${TAG}" >> $GITHUB_OUTPUT
echo "push_image=${PUSH_IMAGE}" >> $GITHUB_OUTPUT
# Generate image names
GHCR_IMAGE="ghcr.io/curvineio/curvine"
DOCKER_IMAGE="curvine/curvine"
echo "ghcr_image=${GHCR_IMAGE}" >> $GITHUB_OUTPUT
echo "docker_image=${DOCKER_IMAGE}" >> $GITHUB_OUTPUT
# Also tag as 'latest' if this is a version tag
if [[ "${TAG}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+ ]]; then
echo "also_latest=true" >> $GITHUB_OUTPUT
echo "Will also tag as 'latest'"
else
echo "also_latest=false" >> $GITHUB_OUTPUT
fi
- name: Build and push Docker image (Rocky Linux 9)
uses: docker/build-push-action@v5
with:
context: .
file: ./curvine-docker/deploy/Dockerfile_rocky9
platforms: ${{ inputs.platforms || 'linux/amd64,linux/arm64' }}
push: ${{ steps.meta.outputs.push_image }}
tags: |
${{ steps.meta.outputs.ghcr_image }}:${{ steps.meta.outputs.tag }}
${{ steps.meta.outputs.docker_image }}:${{ steps.meta.outputs.tag }}
${{ steps.meta.outputs.also_latest == 'true' && format('{0}:latest', steps.meta.outputs.ghcr_image) || '' }}
${{ steps.meta.outputs.also_latest == 'true' && format('{0}:latest', steps.meta.outputs.docker_image) || '' }}
cache-from: type=gha
cache-to: type=gha,mode=max
shm-size: 2g
build-args: |
REPO_URL=https://github.com/${{ github.repository }}
- name: Image build summary
run: |
echo "### Build Summary :rocket:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Platform:** Rocky Linux 9" >> $GITHUB_STEP_SUMMARY
echo "**Architectures:** ${{ inputs.platforms || 'linux/amd64,linux/arm64' }}" >> $GITHUB_STEP_SUMMARY
echo "**Tag:** ${{ steps.meta.outputs.tag }}" >> $GITHUB_STEP_SUMMARY
echo "**Trigger:** ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.meta.outputs.push_image }}" == "true" ]; then
echo "**Images pushed to:**" >> $GITHUB_STEP_SUMMARY
echo "- \`${{ steps.meta.outputs.ghcr_image }}:${{ steps.meta.outputs.tag }}\`" >> $GITHUB_STEP_SUMMARY
echo "- \`${{ steps.meta.outputs.docker_image }}:${{ steps.meta.outputs.tag }}\`" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.meta.outputs.also_latest }}" == "true" ]; then
echo "- \`${{ steps.meta.outputs.ghcr_image }}:latest\`" >> $GITHUB_STEP_SUMMARY
echo "- \`${{ steps.meta.outputs.docker_image }}:latest\`" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Pull commands:**" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
echo "# Pull specific version" >> $GITHUB_STEP_SUMMARY
echo "docker pull ${{ steps.meta.outputs.ghcr_image }}:${{ steps.meta.outputs.tag }}" >> $GITHUB_STEP_SUMMARY
echo "# or from Docker Hub" >> $GITHUB_STEP_SUMMARY
echo "docker pull ${{ steps.meta.outputs.docker_image }}:${{ steps.meta.outputs.tag }}" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.meta.outputs.also_latest }}" == "true" ]; then
echo "" >> $GITHUB_STEP_SUMMARY
echo "# Pull latest version" >> $GITHUB_STEP_SUMMARY
echo "docker pull ${{ steps.meta.outputs.docker_image }}:latest" >> $GITHUB_STEP_SUMMARY
fi
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
else
echo "**Note:** Image was built but not pushed (push_image=false)" >> $GITHUB_STEP_SUMMARY
fi