Skip to content

Publish container image for API using latest as an image tag #12

Publish container image for API using latest as an image tag

Publish container image for API using latest as an image tag #12

name: Publish container image for API using latest as an image tag
on: workflow_dispatch # run maually
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}-api
jobs:
build-and-publish-image:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
permissions:
contents: read
packages: write
steps:
- name: Check out the repo
uses: actions/checkout@v4
with:
ref: ${{ github.ref }} # This dynamically references the branch you trigger the workflow from
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: .
file: Dockerfile.api
push: true
tags: |
${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max