name: Build and Push Docker Image
on:
push:
tags: ["v*"]
pull_request:
branches: [main]
env:
REGISTRY: docker.io
IMAGE_NAME: couchbaseecosystem/mcp-server-couchbase
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
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: Log in to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Check if stable release
id: check-stable
if: startsWith(github.ref, 'refs/tags/')
run: |
TAG_NAME="${GITHUB_REF#refs/tags/}"
echo "Checking tag: $TAG_NAME"
# Only match vX.Y.Z format (no suffixes like rc, alpha, beta)
if [[ "$TAG_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "is_stable=true" >> $GITHUB_OUTPUT
echo "This is a STABLE release: $TAG_NAME"
else
echo "is_stable=false" >> $GITHUB_OUTPUT
echo "This is a PRE-RELEASE: $TAG_NAME (will not update 'latest' or major.minor tags)"
fi
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
# Disable automatic 'latest' tag to have explicit control
latest=false
tags: |
# For PRs: tag as pr-<number>
type=ref,event=pr
# For all tags: extract full version without 'v' prefix (e.g., 0.5.2 or 0.5.2rc3)
type=match,pattern=v(.*),group=1
# For stable releases only: extract major.minor (e.g., 0.5 from v0.5.2)
type=match,pattern=v(\d+\.\d+),group=1,enable=${{ steps.check-stable.outputs.is_stable == 'true' }}
# For stable releases only: tag as 'latest'
type=raw,value=latest,enable=${{ steps.check-stable.outputs.is_stable == 'true' }}
- name: Set build timestamp
id: timestamp
run: echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
- name: Build and push Docker image
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 }}
build-args: |
GIT_COMMIT_HASH=${{ github.sha }}
BUILD_DATE=${{ steps.timestamp.outputs.BUILD_DATE }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Update Docker Hub description
if: github.ref_type == 'tag'
uses: peter-evans/dockerhub-description@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: ${{ env.IMAGE_NAME }}
readme-filepath: ./DOCKER.md