Both builds in the same job shared the same docker buildx instance, causing the backend image to be incorrectly tagged with the frontend image. Separate jobs get isolated buildx instances and separate build caches. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
153 lines
5.4 KiB
YAML
153 lines
5.4 KiB
YAML
name: Build and Push Docker Image to Gitea
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- develop
|
|
tags:
|
|
- 'v*.*.*'
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
workflow_dispatch:
|
|
inputs:
|
|
tag:
|
|
description: 'Custom tag for the image'
|
|
required: false
|
|
default: 'manual'
|
|
|
|
env:
|
|
REGISTRY: dev.pivoine.art
|
|
IMAGE_NAME: valknar/sexy
|
|
BACKEND_IMAGE_NAME: valknar/sexy-backend
|
|
|
|
jobs:
|
|
build-frontend:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
with:
|
|
platforms: linux/amd64
|
|
|
|
- name: Log in to Gitea Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ gitea.actor }}
|
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
|
|
- name: Extract metadata (tags, labels)
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
tags: |
|
|
type=raw,value=latest,enable={{is_default_branch}}
|
|
type=ref,event=branch
|
|
type=ref,event=pr
|
|
type=semver,pattern={{version}}
|
|
type=semver,pattern={{major}}.{{minor}}
|
|
type=semver,pattern={{major}}
|
|
type=sha,prefix={{branch}}-
|
|
type=raw,value=${{ gitea.event.inputs.tag }},enable=${{ gitea.event_name == 'workflow_dispatch' }}
|
|
labels: |
|
|
org.opencontainers.image.title=sexy.pivoine.art
|
|
org.opencontainers.image.description=Adult content platform frontend (SvelteKit)
|
|
org.opencontainers.image.vendor=valknar
|
|
org.opencontainers.image.source=https://dev.pivoine.art/${{ gitea.repository }}
|
|
|
|
- name: Build and push frontend Docker image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
dockerfile: Dockerfile
|
|
platforms: linux/amd64
|
|
push: ${{ gitea.event_name != 'pull_request' }}
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache
|
|
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache,mode=max
|
|
build-args: |
|
|
NODE_ENV=production
|
|
CI=true
|
|
|
|
- name: Generate image digest
|
|
if: gitea.event_name != 'pull_request'
|
|
run: |
|
|
echo "### Frontend Image Published :rocket:" >> $GITEA_STEP_SUMMARY
|
|
echo "" >> $GITEA_STEP_SUMMARY
|
|
echo "**Registry:** \`${{ env.REGISTRY }}\`" >> $GITEA_STEP_SUMMARY
|
|
echo "\`\`\`" >> $GITEA_STEP_SUMMARY
|
|
echo "${{ steps.meta.outputs.tags }}" >> $GITEA_STEP_SUMMARY
|
|
echo "\`\`\`" >> $GITEA_STEP_SUMMARY
|
|
|
|
build-backend:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
with:
|
|
platforms: linux/amd64
|
|
|
|
- name: Log in to Gitea Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ gitea.actor }}
|
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
|
|
- name: Extract metadata for backend image
|
|
id: meta-backend
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ${{ env.REGISTRY }}/${{ env.BACKEND_IMAGE_NAME }}
|
|
tags: |
|
|
type=raw,value=latest,enable={{is_default_branch}}
|
|
type=ref,event=branch
|
|
type=ref,event=pr
|
|
type=semver,pattern={{version}}
|
|
type=semver,pattern={{major}}.{{minor}}
|
|
type=semver,pattern={{major}}
|
|
type=sha,prefix={{branch}}-
|
|
type=raw,value=${{ gitea.event.inputs.tag }},enable=${{ gitea.event_name == 'workflow_dispatch' }}
|
|
labels: |
|
|
org.opencontainers.image.title=sexy.pivoine.art backend
|
|
org.opencontainers.image.description=GraphQL backend for sexy.pivoine.art (Fastify + Drizzle + Pothos)
|
|
org.opencontainers.image.vendor=valknar
|
|
org.opencontainers.image.source=https://dev.pivoine.art/${{ gitea.repository }}
|
|
|
|
- name: Build and push backend Docker image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
dockerfile: Dockerfile.backend
|
|
platforms: linux/amd64
|
|
push: ${{ gitea.event_name != 'pull_request' }}
|
|
tags: ${{ steps.meta-backend.outputs.tags }}
|
|
labels: ${{ steps.meta-backend.outputs.labels }}
|
|
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.BACKEND_IMAGE_NAME }}:buildcache
|
|
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.BACKEND_IMAGE_NAME }}:buildcache,mode=max
|
|
build-args: |
|
|
NODE_ENV=production
|
|
CI=true
|
|
|
|
- name: Generate image digest
|
|
if: gitea.event_name != 'pull_request'
|
|
run: |
|
|
echo "### Backend Image Published :rocket:" >> $GITEA_STEP_SUMMARY
|
|
echo "" >> $GITEA_STEP_SUMMARY
|
|
echo "**Registry:** \`${{ env.REGISTRY }}\`" >> $GITEA_STEP_SUMMARY
|
|
echo "\`\`\`" >> $GITEA_STEP_SUMMARY
|
|
echo "${{ steps.meta-backend.outputs.tags }}" >> $GITEA_STEP_SUMMARY
|
|
echo "\`\`\`" >> $GITEA_STEP_SUMMARY
|