Skip to content

Merge pull request #8 from VirtualFlyBrain/site/search-palette #61

Merge pull request #8 from VirtualFlyBrain/site/search-palette

Merge pull request #8 from VirtualFlyBrain/site/search-palette #61

name: Docker Notebooks 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-notebooks
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: Build Docker image
run: |
docker build . \
--file Dockerfile \
--tag ${DOCKER_IMAGE}:${{ steps.version.outputs.version }} \
--tag ${DOCKER_IMAGE}:latest
- name: Run tests (build verification)
run: |
# Verify the build succeeded by checking the image exists
docker images ${DOCKER_IMAGE} --format "{{.Tag}}"
- name: Login to Docker Hub
if: success() && (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: Push to Docker Hub
if: success() && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch')
run: |
docker push ${DOCKER_IMAGE}:${{ steps.version.outputs.version }}
docker push ${DOCKER_IMAGE}:latest
echo "Pushed ${DOCKER_IMAGE}:${{ steps.version.outputs.version }}"
echo "Pushed ${DOCKER_IMAGE}:latest"
- 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