Rewrite docker workflow. (#994)

* Rewrite docker workflow.

* tidy

* Create 994.misc

Signed-off-by: Will Hunt <will@half-shot.uk>

---------

Signed-off-by: Will Hunt <will@half-shot.uk>
This commit is contained in:
Will Hunt 2024-11-29 09:15:53 +00:00 committed by GitHub
parent 819c089aa4
commit d550077f3e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 85 additions and 103 deletions

View File

@ -1,56 +0,0 @@
# Based on https://github.com/matrix-org/dendrite/blob/master/.github/workflows/docker-hub.yml
name: "Docker Hub - Latest"
on:
push:
paths-ignore:
- changelog.d/**'
pull_request:
branches: [ main ]
paths-ignore:
- changelog.d/**'
merge_group:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
env:
DOCKER_NAMESPACE: halfshot
PLATFORMS: linux/amd64
PLATFORMS_PUSH: linux/amd64,linux/arm64
# Only push if this is main, otherwise we just want to build
PUSH: ${{ github.ref == 'refs/heads/main' }}
jobs:
docker-latest:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to Docker Hub
if: github.ref == 'refs/heads/main'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Build image
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
platforms: ${{ (env.PUSH == 'true' && env.PLATFORMS_PUSH) || env.PLATFORMS }}
push: ${{ env.PUSH }}
tags: |
${{ env.DOCKER_NAMESPACE }}/matrix-hookshot:latest
# arm64 builds OOM without the git fetch setting. c.f.
# https://github.com/rust-lang/cargo/issues/10583
build-args: |
CARGO_NET_GIT_FETCH_WITH_CLI=true

View File

@ -1,47 +0,0 @@
# Based on https://github.com/matrix-org/dendrite/blob/master/.github/workflows/docker-hub.yml
name: "Docker Hub - Release"
on:
release:
types: [published]
env:
DOCKER_NAMESPACE: halfshot
PLATFORMS: linux/amd64,linux/arm64
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
docker-release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Get release tag
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Build image
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
platforms: ${{ env.PLATFORMS }}
push: true
tags: |
${{ env.DOCKER_NAMESPACE }}/matrix-hookshot:${{ env.RELEASE_VERSION }}
# arm64 builds OOM without the git fetch setting. c.f.
# https://github.com/rust-lang/cargo/issues/10583
build-args: |
CARGO_NET_GIT_FETCH_WITH_CLI=true

84
.github/workflows/docker.yml vendored Normal file
View File

@ -0,0 +1,84 @@
# Based on https://github.com/matrix-org/dendrite/blob/master/.github/workflows/docker-hub.yml
name: "Docker"
on:
push:
paths-ignore:
- changelog.d/**'
pull_request:
branches: [ main ]
paths-ignore:
- changelog.d/**'
release:
types: [published]
merge_group:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
env:
DOCKER_NAMESPACE: halfshot
PLATFORMS: linux/amd64
PLATFORMS_PUSH: linux/amd64,linux/arm64
# Only push if this is main, otherwise we just want to build
BUILD_FOR_ALL_PLATFORMS: ${{ github.ref == 'refs/heads/main' }}
jobs:
docker-latest:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Log in to the GitHub Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
tags: |
type=semver,pattern={{version}}
type=ref,event=branch
type=ref,event=pr
type=raw,value=latest,enable={{is_default_branch}}
images: |
${{ env.DOCKER_NAMESPACE }}/matrix-hookshot
ghcr.io/matrix-org/matrix-hookshot
- name: Build and push Docker images
id: push
uses: docker/build-push-action@v6
with:
context: .
# arm64 builds OOM without the git fetch setting. c.f.
# https://github.com/rust-lang/cargo/issues/10583
build-args: |
CARGO_NET_GIT_FETCH_WITH_CLI=true
platforms: ${{ (env.BUILD_FOR_ALL_PLATFORMS == 'true' && env.PLATFORMS_PUSH) || env.PLATFORMS }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

1
changelog.d/994.misc Normal file
View File

@ -0,0 +1 @@
Push Docker images to ghcr.io, and and build an image on each commit.