Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub action for automatic multiarch Docker build #1613

Merged
merged 9 commits into from
Jan 18, 2021
73 changes: 73 additions & 0 deletions .github/workflows/docker-build-and-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Based on https://github.com/docker/build-push-action

name: "Docker Multiarch Build & Push"

on:
release:
# types: [published]
branches: [master]

env:
DOCKER_HUB_USER: neilalexander

jobs:
BuildAndPush:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Get release tag
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ env.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_TOKEN }}
-
name: Build temporary (builder) image
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we calling this a temporary builder image?

Copy link
Contributor Author

@TR-SLimey TR-SLimey Dec 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I've gathered, that's the image which contains the go toolchain and which builds Dendrite, and only the binaries get copied to the actual monolith and polylith images (to save space I believe - Neil mentioned this somewhere), while this image is just discarded, hence it is temporary and a builder. That's mostly just from a quick glance at the Dockerfiles though so I may be wrong.

EDIT: Having checked, I also can't find the dendrite image in matrixdotorg's docker repo (only the -monolith and -polylith ones) so it does indeed seem temporary.

EDIT 2: As for testing, I think the easiest way is to just (1) fork Dendrite, (2) paste this into the correct file replacing matrixdotorg with a test user, (3) create a token for the test user, (4) create a dummy release.

Copy link
Member

@anoadragon453 anoadragon453 Dec 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool OK, and thanks for the info. Do you want to try that testing strategy? Otherwise I can do so sometime tomorrow possibly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've done those tests already on my fork ( I'm nowhere near confident enough to open a PR without testing :P ), and it seemed to work pretty well, but I think it might be good for you to test also, to avoid "works on my end" kinds of bugs :P

id: docker_build_temporary
uses: docker/build-push-action@v2
with:
context: .
file: ./build/docker/Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: false
tags: ${{ env.DOCKER_HUB_USER }}/dendrite:latest
-
name: Build monolith image
id: docker_build_monolith
uses: docker/build-push-action@v2
with:
context: .
file: ./build/docker/Dockerfile.monolith
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
tags: |
${{ env.DOCKER_HUB_USER }}/dendrite-monolith:latest
${{ env.DOCKER_HUB_USER }}/dendrite-monolith:${{ env.RELEASE_VERSION }}
-
name: Build polylith image
id: docker_build_polylith
uses: docker/build-push-action@v2
with:
context: .
file: ./build/docker/Dockerfile.polylith
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
tags: |
${{ env.DOCKER_HUB_USER }}/dendrite-polylith:latest
${{ env.DOCKER_HUB_USER }}/dendrite-polylith:${{ env.RELEASE_VERSION }}
-
name: Image digest
run: |
echo Monolith ( ${{ env.RELEASE_VERSION }} ) image digest - ${{ steps.docker_build_monolith.outputs.digest }}
echo Polylith ( ${{ env.RELEASE_VERSION }} ) image digest - ${{ steps.docker_build_polylith.outputs.digest }}