Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions .github/workflows/cd-build-image.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: Build & Publish Docker Image

on:
push:
branches: ["dev", "main"]
release:
types: [published]

jobs:
deploy:
if: github.event.release.target_commitish == 'main'
name: Build & Deploy spacedf-backend Docker Image
build:
runs-on: ubuntu-latest

permissions:
Expand All @@ -18,8 +18,8 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.release.tag_name }}
ref: ${{ github.event_name == 'release' && 'main' || github.ref }}

# Enable multi-arch
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand All @@ -36,26 +36,26 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Generate Docker metadata
- name: Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}},value=${{ github.event.release.tag_name }}
type=semver,pattern={{major}}.{{minor}},value=${{ github.event.release.tag_name }}
type=semver,pattern={{major}},value=${{ github.event.release.tag_name }}
- name: Set build variables
id: vars
run: |
if [ "${{ github.event_name }}" = "release" ]; then
VERSION=${{ github.event.release.tag_name }}
VERSION=${VERSION#v}
echo "TAGS=ghcr.io/${{ github.repository }}:${VERSION},ghcr.io/${{ github.repository }}:latest" >> $GITHUB_OUTPUT

elif [ "${GITHUB_REF_NAME}" = "main" ]; then
echo "TAGS=ghcr.io/${{ github.repository }}:prod" >> $GITHUB_OUTPUT

else
echo "TAGS=ghcr.io/${{ github.repository }}:dev" >> $GITHUB_OUTPUT
fi

# Build & Push image
- name: Build & Push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
secrets: |
github_token=${{ secrets.GH_PAT }}
tags: ${{ steps.vars.outputs.TAGS }}