Build and Publish Docker Images #3
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: Build and Publish Docker Images | |
on: | |
push: | |
tags: | |
- v* | |
workflow_dispatch: | |
env: | |
PACKAGE: ${{ vars.PACKAGE || github.event.repository.name }} | |
ACTOR: ${{ vars.ORGANISATION || github.actor }} | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Check if Registry details are available | |
env: | |
REGISTRY_URL: ${{ secrets.FORGE_REGISTRY_URL }} | |
if: ${{ env.REGISTRY_URL }} | |
run: echo "Registry url is available. Continuing..." | |
- name: Checkout | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Docker metadata | |
id: meta | |
uses: docker/metadata-action@v5 | |
env: | |
FORGE_REGISTRY_URL: ${{ secrets.FORGE_REGISTRY_URL }} | |
with: | |
images: | | |
name=${{ env.FORGE_REGISTRY_URL }}/${{ env.ACTOR }}/${{ env.PACKAGE }} | |
tags: | | |
type=semver,pattern=v{{version}} | |
type=semver,pattern=v{{major}} | |
type=semver,pattern=v{{major}}.{{minor}} | |
type=semver,pattern=v{{major}}.{{minor}}.{{patch}} | |
type=sha | |
labels: | | |
org.opencontainers.image.authors=${{ vars.MY_NAME || env.ACTOR }} <${{ vars.MY_EMAIL }}> | |
annotations: | | |
org.opencontainers.image.authors=${{ vars.MY_NAME || env.ACTOR }} <${{ vars.MY_EMAIL }}> | |
- name: Login to Forge registry | |
uses: docker/login-action@v3 | |
env: | |
FORGE_REGISTRY_URL: ${{ secrets.FORGE_REGISTRY_URL }} | |
if: ${{ env.FORGE_REGISTRY_URL }} | |
id: login-forge | |
with: | |
registry: ${{ env.FORGE_REGISTRY_URL }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.FORGE_REGISTRY_PAT || secrets.GITHUB_TOKEN }} | |
- name: Build and push to Forge | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
builder: ${{ steps.buildx.outputs.name }} | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
annotations: ${{ steps.meta.outputs.annotations }} |