Merge pull request #8 from VirtualFlyBrain/site/search-palette #61
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: Docker Site CI | |
| on: | |
| push: | |
| branches: [ main, master ] | |
| tags: [ 'v*', '*.*' ] # matches v1.2.3 and bare semver like 1.0 | |
| pull_request: | |
| branches: [ main, master ] | |
| workflow_dispatch: {} # manual re-run, e.g. to backfill a release tag cut before this fix | |
| env: | |
| DOCKER_IMAGE: virtualflybrain/vfb-workshop-site | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Extract version from ref | |
| id: version | |
| run: | | |
| if [[ $GITHUB_REF == refs/tags/* ]]; then | |
| VERSION=${GITHUB_REF#refs/tags/} | |
| elif [[ $GITHUB_REF == refs/heads/* ]]; then | |
| VERSION=${GITHUB_REF#refs/heads/} | |
| VERSION=${VERSION//\//-} # branch names can contain slashes (e.g. fix/foo); tags can't | |
| elif [[ $GITHUB_REF == refs/pull/* ]]; then | |
| # PR builds run on the refs/pull/<N>/merge ref, not a branch, and | |
| # that ref (and branch names with slashes, like fix/foo) aren't | |
| # valid Docker tags. Tag PR builds by PR number instead. | |
| PR_NUM=${GITHUB_REF#refs/pull/} | |
| PR_NUM=${PR_NUM%/merge} | |
| VERSION="pr-${PR_NUM}" | |
| else | |
| # Fallback for any other ref shape: sanitize slashes for a valid Docker tag. | |
| VERSION=$(echo "${GITHUB_REF#refs/}" | tr '/' '-') | |
| fi | |
| echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
| echo "Built version: ${VERSION}" | |
| - name: Login to Docker Hub | |
| if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_HUB_USER }} | |
| password: ${{ secrets.DOCKER_HUB_PASSWORD }} | |
| - name: Build Docker image (multi-arch) | |
| run: | | |
| if [[ $GITHUB_REF == refs/heads/main* ]] || [[ $GITHUB_REF == refs/heads/master* ]] || [[ $GITHUB_REF == refs/tags/* ]] || [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
| # Real release (or a manual re-run): push a proper multi-arch manifest list to Docker Hub. | |
| PUSH_FLAG="--push" | |
| PLATFORMS="linux/amd64,linux/arm64" | |
| else | |
| # PR/branch build verification only: --load can't import a | |
| # multi-platform manifest list into the local Docker daemon | |
| # ("docker exporter does not currently support exporting | |
| # manifest lists"), so build just the runner's native arch and | |
| # load that single image for testing. | |
| PUSH_FLAG="--load" | |
| PLATFORMS="linux/amd64" | |
| fi | |
| docker buildx build . \ | |
| --file Dockerfile.site \ | |
| --platform ${PLATFORMS} \ | |
| --tag ${DOCKER_IMAGE}:${{ steps.version.outputs.version }} \ | |
| --tag ${DOCKER_IMAGE}:latest \ | |
| ${PUSH_FLAG} | |
| - name: Verify build | |
| run: | | |
| if [[ $GITHUB_REF == refs/heads/main* ]] || [[ $GITHUB_REF == refs/heads/master* ]] || [[ $GITHUB_REF == refs/tags/* ]] || [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
| echo "Multi-arch build pushed to Docker Hub" | |
| else | |
| echo "PR build - image loaded locally" | |
| fi | |
| - name: Create build summary | |
| if: always() | |
| run: | | |
| echo "## Docker Build Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**Image:** \`${DOCKER_IMAGE}\`" >> $GITHUB_STEP_SUMMARY | |
| echo "**Version:** \`${{ steps.version.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY | |
| echo "**Status:** ${{ job.status }}" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| if [ "${{ job.status }}" == "success" ]; then | |
| echo "✓ Build completed successfully" >> $GITHUB_STEP_SUMMARY | |
| if [[ $GITHUB_REF == refs/heads/main* ]] || [[ $GITHUB_REF == refs/heads/master* ]] || [[ $GITHUB_REF == refs/tags/* ]] || [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
| echo "✓ Image pushed to Docker Hub" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "ℹ️ PR build - image not pushed" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| else | |
| echo "✗ Build failed" >> $GITHUB_STEP_SUMMARY | |
| fi |