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
on:
push:
branches:
- main
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 Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
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=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 }}
name: Publish API to GitHub Container Registry
on:
push:
branches:
- main
jobs:
build-and-push-api:
runs-on: ubuntu-latest
# This permission is necessary to allow the workflow to write to GitHub Packages.
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
# This tells Docker where to find your Dockerfile and code
context: ./apps/api
push: true
# This will tag the image with both 'latest' and 'main'
tags: ghcr.io/${{ github.repository }}:latest,ghcr.io/${{ github.repository }}:main