Major Updates: - Rewrote all docs in beginner-friendly 'ELI5' language - Created docs index with user journey navigation - Added complete getting-started guide for novice users - Set up GitHub Container Registry (GHCR) automation - Configured GitHub Pages deployment for documentation Documentation: - docs/index.md - Central navigation hub - docs/getting-started.md - Step-by-step beginner guide - docs/github-setup.md - CI/CD setup instructions - README.md - Complete rewrite in accessible language - CONTRIBUTING.md - Contributor guidelines - Multiple comprehensive API and schema docs CI/CD Workflows: - .github/workflows/docker-build.yml - Multi-platform builds to GHCR - .github/workflows/docs.yml - Automated docs deployment to Pages - Supports main (latest), development (dev), and version tags - Automated testing of built images - Beautiful documentation site with dark theme Benefits: - Zero barrier to entry for new users - Automated Docker builds (AMD64 + ARM64) - Professional documentation site - No Docker Hub account needed (uses GHCR) - Complete CI/CD pipeline All 7 implementation phases complete - project is production ready!
170 lines
6.2 KiB
YAML
170 lines
6.2 KiB
YAML
name: Build and Push Docker Images
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main # Pushes to main → tags as "latest"
|
|
- development # Pushes to development → tags as "dev"
|
|
tags:
|
|
- 'v*.*.*' # Version tags (v1.0.0, v1.2.3, etc.) → tags as version number
|
|
workflow_dispatch: # Allows manual trigger from GitHub UI
|
|
|
|
env:
|
|
REGISTRY: ghcr.io
|
|
IMAGE_NAME: ${{ github.repository }}
|
|
|
|
jobs:
|
|
build-and-push:
|
|
name: Build and Push Docker Image
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
steps:
|
|
# Step 1: Download the code
|
|
- name: 📥 Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
# Step 2: Set up QEMU for multi-platform builds (ARM, AMD64, etc.)
|
|
- name: 🔧 Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
|
|
# Step 3: Set up Docker Buildx (advanced Docker builder)
|
|
- name: 🔧 Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
# Step 4: Log in to GitHub Container Registry
|
|
- name: 🔐 Log in to GitHub Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.CPMP_GHCR_TOKEN }}
|
|
|
|
# Step 5: Figure out what tags to use
|
|
- name: 🏷️ Extract metadata (tags, labels)
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
tags: |
|
|
# Tag "latest" for main branch
|
|
type=raw,value=latest,enable={{is_default_branch}}
|
|
# Tag "dev" for development branch
|
|
type=raw,value=dev,enable=${{ github.ref == 'refs/heads/development' }}
|
|
# Tag version numbers from git tags (v1.0.0 → 1.0.0)
|
|
type=semver,pattern={{version}}
|
|
# Tag major.minor from git tags (v1.2.3 → 1.2)
|
|
type=semver,pattern={{major}}.{{minor}}
|
|
# Tag major from git tags (v1.2.3 → 1)
|
|
type=semver,pattern={{major}}
|
|
# Tag with git SHA for tracking (first 7 characters)
|
|
type=sha,prefix=sha-,format=short
|
|
|
|
# Step 6: Build the frontend first
|
|
- name: 🎨 Build frontend
|
|
run: |
|
|
cd frontend
|
|
npm ci
|
|
npm run build
|
|
|
|
# Step 7: Build and push Docker image
|
|
- name: 🐳 Build and push Docker image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: ./Dockerfile
|
|
platforms: linux/amd64,linux/arm64
|
|
push: true
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
# Step 8: Create a summary
|
|
- name: 📋 Create summary
|
|
run: |
|
|
echo "## 🎉 Docker Image Built Successfully!" >> $GITHUB_STEP_SUMMARY
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
echo "### 📦 Image Details" >> $GITHUB_STEP_SUMMARY
|
|
echo "- **Registry**: GitHub Container Registry (ghcr.io)" >> $GITHUB_STEP_SUMMARY
|
|
echo "- **Repository**: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" >> $GITHUB_STEP_SUMMARY
|
|
echo "- **Tags**: " >> $GITHUB_STEP_SUMMARY
|
|
echo '```' >> $GITHUB_STEP_SUMMARY
|
|
echo "${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY
|
|
echo '```' >> $GITHUB_STEP_SUMMARY
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
echo "### 🚀 How to Use" >> $GITHUB_STEP_SUMMARY
|
|
echo '```bash' >> $GITHUB_STEP_SUMMARY
|
|
echo "docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" >> $GITHUB_STEP_SUMMARY
|
|
echo "docker run -d -p 8080:8080 -v caddy_data:/app/data ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" >> $GITHUB_STEP_SUMMARY
|
|
echo '```' >> $GITHUB_STEP_SUMMARY
|
|
|
|
test-image:
|
|
name: Test Docker Image
|
|
needs: build-and-push
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
# Step 1: Figure out which tag to test
|
|
- name: 🏷️ Determine image tag
|
|
id: tag
|
|
run: |
|
|
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
|
|
echo "tag=latest" >> $GITHUB_OUTPUT
|
|
elif [[ "${{ github.ref }}" == "refs/heads/development" ]]; then
|
|
echo "tag=dev" >> $GITHUB_OUTPUT
|
|
elif [[ "${{ github.ref }}" == refs/tags/v* ]]; then
|
|
echo "tag=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "tag=sha-$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
# Step 2: Pull the image we just built
|
|
- name: 📥 Pull Docker image
|
|
run: docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.tag }}
|
|
|
|
# Step 3: Start the container
|
|
- name: 🚀 Run container
|
|
run: |
|
|
docker run -d \
|
|
--name test-container \
|
|
-p 8080:8080 \
|
|
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.tag }}
|
|
|
|
# Step 4: Wait for it to start
|
|
- name: ⏳ Wait for container to be ready
|
|
run: sleep 10
|
|
|
|
# Step 5: Check if the health endpoint works
|
|
- name: 🏥 Test health endpoint
|
|
run: |
|
|
response=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/api/v1/health)
|
|
if [ $response -eq 200 ]; then
|
|
echo "✅ Health check passed!"
|
|
else
|
|
echo "❌ Health check failed with status $response"
|
|
docker logs test-container
|
|
exit 1
|
|
fi
|
|
|
|
# Step 6: Check the logs for errors
|
|
- name: 📋 Check container logs
|
|
if: always()
|
|
run: docker logs test-container
|
|
|
|
# Step 7: Clean up
|
|
- name: 🧹 Stop container
|
|
if: always()
|
|
run: docker stop test-container && docker rm test-container
|
|
|
|
# Step 8: Summary
|
|
- name: 📋 Create test summary
|
|
if: always()
|
|
run: |
|
|
echo "## 🧪 Docker Image Test Results" >> $GITHUB_STEP_SUMMARY
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
echo "- **Image**: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.tag }}" >> $GITHUB_STEP_SUMMARY
|
|
echo "- **Health Check**: ${{ job.status == 'success' && '✅ Passed' || '❌ Failed' }}" >> $GITHUB_STEP_SUMMARY
|