Skip to content

Commit

Permalink
ci: add docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
torkelrogstad committed Jan 15, 2025
1 parent ee1d3ee commit c3803b4
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/build_docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Build and push Docker image

on:
push:
branches:
- master
workflow_dispatch:
pull_request:

jobs:
# Build and push ALL events. We'll make sure to give the images
# sensible tags, so there's no confusion around what's 'dev' builds
# through PRs, and what's proper 'master' builds.
#
# Official GitHub docs on this: https://docs.github.com/en/actions/use-cases-and-examples/publishing-packages/publishing-docker-images
build-push-docker:
runs-on: ubuntu-latest
# needed to push to GHCR
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Docker meta
id: meta
# https://github.com/docker/metadata-action
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository_owner }}/bitcoin-patched
# generate Docker tags based on the following events/attributes
tags: |
# creates a tag for each push
type=sha,event=push
# creates a tag for each pr
type=ref,event=pr
# set latest tag for default branch
type=raw,value=latest,enable={{is_default_branch}}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

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

- name: Build (and maybe push) Docker image
uses: docker/build-push-action@v6
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
# Caching Docker builds on CI is an eternally
# difficult task. From the official docs:
# "In most cases you want to use the inline cache exporter"
#
# https://docs.docker.com/build/ci/github-actions/cache/#inline-cache
# prettier-ignore
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/bitcoin-patched:latest
cache-to: type=inline

- name: Find existing comment about built images
id: fc
uses: peter-evans/find-comment@v3
if: github.event_name == 'pull_request'
with:
body-includes: "Built Docker"
issue-number: ${{ github.event.pull_request.number }}

- name: Comment on pull request about built images
if: github.event_name == 'pull_request'
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
edit-mode: replace
body: |
Built Docker image(s): ${{ steps.meta.outputs.tags }}

0 comments on commit c3803b4

Please sign in to comment.