Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .github/workflows/build-push-docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Build Docker image and push to GHCR

on:
# Can be triggered manually
workflow_dispatch:
# Runs automatically on pushes (merges) to the branch
push:
branches:
- master

# Allow one concurrent build
concurrency: build-and-push

# Least required permissions
permissions:
contents: read
packages: write

env:
# Has to be in form ghcr.io/USER/REPO_NAME
# github.repository is exactly USER/REPO_NAME part
IMAGE_NAME: ghcr.io/${{ github.repository }}

jobs:
build:
timeout-minutes: 5
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Login to GHCR
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2

- name: Build and push
uses: docker/build-push-action@v3
with:
builder: ${{ steps.buildx.outputs.name }}

# Build options
context: ./
file: ./Dockerfile
tags: ${{ env.IMAGE_NAME }}:latest

# Push the result to the registry
push: true

# Cache layers in the registry
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache,mode=max

# Label to link the resulting package to the current repository
labels: |
org.opencontainers.image.source=${{ github.repositoryUrl }}