Build and Deploy Advanced (Docker Compose) #27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Deploy Advanced (Docker Compose) | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: Optional version tag override (e.g. v1.2.3) | |
| required: false | |
| push: | |
| branches: [ "main" ] | |
| paths: | |
| - "*" | |
| - "backends/advanced/**" | |
| - "extras/asr-services/**" | |
| - "extras/speaker-recognition/**" | |
| - ".github/workflows/advanced-docker-compose-build.yml" | |
| release: | |
| types: [ published ] | |
| permissions: | |
| contents: write | |
| packages: write | |
| actions: read | |
| env: | |
| REGISTRY: ghcr.io | |
| jobs: | |
| build-images: | |
| name: Build ${{ matrix.image }} | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 60 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - image: chronicle-backend | |
| service: chronicle-backend | |
| source-image: chronicle-backend:latest | |
| directory: backends/advanced | |
| variant: "" | |
| - image: chronicle-asr-nemo-cu126 | |
| service: parakeet-asr | |
| source-image: parakeet-asr:latest | |
| directory: extras/asr-services | |
| variant: cu126 | |
| - image: chronicle-asr-nemo-cu128 | |
| service: parakeet-asr | |
| source-image: parakeet-asr:latest | |
| directory: extras/asr-services | |
| variant: cu128 | |
| - image: chronicle-speaker-cpu | |
| service: speaker-service | |
| source-image: chronicle-speaker:latest | |
| directory: extras/speaker-recognition | |
| variant: cpu | |
| - image: chronicle-speaker-cu126 | |
| service: speaker-service | |
| source-image: chronicle-speaker:latest | |
| directory: extras/speaker-recognition | |
| variant: cu126 | |
| - image: chronicle-speaker-cu128 | |
| service: speaker-service | |
| source-image: chronicle-speaker:latest | |
| directory: extras/speaker-recognition | |
| variant: cu128 | |
| env: | |
| ADVANCED_ENV: ${{ secrets.ADVANCED_ENV }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Print commit details | |
| working-directory: ${{ matrix.directory }} | |
| run: | | |
| echo "Image: ${{ matrix.image }}" | |
| echo "Event: ${{ github.event_name }}" | |
| echo "Ref: $GITHUB_REF" | |
| echo "Ref name: ${{ github.ref_name }}" | |
| echo "Repository: $GITHUB_REPOSITORY" | |
| echo "Actor: $GITHUB_ACTOR" | |
| echo "SHA: $GITHUB_SHA" | |
| echo "Short SHA: ${GITHUB_SHA::7}" | |
| echo "Commit info:" | |
| git log -1 --pretty=format:'Author: %an <%ae>%nDate: %ad%nSubject: %s' || true | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Copy .env template | |
| working-directory: ${{ matrix.directory }} | |
| run: | | |
| set -euo pipefail | |
| if [ -f .env.template ]; then | |
| cp .env.template .env | |
| else | |
| touch .env | |
| fi | |
| - name: Create .env from secret (if provided) | |
| if: matrix.image == 'chronicle-backend' && env.ADVANCED_ENV != '' | |
| working-directory: ${{ matrix.directory }} | |
| run: | | |
| echo "Writing .env from ADVANCED_ENV secret" | |
| printf "%s\n" "${ADVANCED_ENV}" > .env | |
| - name: Free Disk Space | |
| working-directory: ${{ matrix.directory }} | |
| run: | | |
| echo "Freeing disk space..." | |
| df -h | |
| sudo rm -rf /usr/share/dotnet | |
| sudo rm -rf /usr/local/lib/android | |
| sudo rm -rf /opt/ghc | |
| sudo rm -rf /usr/share/swift | |
| docker system prune -a -f | |
| df -h | |
| - name: Determine version | |
| id: version | |
| working-directory: ${{ matrix.directory }} | |
| run: | | |
| if [ -n "${{ github.event.inputs.version }}" ]; then | |
| VERSION="${{ github.event.inputs.version }}" | |
| elif [ "${{ github.event_name }}" = "release" ]; then | |
| VERSION="${{ github.event.release.tag_name }}" | |
| elif [[ "${GITHUB_REF}" == refs/tags/* ]]; then | |
| VERSION="${GITHUB_REF#refs/tags/}" | |
| else | |
| VERSION="sha-${GITHUB_SHA::7}" | |
| fi | |
| echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT" | |
| - name: Build, tag, and push ${{ matrix.image }} | |
| working-directory: ${{ matrix.directory }} | |
| env: | |
| OWNER: ${{ github.repository_owner }} | |
| VERSION: ${{ steps.version.outputs.VERSION }} | |
| CHRONICLE_BUILD_VERSION: ${{ steps.version.outputs.VERSION }} | |
| PYTORCH_CUDA_VERSION: ${{ matrix.variant }} | |
| run: | | |
| set -euo pipefail | |
| docker compose version | |
| OWNER_LC=$(echo "$OWNER" | tr '[:upper:]' '[:lower:]') | |
| docker compose build --pull "${{ matrix.service }}" | |
| img_id=$(docker image inspect "${{ matrix.source-image }}" --format '{{.Id}}') | |
| target_image="$REGISTRY/$OWNER_LC/${{ matrix.image }}:$VERSION" | |
| latest_image="$REGISTRY/$OWNER_LC/${{ matrix.image }}:latest" | |
| docker tag "$img_id" "$target_image" | |
| docker tag "$img_id" "$latest_image" | |
| docker push "$target_image" | |
| docker push "$latest_image" | |
| update-release: | |
| name: Update release notes | |
| needs: build-images | |
| if: github.event_name == 'release' || inputs.version != '' | |
| runs-on: ubuntu-latest | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| OWNER: ${{ github.repository_owner }} | |
| VERSION: ${{ github.event.release.tag_name || inputs.version }} | |
| TAG_NAME: ${{ github.event.release.tag_name || inputs.version }} | |
| steps: | |
| - name: Update release notes with Docker images | |
| run: | | |
| set -euo pipefail | |
| OWNER_LC=$(echo "$OWNER" | tr '[:upper:]' '[:lower:]') | |
| DOCKER_SECTION=$(cat <<EOF | |
| --- | |
| ## Docker Images | |
| All images are published to \`ghcr.io/${OWNER_LC}\` with tags \`${VERSION}\` and \`latest\`. | |
| ### Core Services | |
| \`\`\`bash | |
| docker pull ghcr.io/${OWNER_LC}/chronicle-backend:${VERSION} | |
| \`\`\` | |
| ### Parakeet ASR (pick your CUDA version) | |
| \`\`\`bash | |
| docker pull ghcr.io/${OWNER_LC}/chronicle-asr-nemo-cu126:${VERSION} | |
| docker pull ghcr.io/${OWNER_LC}/chronicle-asr-nemo-cu128:${VERSION} | |
| \`\`\` | |
| ### Speaker Recognition (pick your variant) | |
| \`\`\`bash | |
| docker pull ghcr.io/${OWNER_LC}/chronicle-speaker-cpu:${VERSION} | |
| docker pull ghcr.io/${OWNER_LC}/chronicle-speaker-cu126:${VERSION} | |
| docker pull ghcr.io/${OWNER_LC}/chronicle-speaker-cu128:${VERSION} | |
| \`\`\` | |
| EOF | |
| ) | |
| EXISTING_BODY=$(gh release view "$TAG_NAME" --json body -q '.body' --repo "$GITHUB_REPOSITORY") | |
| EXISTING_BODY="${EXISTING_BODY%%$'\n---\n\n## Docker Images'*}" | |
| UPDATED_BODY="${EXISTING_BODY}${DOCKER_SECTION}" | |
| gh release edit "$TAG_NAME" --notes "$UPDATED_BODY" --repo "$GITHUB_REPOSITORY" | |
| echo "Release notes updated with Docker image info" |