spoticord/.github/workflows/build-push.yml

77 lines
2.3 KiB
YAML

name: Build and push to registry
on:
push:
branches: ["main", "dev"]
tags: ["v*.*.*"]
pull_request:
branches: ["main", "dev"]
workflow_dispatch:
permissions:
packages: write
contents: read
jobs:
build-and-push:
name: Build Docker image and push to registry
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Docker buildx
id: buildx
uses: docker/setup-buildx-action@v2
- 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 }}
- uses: Entepotenz/change-string-case-action-min-dependencies@v1 # https://github.com/orgs/community/discussions/10553
id: repo-uri-string
with:
string: ghcr.io/${{ github.repository }}
- name: Generate image metadata
id: docker-meta # used in next step
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: ${{ steps.repo-uri-string.outputs.lowercase }}
# 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
- name: Inject Docker cache
uses: reproducible-containers/buildkit-cache-dance@v3.1.0
with:
cache-map: |
{
"usr-local-cargo-registry": "/usr/local/cargo/registry",
"app-target": "/app/target"
}
- name: Build image and push to registry
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.docker-meta.outputs.tags }}
labels: ${{ steps.docker-meta.outputs.labels }}
# Some basic caching of the layers...
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: false