name: Build and Publish Docker Image
on:
push:
branches: [main]
tags:
- 'v*'
paths-ignore:
- '**.md'
- '.github/ISSUE_TEMPLATE/**'
- '.gitignore'
pull_request:
branches: [main]
paths-ignore:
- '**.md'
- '.github/ISSUE_TEMPLATE/**'
- '.gitignore'
jobs:
build-and-push:
name: Build and Push Docker Image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract version from pyproject.toml
id: version
run: |
VERSION=$(python3 -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
echo "version=${VERSION}" >> $GITHUB_OUTPUT
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
pab1it0/chess-mcp
ghcr.io/pab1it0/chess-mcp
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha,format=long
type=raw,value=latest,enable={{is_default_branch}}
labels: |
org.opencontainers.image.title=Chess.com API MCP Server
org.opencontainers.image.description=Model Context Protocol server for Chess.com API integration
org.opencontainers.image.version=${{ steps.version.outputs.version }}
- name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ steps.version.outputs.version }}
cache-from: type=registry,ref=pab1it0/chess-mcp:latest
cache-to: type=inline
platforms: linux/amd64,linux/arm64