- Added type=raw,value=main to both API and Nginx image metadata - This will create both SHA tags and :main tags for the default branch - Fixes deployment timeout issues when pulling from GHCR - Also added temporary deployment file using specific SHA
128 lines
No EOL
3.7 KiB
YAML
128 lines
No EOL
3.7 KiB
YAML
name: Build and Push Docker Images
|
|
|
|
on:
|
|
push:
|
|
branches: [ main, develop ]
|
|
tags: [ 'v*' ]
|
|
pull_request:
|
|
branches: [ main ]
|
|
|
|
env:
|
|
REGISTRY: ghcr.io
|
|
IMAGE_NAME: ${{ github.repository }}
|
|
|
|
jobs:
|
|
build-and-push:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '18'
|
|
cache: 'npm'
|
|
cache-dependency-path: |
|
|
client/package-lock.json
|
|
server/package-lock.json
|
|
|
|
- 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 for Docker
|
|
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=sha,prefix=sha-
|
|
type=raw,value=main,enable={{is_default_branch}}
|
|
|
|
- name: Build React client
|
|
working-directory: ./client
|
|
run: |
|
|
npm ci
|
|
npm run build
|
|
|
|
- name: Verify client build
|
|
run: |
|
|
ls -la client/dist/ || echo "No dist directory found"
|
|
if [ -d "client/dist" ]; then
|
|
echo "✅ Client build successful"
|
|
echo "Build contents:"
|
|
find client/dist -type f | head -5
|
|
else
|
|
echo "❌ Client build failed - no dist directory"
|
|
exit 1
|
|
fi
|
|
|
|
- name: Build and push API image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
target: production
|
|
push: ${{ github.event_name != 'pull_request' }}
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
platforms: linux/amd64,linux/arm64
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
- name: Extract metadata for Nginx image
|
|
id: nginx-meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-nginx
|
|
tags: |
|
|
type=ref,event=branch
|
|
type=ref,event=pr
|
|
type=semver,pattern={{version}}
|
|
type=semver,pattern={{major}}.{{minor}}
|
|
type=sha,prefix=sha-
|
|
type=raw,value=main,enable={{is_default_branch}}
|
|
|
|
- name: Build and push Nginx image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
target: nginx-frontend
|
|
push: ${{ github.event_name != 'pull_request' }}
|
|
tags: ${{ steps.nginx-meta.outputs.tags }}
|
|
labels: ${{ steps.nginx-meta.outputs.labels }}
|
|
platforms: linux/amd64,linux/arm64
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
- name: Make package public
|
|
if: github.event_name != 'pull_request'
|
|
run: |
|
|
echo "Setting package visibility to public..."
|
|
# Note: This requires the GITHUB_TOKEN to have package:write permission
|
|
# The package visibility will be set to public automatically for public repos
|
|
|
|
- name: Image build summary
|
|
if: github.event_name != 'pull_request'
|
|
run: |
|
|
echo "✅ Docker image built and pushed successfully!"
|
|
echo "📦 Image tags:"
|
|
echo "${{ steps.meta.outputs.tags }}"
|
|
echo ""
|
|
echo "🚀 Deploy on your Mac Mini with:"
|
|
echo "git pull && ./build-deploy.sh ghcr" |