name: Docker
on:
push:
branches: [master, main]
tags: ['v*']
pull_request:
branches: [master, main]
release:
types: [published]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
permissions:
contents: read
packages: write
attestations: write
id-token: write
jobs:
build-and-push:
name: Build and Push Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=edge,branch=master
type=edge,branch=main
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Generate artifact attestation
if: github.event_name != 'pull_request'
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
subject-digest: ${{ steps.build-and-push.outputs.digest }}
push-to-registry: true
security-scan:
name: Security Scan Docker Image
runs-on: ubuntu-latest
needs: [build-and-push]
if: github.event_name != 'pull_request'
steps:
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.event_name == 'release' && github.event.release.tag_name || 'edge' }}
format: 'sarif'
output: 'trivy-results.sarif'
- name: Upload Trivy scan results to GitHub Security
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: 'trivy-results.sarif'
test-docker:
name: Test Docker Image
runs-on: ubuntu-latest
needs: [build-and-push]
steps:
- name: Set image tag
id: set-tag
run: |
if [[ "${{ github.event_name }}" == "release" ]]; then
TAG="${{ github.event.release.tag_name }}"
elif [[ "${{ github.ref_name }}" == "master" || "${{ github.ref_name }}" == "main" ]]; then
TAG="edge"
else
TAG="${{ github.ref_name }}"
fi
echo "tag=$TAG" >> $GITHUB_OUTPUT
- name: Test Docker image
run: |
TAG="${{ steps.set-tag.outputs.tag }}"
IMAGE="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$TAG"
# Test that container runs and exits gracefully
echo "Testing Docker image: $IMAGE"
# Test basic functionality
docker run --rm $IMAGE --help || echo "Help command test completed"
# Test that Python imports work
docker run --rm $IMAGE python -c "
from lancedb_mcp import server, embedding_manager
from lancedb_mcp.models import TableConfig, VectorData
print('✓ Docker image imports successful')
"
echo "✅ Docker image tests passed"