Skip to content

Build and Push Backend Image #80

Build and Push Backend Image

Build and Push Backend Image #80

name: Build and Push Backend Image
on:
push:
branches: [main]
paths:
- "PhantomDave.BankTracking.Api/**"
- "PhantomDave.BankTracking.Data/**"
- "PhantomDave.BankTracking.Library/**"
- "Dockerfile"
- ".github/workflows/build-backend-image.yml"
pull_request:
branches: [main]
paths:
- "PhantomDave.BankTracking.Api/**"
- "PhantomDave.BankTracking.Data/**"
- "PhantomDave.BankTracking.Library/**"
- "Dockerfile"
- ".github/workflows/build-backend-image.yml"
workflow_dispatch:
workflow_run:
workflows: ["Run Project Tests"]
types: [completed]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/backend
jobs:
build-and-push:
name: Build and Push Backend Container
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Log in to GitHub 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
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha,prefix={{branch}}-,enable=${{ github.event_name != 'pull_request' }}
type=ref,event=branch
type=ref,event=pr
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push backend image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}