Skip to content

Docker Build & Push All Services #64

Docker Build & Push All Services

Docker Build & Push All Services #64

name: Docker Build & Push All Services
on:
delete:
push:
tags:
- "v*.*.*"
- "v*.*.*-*"
release:
types: [published]
jobs:
debug:
runs-on: ubuntu-latest
steps:
- name: πŸ” Show event name and action
run: |
echo "ref ${{ github.ref }}"
echo "event_ref ${{ github.event.ref }}"
echo "ref_type: ${{ github.event.ref_type }}"
echo "event_name: ${{ github.event_name }}"
echo "event_action: ${{ github.event.action }}"
discover:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: 🧾 Checkout repository
uses: actions/checkout@v3
- name: 🧠 Discover components and services
id: set-matrix
run: |
mkdir -p .build/tmp_matrix
echo '{ "include": [' > .build/tmp_matrix/matrix.json
FIRST=true
for comp in subvortex/*; do
[ -d "$comp" ] || continue
comp_name=$(basename "$comp")
# βœ… Include only if it has a pyproject or version.py
if [[ -f "$comp/pyproject.toml" || -f "$comp/version.py" ]]; then
if [ "$FIRST" = true ]; then
FIRST=false
else
echo "," >> .build/tmp_matrix/matrix.json
fi
echo " { \"component\": \"$comp_name\" }" >> .build/tmp_matrix/matrix.json
fi
done
echo "] }" >> .build/tmp_matrix/matrix.json
echo "matrix<<EOF" >> $GITHUB_OUTPUT
cat .build/tmp_matrix/matrix.json >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "πŸ” Final matrix ready."
build:
if: github.event_name == 'push' || github.event_name == 'delete'
needs: [discover]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
matrix:
include: ${{ fromJson(needs.discover.outputs.matrix).include }}
steps:
- name: 🧾 Checkout repository
uses: actions/checkout@v3
- name: πŸ›  Set up QEMU
uses: docker/setup-qemu-action@v2
- name: 🧱 Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: πŸ” Docker Login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: 🧠 Generate build tag from hash
id: meta
run: |
HASH=$(sha256sum subvortex/core/Dockerfile.builder | cut -d ' ' -f1)
echo "tag=subvortex/subvortex-wheel-builder:3.11-$HASH" >> $GITHUB_OUTPUT
- name: πŸ‹ Build & push wheel-builder (only if not exists)
if: startsWith(github.ref, 'refs/tags/') && github.event_name == 'push'
id: wheelbuilder
run: |
TAG="${{ steps.meta.outputs.tag }}"
LATEST_TAG="subvortex/subvortex-wheel-builder:latest"
if docker pull "$TAG" >/dev/null 2>&1; then
echo "βœ… Image already exists: $TAG"
else
echo "πŸš€ Building wheel-builder image"
docker buildx build \
--platform linux/amd64 \
--tag "$TAG" \
--tag "$LATEST_TAG" \
--file subvortex/core/Dockerfile.builder \
--push \
.
fi
echo "tag=$TAG" >> $GITHUB_OUTPUT
- name: 🧠 Determine tag and floating tags
id: taginfo
run: |
TAG="${GITHUB_REF#refs/tags/}"
echo "version_tag=$TAG" >> $GITHUB_OUTPUT
FLOATING_TAGS="dev"
if [[ "$TAG" == *-rc* ]]; then
FLOATING_TAGS="dev stable"
elif [[ "$TAG" != *-* ]]; then
FLOATING_TAGS="dev stable latest"
fi
echo "floating_tags=$FLOATING_TAGS" >> $GITHUB_OUTPUT
- name: πŸš€ Build and push version-tagged image (on tag push only)
if: startsWith(github.ref, 'refs/tags/') && github.event_name == 'push'
run: |
.github/scripts/on_tag_pushed.sh \
"${{ matrix.component }}" \
"${{ steps.meta.outputs.tag }}" \
"${{ steps.taginfo.outputs.version_tag }}"
- name: 🧹 Remove version-tagged image (on tag delete)
if: github.event_name == 'delete' && github.event.ref_type == 'tag'
run: |
.github/scripts/on_tag_deleted.sh "${{ matrix.component }}" "${{ matrix.service }}" "${{ github.event.ref }}"
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
release:
if: github.event_name == 'release'
needs: [discover]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
matrix:
include: ${{ fromJson(needs.discover.outputs.matrix).include }}
steps:
- name: 🧾 Checkout repository
uses: actions/checkout@v3
- name: πŸ›  Set up QEMU
uses: docker/setup-qemu-action@v2
- name: 🧱 Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: πŸ” Docker Login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: 🧠 Determine tag and floating tags
id: taginfo
run: |
TAG="${GITHUB_REF#refs/tags/}"
echo "version_tag=$TAG" >> $GITHUB_OUTPUT
FLOATING_TAGS="dev"
if [[ "$TAG" == *-rc* ]]; then
FLOATING_TAGS="dev stable"
elif [[ "$TAG" != *-* ]]; then
FLOATING_TAGS="dev stable latest"
fi
echo "floating_tags=$FLOATING_TAGS" >> $GITHUB_OUTPUT
- name: πŸš€ Retag and push floating tags (on release or prerelease)
if: github.event_name == 'release' && github.event.action != 'deleted'
run: |
.github/scripts/on_release_pushed.sh \
"${{ matrix.component }}" \
"${{ steps.taginfo.outputs.version_tag }}" \
"${{ github.event.release.prerelease }}" \
"${{ github.event.release.draft }}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}