Skip to content

Docker Image

Docker Image #9

Workflow file for this run

name: Docker Image
on:
# Called by release.yml or other workflows
workflow_call:
inputs:
tag:
description: "Image tag override (leave empty for auto-detect)"
required: false
type: string
default: ""
# On-demand builds
workflow_dispatch:
inputs:
tag:
description: "Image tag override (leave empty for auto-detect)"
required: false
type: string
default: ""
# Daily staging build from the staging branch
schedule:
- cron: '0 6 * * *'
env:
IMAGE_NAME: nearaidev/ironclaw
WORKER_IMAGE_NAME: nearaidev/ironclaw-worker
jobs:
build:
name: Build & Push
runs-on: ubuntu-24.04
permissions:
contents: read
packages: read
actions: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'schedule' && 'staging' || '' }}
- name: Extract version from Cargo.toml
id: version
run: |
VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)"/\1/')
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "Detected version: ${VERSION}"
- name: Determine tags
id: tags
run: |
VERSION="${{ steps.version.outputs.version }}"
SHA="sha-${GITHUB_SHA::7}"
echo "sha_tag=${SHA}" >> "$GITHUB_OUTPUT"
if [[ "${{ github.event_name }}" == "workflow_call" ]]; then
# Release: :version + :latest + :sha-xxx
TAGS="${{ env.IMAGE_NAME }}:${VERSION}"
TAGS="${TAGS},${{ env.IMAGE_NAME }}:latest"
TAGS="${TAGS},${{ env.IMAGE_NAME }}:${SHA}"
WORKER_TAGS="${{ env.WORKER_IMAGE_NAME }}:${VERSION}"
WORKER_TAGS="${WORKER_TAGS},${{ env.WORKER_IMAGE_NAME }}:latest"
WORKER_TAGS="${WORKER_TAGS},${{ env.WORKER_IMAGE_NAME }}:${SHA}"
elif [[ "${{ github.event_name }}" == "schedule" ]]; then
# Daily staging: :staging + :sha-xxx
TAGS="${{ env.IMAGE_NAME }}:staging"
TAGS="${TAGS},${{ env.IMAGE_NAME }}:${SHA}"
WORKER_TAGS="${{ env.WORKER_IMAGE_NAME }}:staging"
WORKER_TAGS="${WORKER_TAGS},${{ env.WORKER_IMAGE_NAME }}:${SHA}"
else
# Manual dispatch: :sha-xxx only
TAGS="${{ env.IMAGE_NAME }}:${SHA}"
WORKER_TAGS="${{ env.WORKER_IMAGE_NAME }}:${SHA}"
fi
# Manual override adds an extra tag (e.g. "staging")
if [[ -n "${{ inputs.tag }}" ]]; then
TAGS="${TAGS},${{ env.IMAGE_NAME }}:${{ inputs.tag }}"
WORKER_TAGS="${WORKER_TAGS},${{ env.WORKER_IMAGE_NAME }}:${{ inputs.tag }}"
fi
echo "tags=${TAGS}" >> "$GITHUB_OUTPUT"
echo "worker_tags=${WORKER_TAGS}" >> "$GITHUB_OUTPUT"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKER_REGISTRY_USER }}
password: ${{ secrets.DOCKER_REGISTRY_TOKEN }}
- name: Build and push (ironclaw)
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.tags.outputs.tags }}
platforms: linux/amd64
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build and push (ironclaw-worker)
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile.worker
push: true
tags: ${{ steps.tags.outputs.worker_tags }}
platforms: linux/amd64
cache-from: type=gha,scope=worker
cache-to: type=gha,mode=max,scope=worker
- name: Summary
run: |
{
echo "## Docker Images"
echo ""
echo "**ironclaw:**"
echo '```'
echo "${{ steps.tags.outputs.tags }}" | tr ',' '\n'
echo '```'
echo ""
echo "**ironclaw-worker:**"
echo '```'
echo "${{ steps.tags.outputs.worker_tags }}" | tr ',' '\n'
echo '```'
echo ""
echo "- version: \`${{ steps.version.outputs.version }}\`"
echo "- sha: \`${GITHUB_SHA::7}\`"
} >> "$GITHUB_STEP_SUMMARY"