mirror of
https://github.com/basnijholt/compose-farm.git
synced 2026-02-08 00:12:11 +00:00
93 lines
2.9 KiB
YAML
93 lines
2.9 KiB
YAML
name: Build and Push Docker Image
|
|
|
|
on:
|
|
workflow_run:
|
|
workflows: ["Upload Python Package"]
|
|
types: [completed]
|
|
workflow_dispatch:
|
|
inputs:
|
|
version:
|
|
description: 'Version to build (leave empty for latest)'
|
|
required: false
|
|
|
|
env:
|
|
REGISTRY: ghcr.io
|
|
IMAGE_NAME: ${{ github.repository }}
|
|
|
|
jobs:
|
|
build-and-push:
|
|
runs-on: ubuntu-latest
|
|
# Only run if PyPI upload succeeded (or manual dispatch)
|
|
if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }}
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v6
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Extract version
|
|
id: version
|
|
run: |
|
|
if [ "${{ github.event_name }}" = "workflow_run" ]; then
|
|
# Get version from the tag that triggered the release
|
|
VERSION="${{ github.event.workflow_run.head_branch }}"
|
|
# Strip 'v' prefix if present
|
|
VERSION="${VERSION#v}"
|
|
elif [ -n "${{ github.event.inputs.version }}" ]; then
|
|
VERSION="${{ github.event.inputs.version }}"
|
|
else
|
|
VERSION=""
|
|
fi
|
|
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
|
|
|
- name: Wait for PyPI
|
|
if: steps.version.outputs.version != ''
|
|
run: |
|
|
VERSION="${{ steps.version.outputs.version }}"
|
|
echo "Waiting for compose-farm==$VERSION on PyPI..."
|
|
for i in {1..30}; do
|
|
if curl -sf "https://pypi.org/pypi/compose-farm/$VERSION/json" > /dev/null; then
|
|
echo "✓ Version $VERSION available on PyPI"
|
|
exit 0
|
|
fi
|
|
echo "Attempt $i: not yet available, waiting 10s..."
|
|
sleep 10
|
|
done
|
|
echo "✗ Timeout waiting for PyPI"
|
|
exit 1
|
|
|
|
- name: Extract metadata
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
tags: |
|
|
type=semver,pattern={{version}},value=v${{ steps.version.outputs.version }}
|
|
type=semver,pattern={{major}}.{{minor}},value=v${{ steps.version.outputs.version }}
|
|
type=semver,pattern={{major}},value=v${{ steps.version.outputs.version }}
|
|
type=raw,value=latest
|
|
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
push: true
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
build-args: |
|
|
VERSION=${{ steps.version.outputs.version }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|