Skip to content

v1.0.11

v1.0.11 #11

Workflow file for this run

name: Release Multi-Arch Images
on:
push:
tags:
- 'v*.*.*'
workflow_dispatch:
inputs:
release_type:
description: 'Release type'
required: true
type: choice
options:
- staging
- production
env:
REGISTRY: ghcr.io
BASE_IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write # For OIDC
attestations: write # For provenance
strategy:
matrix:
include:
- image_name: smithy
dockerfile: Dockerfile.buildkit
- image_name: smithy-bud
dockerfile: Dockerfile.buildah
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Extract version metadata
id: meta
run: |
# Get version from tag (strip 'v' prefix: v1.0.3 -> 1.0.3)
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
VERSION=${VERSION#v}
RELEASE_TYPE="production"
else
VERSION=$(git describe --tags --abbrev=0 2>/dev/null | sed 's/^v//' || echo "0.0.0")
RELEASE_TYPE="${{ github.event.inputs.release_type || 'staging' }}"
fi
COMMIT=$(git rev-parse --short HEAD)
BRANCH=$(git rev-parse --abbrev-ref HEAD)
BUILD_DATE=$(date +%s)
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
echo "COMMIT=${COMMIT}" >> $GITHUB_OUTPUT
echo "BRANCH=${BRANCH}" >> $GITHUB_OUTPUT
echo "BUILD_DATE=${BUILD_DATE}" >> $GITHUB_OUTPUT
echo "RELEASE_TYPE=${RELEASE_TYPE}" >> $GITHUB_OUTPUT
echo "📦 Building version: ${VERSION}"
echo "🏷️ Release type: ${RELEASE_TYPE}"
- name: Generate Docker tags
id: tags
run: |
VERSION="${{ steps.meta.outputs.VERSION }}"
RELEASE_TYPE="${{ steps.meta.outputs.RELEASE_TYPE }}"
# Get the repository owner and name
REPO_OWNER="${{ github.repository_owner }}"
REPO_NAME="${{ github.event.repository.name }}"
# Build the full image name
IMAGE="${{ env.REGISTRY }}/${REPO_OWNER}/${{ matrix.image_name }}"
# Generate tags based on release type
if [[ "${RELEASE_TYPE}" == "staging" ]]; then
TAGS="${IMAGE}:${VERSION}-staging,${IMAGE}:latest-staging"
else
TAGS="${IMAGE}:${VERSION},${IMAGE}:latest"
fi
echo "TAGS=${TAGS}" >> $GITHUB_OUTPUT
echo "IMAGE=${IMAGE}" >> $GITHUB_OUTPUT
echo "🏷️ Tags for ${{ matrix.image_name }}: ${TAGS}"
- name: Build and push multi-arch image
uses: docker/build-push-action@v5
with:
context: .
file: ./${{ matrix.dockerfile }}
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.tags.outputs.TAGS }}
build-args: |
VERSION=${{ steps.meta.outputs.VERSION }}
BUILD_DATE=${{ steps.meta.outputs.BUILD_DATE }}
COMMIT=${{ steps.meta.outputs.COMMIT }}
BRANCH=${{ steps.meta.outputs.BRANCH }}
RELEASE=1
cache-from: type=gha,scope=${{ matrix.image_name }}
cache-to: type=gha,mode=max,scope=${{ matrix.image_name }}
- name: Test image (smoke test)
run: |
VERSION="${{ steps.meta.outputs.VERSION }}"
RELEASE_TYPE="${{ steps.meta.outputs.RELEASE_TYPE }}"
IMAGE="${{ steps.tags.outputs.IMAGE }}"
if [[ "${RELEASE_TYPE}" == "staging" ]]; then
TEST_TAG="${IMAGE}:${VERSION}-staging"
else
TEST_TAG="${IMAGE}:${VERSION}"
fi
echo "🧪 Testing image: ${TEST_TAG}"
docker pull ${TEST_TAG}
docker run --rm ${TEST_TAG} --version
- name: Generate build summary
run: |
VERSION="${{ steps.meta.outputs.VERSION }}"
RELEASE_TYPE="${{ steps.meta.outputs.RELEASE_TYPE }}"
IMAGE="${{ steps.tags.outputs.IMAGE }}"
if [[ "${RELEASE_TYPE}" == "staging" ]]; then
TAG="${VERSION}-staging"
else
TAG="${VERSION}"
fi
cat >> $GITHUB_STEP_SUMMARY <<EOF
## 🚀 Release Summary - ${{ matrix.image_name }}
- **Version**: ${VERSION}
- **Type**: ${RELEASE_TYPE}
- **Commit**: ${{ steps.meta.outputs.COMMIT }}
- **Dockerfile**: ${{ matrix.dockerfile }}
- **Architectures**: amd64, arm64
- **Image**: ${IMAGE}
- **Tags**: ${{ steps.tags.outputs.TAGS }}
### Installation
\`\`\`bash
# Pull the image
docker pull ${IMAGE}:${TAG}
# Or use in Kubernetes
kubectl set image deployment/${{ matrix.image_name }} \\
${{ matrix.image_name }}=${IMAGE}:${TAG}
\`\`\`
EOF
summary:
runs-on: ubuntu-latest
needs: build-and-push
if: always()
steps:
- name: Final build summary
run: |
cat >> $GITHUB_STEP_SUMMARY <<EOF
## ✅ Multi-Image Build Complete
Both **smithy** (buildkit) and **smithy-bud** (buildah) images have been built and pushed successfully.
### Quick Reference
\`\`\`bash
# Pull smithy
docker pull ${{ env.REGISTRY }}/${{ github.repository_owner }}/smithy:latest
# Pull smithy-bud
docker pull ${{ env.REGISTRY }}/${{ github.repository_owner }}/smithy-bud:latest
\`\`\`
EOF
promote-to-production:
runs-on: ubuntu-latest
needs: build-and-push
if: github.event.inputs.release_type == 'staging' && github.event_name == 'workflow_dispatch'
permissions:
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get version
id: version
run: |
VERSION=$(git describe --tags --abbrev=0 2>/dev/null | sed 's/^v//' || echo "0.0.0")
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
- name: Promote staging to production
run: |
echo "✨ Staging build complete. To promote to production:"
echo ""
echo " git tag v${{ steps.version.outputs.VERSION }}"
echo " git push origin v${{ steps.version.outputs.VERSION }}"
echo ""
echo "This will trigger a production release for both images:"
echo " - smithy (buildkit)"
echo " - smithy-bud (buildah)"