Add API publishing to GitHub Container Registry workflow

Updated workflow to publish API Docker image to GitHub Container Registry.
This commit is contained in:
gamvo74 2026-02-22 08:42:55 -05:00 committed by GitHub
parent 04a0358dd6
commit 85fc8b4024
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,55 +1,37 @@
name: Publish to GitHub Container Registry name: Publish API to GitHub Container Registry
on: on:
push: push:
branches: branches:
- main - main
tags:
- 'v*'
pull_request:
branches:
- main
env: jobs:
REGISTRY: ghcr.io build-and-push-api:
IMAGE_NAME: ${{ github.repository }} runs-on: ubuntu-latest
# This permission is necessary to allow the workflow to write to GitHub Packages.
permissions:
contents: read
packages: write
jobs: steps:
build-and-push: - name: Checkout code
runs-on: ubuntu-latest uses: actions/checkout@v3
permissions:
contents: read
packages: write
steps: - name: Log in to GitHub Container Registry
- name: Checkout repository uses: docker/login-action@v2
uses: actions/checkout@v4 with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v2
- name: Log in to Container Registry - name: Build and push Docker image
uses: docker/login-action@v3 uses: docker/build-push-action@v4
with: with:
registry: ${{ env.REGISTRY }} # This tells Docker where to find your Dockerfile and code
username: ${{ github.actor }} context: ./apps/api
password: ${{ secrets.GITHUB_TOKEN }} push: true
# This will tag the image with both 'latest' and 'main'
- name: Extract metadata tags: ghcr.io/${{ github.repository }}:latest,ghcr.io/${{ github.repository }}:main
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}