2023-09-24 11:43:30 +00:00
|
|
|
name: Build and push to registry
|
2022-12-01 14:34:41 +01:00
|
|
|
|
|
|
|
on:
|
|
|
|
push:
|
2023-09-24 11:43:30 +00:00
|
|
|
branches: [ "main", "dev" ]
|
|
|
|
tags: [ "v*.*.*" ]
|
|
|
|
pull_request:
|
|
|
|
branches: [ "main", "dev" ]
|
|
|
|
workflow_dispatch:
|
|
|
|
|
2023-09-25 17:30:23 +02:00
|
|
|
permissions:
|
|
|
|
packages: write
|
|
|
|
contents: read
|
|
|
|
|
2022-12-01 14:34:41 +01:00
|
|
|
jobs:
|
|
|
|
build-and-push:
|
2023-09-24 11:43:30 +00:00
|
|
|
name: Build Docker image and push to registry
|
2022-12-01 14:34:41 +01:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- name: Checkout code
|
|
|
|
uses: actions/checkout@v3
|
2023-09-24 11:43:30 +00:00
|
|
|
|
2022-12-01 14:34:41 +01:00
|
|
|
- name: Set up Docker buildx
|
|
|
|
id: buildx
|
|
|
|
uses: docker/setup-buildx-action@v2
|
2023-09-24 11:43:30 +00:00
|
|
|
|
|
|
|
- name: Login to GitHub's container registry
|
|
|
|
if: github.event_name != 'pull_request'
|
|
|
|
uses: docker/login-action@v2
|
|
|
|
with:
|
|
|
|
registry: ghcr.io
|
|
|
|
username: ${{ github.repository_owner }}
|
|
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
|
2023-09-25 19:23:24 +02:00
|
|
|
- uses: Entepotenz/change-string-case-action-min-dependencies@v1 # https://github.com/orgs/community/discussions/10553
|
2023-09-25 19:17:26 +02:00
|
|
|
id: repo-uri-string
|
|
|
|
with:
|
|
|
|
string: ghcr.io/${{ github.repository }}
|
|
|
|
|
2023-09-24 11:43:30 +00:00
|
|
|
- name: Generate image metadata
|
2023-09-25 19:17:26 +02:00
|
|
|
id: docker-meta # used in next step
|
2023-09-24 11:43:30 +00:00
|
|
|
uses: docker/metadata-action@v5
|
|
|
|
with:
|
|
|
|
# list of Docker images to use as base name for tags
|
2023-09-25 19:17:26 +02:00
|
|
|
images: ${{ steps.repo-uri-string.outputs.lowercase }}
|
2023-09-24 11:43:30 +00:00
|
|
|
# Docker tags based on the following events/attributes
|
|
|
|
tags: |
|
|
|
|
type=raw,value=latest,enable={{is_default_branch}}
|
|
|
|
type=ref,event=branch
|
|
|
|
type=ref,event=pr
|
|
|
|
type=semver,pattern={{version}}
|
|
|
|
type=semver,pattern={{major}}.{{minor}}
|
|
|
|
type=semver,pattern={{major}}
|
|
|
|
type=sha
|
|
|
|
|
2022-12-01 14:34:41 +01:00
|
|
|
- name: Build image and push to registry
|
2023-09-24 11:43:30 +00:00
|
|
|
uses: docker/build-push-action@v5
|
2022-12-01 14:34:41 +01:00
|
|
|
with:
|
|
|
|
context: .
|
2023-09-24 11:43:30 +00:00
|
|
|
platforms: linux/amd64,linux/arm64
|
|
|
|
push: ${{ github.event_name != 'pull_request' }}
|
2023-09-25 19:17:26 +02:00
|
|
|
tags: ${{ steps.docker-meta.outputs.tags }}
|
|
|
|
labels: ${{ steps.docker-meta.outputs.labels }}
|
2023-09-24 11:43:30 +00:00
|
|
|
# Some basic caching of the layers...
|
2023-09-25 19:17:26 +02:00
|
|
|
cache-from: ${{ steps.repo-uri-string.outputs.lowercase }}:latest-cache
|
|
|
|
cache-to: ${{ steps.repo-uri-string.outputs.lowercase }}:latest-cache
|