Skip to content

Add kimia-bud pacakge #14

Add kimia-bud pacakge

Add kimia-bud pacakge #14

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
REPO_OWNER: ${{ github.repository_owner }}
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: kimia
dockerfile: Dockerfile.buildkit
description: "Kimia (BuildKit)"
- image_name: kimia-bud
dockerfile: Dockerfile.buildah
description: "Kimia-Bud (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.GITHUB_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 -u +"%Y-%m-%dT%H:%M:%SZ")
BUILD_TIMESTAMP=$(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 "BUILD_TIMESTAMP=${BUILD_TIMESTAMP}" >> $GITHUB_OUTPUT
echo "RELEASE_TYPE=${RELEASE_TYPE}" >> $GITHUB_OUTPUT
echo "πŸ“¦ Building version: ${VERSION}"
echo "🏷️ Release type: ${RELEASE_TYPE}"
echo "🐳 Image: ${{ matrix.image_name }}"
- name: Generate Docker tags
id: tags
run: |
VERSION="${{ steps.meta.outputs.VERSION }}"
RELEASE_TYPE="${{ steps.meta.outputs.RELEASE_TYPE }}"
COMMIT="${{ steps.meta.outputs.COMMIT }}"
# Build the full image name
IMAGE="${{ env.REGISTRY }}/${{ env.REPO_OWNER }}/${{ matrix.image_name }}"
# Generate tags based on release type
if [[ "${RELEASE_TYPE}" == "staging" ]]; then
TAGS="${IMAGE}:${VERSION}-staging"
TAGS="${TAGS},${IMAGE}:staging"
TAGS="${TAGS},${IMAGE}:${COMMIT}-staging"
else
# Production tags
TAGS="${IMAGE}:${VERSION}"
TAGS="${TAGS},${IMAGE}:latest"
# Add major.minor tag (e.g., 1.2.3 -> 1.2)
if [[ "${VERSION}" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
MAJOR="${BASH_REMATCH[1]}"
MINOR="${BASH_REMATCH[2]}"
TAGS="${TAGS},${IMAGE}:${MAJOR}.${MINOR}"
TAGS="${TAGS},${IMAGE}:${MAJOR}"
fi
fi
echo "TAGS=${TAGS}" >> $GITHUB_OUTPUT
echo "IMAGE=${IMAGE}" >> $GITHUB_OUTPUT
echo "🏷️ Tags: ${TAGS}"
- name: Build and push multi-arch image
id: build
uses: docker/build-push-action@v5
with:
context: .
file: ./${{ matrix.dockerfile }}
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.tags.outputs.TAGS }}
labels: |
org.opencontainers.image.title=${{ matrix.image_name }}
org.opencontainers.image.description=${{ matrix.description }}
org.opencontainers.image.version=${{ steps.meta.outputs.VERSION }}
org.opencontainers.image.created=${{ steps.meta.outputs.BUILD_DATE }}
org.opencontainers.image.revision=${{ steps.meta.outputs.COMMIT }}
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.url=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.vendor=${{ github.repository_owner }}
com.github.build.number=${{ github.run_number }}
com.github.build.id=${{ github.run_id }}
build-args: |
VERSION=${{ steps.meta.outputs.VERSION }}
BUILD_DATE=${{ steps.meta.outputs.BUILD_TIMESTAMP }}
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}
# Test that the image runs and has --version flag
echo "Testing --version flag..."
docker run --rm ${TEST_TAG} --version || echo "⚠️ Warning: --version test failed"
# Show image details
echo ""
echo "πŸ“¦ Image details:"
docker inspect ${TEST_TAG} --format='{{json .Config.Labels}}' | jq .
- name: Generate build summary
run: |
VERSION="${{ steps.meta.outputs.VERSION }}"
RELEASE_TYPE="${{ steps.meta.outputs.RELEASE_TYPE }}"
IMAGE="${{ steps.tags.outputs.IMAGE }}"
COMMIT="${{ steps.meta.outputs.COMMIT }}"
if [[ "${RELEASE_TYPE}" == "staging" ]]; then
PRIMARY_TAG="${VERSION}-staging"
else
PRIMARY_TAG="${VERSION}"
fi
cat >> $GITHUB_STEP_SUMMARY <<EOF
## πŸš€ Release Summary - ${{ matrix.description }}
| Property | Value |
|----------|-------|
| **Version** | \`${VERSION}\` |
| **Type** | ${RELEASE_TYPE} |
| **Commit** | \`${COMMIT}\` |
| **Dockerfile** | \`${{ matrix.dockerfile }}\` |
| **Architectures** | amd64, arm64 |
| **Image** | \`${IMAGE}\` |
### 🏷️ Tags Created
\`\`\`
${{ steps.tags.outputs.TAGS }}
\`\`\`
### πŸ“₯ Installation
\`\`\`bash
# Pull the image
docker pull ${IMAGE}:${PRIMARY_TAG}
# Run it
docker run --rm ${IMAGE}:${PRIMARY_TAG} --version
# Use in Kubernetes
kubectl set image deployment/my-app \\
my-app=${IMAGE}:${PRIMARY_TAG}
\`\`\`
### πŸ”— Links
- [View package](https://github.com/${{ github.repository_owner }}?tab=packages&repo_name=${{ github.event.repository.name }})
- [Dockerfile](${{ github.server_url }}/${{ github.repository }}/blob/${{ github.sha }}/${{ matrix.dockerfile }})
EOF
summary:
runs-on: ubuntu-latest
needs: build-and-push
if: always()
steps:
- name: Check build status
id: check
run: |
if [[ "${{ needs.build-and-push.result }}" == "success" ]]; then
echo "STATUS=βœ… Success" >> $GITHUB_OUTPUT
echo "COLOR=green" >> $GITHUB_OUTPUT
else
echo "STATUS=❌ Failed" >> $GITHUB_OUTPUT
echo "COLOR=red" >> $GITHUB_OUTPUT
fi
- name: Final build summary
run: |
cat >> $GITHUB_STEP_SUMMARY <<EOF
## ${{ steps.check.outputs.STATUS }} - Multi-Image Build Complete
Both **kimia** (BuildKit) and **kimia-bud** (Buildah) images have been processed.
### πŸ“¦ Packages
- [\`kimia\`](https://github.com/${{ github.repository_owner }}/kimia/pkgs/container/kimia)
- [\`kimia-bud\`](https://github.com/${{ github.repository_owner }}/kimia/pkgs/container/kimia-bud)
### πŸ“₯ Quick Start
\`\`\`bash
# Pull kimia (BuildKit-based)
docker pull ${{ env.REGISTRY }}/${{ env.REPO_OWNER }}/kimia:latest
# Pull kimia-bud (Buildah-based)
docker pull ${{ env.REGISTRY }}/${{ env.REPO_OWNER }}/kimia-bud:latest
\`\`\`
### 🎯 Next Steps
$(if [[ "${{ github.event_name }}" == "workflow_dispatch" ]] && [[ "${{ github.event.inputs.release_type }}" == "staging" ]]; then
echo "To promote to production, create a version tag:"
echo "\`\`\`bash"
echo "git tag v1.0.0"
echo "git push origin v1.0.0"
echo "\`\`\`"
else
echo "Production release complete! πŸŽ‰"
fi)
EOF
create-release:
runs-on: ubuntu-latest
needs: build-and-push
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get version
id: version
run: |
VERSION=${GITHUB_REF#refs/tags/}
VERSION=${VERSION#v}
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Generate release notes
id: notes
run: |
VERSION="${{ steps.version.outputs.VERSION }}"
# Get previous tag
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [[ -n "${PREV_TAG}" ]]; then
COMMITS=$(git log ${PREV_TAG}..HEAD --oneline --pretty=format:"- %s (%h)")
else
COMMITS=$(git log --oneline --pretty=format:"- %s (%h)" | head -20)
fi
cat > release_notes.md <<EOF
## πŸš€ Release v${VERSION}
### πŸ“¦ Container Images
#### Kimia (BuildKit-based)
\`\`\`bash
docker pull ghcr.io/${{ github.repository_owner }}/kimia:${VERSION}
docker pull ghcr.io/${{ github.repository_owner }}/kimia:latest
\`\`\`
#### Kimia-Bud (Buildah-based)
\`\`\`bash
docker pull ghcr.io/${{ github.repository_owner }}/kimia-bud:${VERSION}
docker pull ghcr.io/${{ github.repository_owner }}/kimia-bud:latest
\`\`\`
### πŸ—οΈ Supported Architectures
- linux/amd64
- linux/arm64
### πŸ“ Changes
${COMMITS}
### πŸ”— Links
- [kimia package](https://github.com/${{ github.repository_owner }}/kimia/pkgs/container/kimia)
- [kimia-bud package](https://github.com/${{ github.repository_owner }}/kimia/pkgs/container/kimia-bud)
EOF
cat release_notes.md
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.version.outputs.TAG }}
name: Release ${{ steps.version.outputs.TAG }}
body_path: release_notes.md
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}