publish-docker-image.yml•2.75 kB
name: Publish docker image
on:
push:
branches:
- main
tags:
- 'v*.*.*'
pull_request:
branches:
- main
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push-image:
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
# Adds support for building multi-platform images
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0
- name: Log in to the Container registry
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Builds metadata for our docker image.
# Image name: railsware/coupler-io-mcp-server
# Tags:
# | Event | Ref | Docker Tags |
# |-----------------|-------------------------------|----------------------|
# | `pull_request` | `refs/pull/2/merge` | `pr-2` |
# | `push` | `refs/heads/main` | `edge` |
# | `push tag` | `refs/tags/v1.2.3` | `1.2.3`, `latest` |
# | `push tag` | `refs/tags/v2.0.8-beta.67` | `2.0.8-beta.67` |
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha
type=edge,branch=main
type=ref,event=pr
type=semver,pattern={{version}}
- name: Build and push Docker image
id: push
uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 # v6.16.0
with:
context: .
file: docker/Dockerfile
build-args: |
APP_VERSION=${{ github.sha }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
# We're getting unknown/unknown OS/Arch build without this
# https://github.com/docker/build-push-action/issues/820
provenance: false
# See https://docs.docker.com/build/ci/github-actions/cache/#github-cache
cache-from: type=gha
cache-to: type=gha,mode=max