Create docker-build-and-push.yml

This commit is contained in:
TR_SLimey 2020-12-03 22:47:08 +00:00 committed by GitHub
parent 1f3a498601
commit 78b2977195
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -0,0 +1,47 @@
name: "Docker Multiarch Build & Push"
on:
push:
branches: [master]
env:
DOCKER_HUB_USER: matrixdotorg
jobs:
BuildAndPush:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up buildx
uses: crazy-max/ghaction-docker-buildx@v1
with:
buildx-version: latest
- name: Log in to registry
run: echo "${{ secrets.DOCKER_TOKEN }}" | docker login -u $(echo "$DOCKER_HUB_USER") --password-stdin
- name: Build and push
run: |
# Build temporary builder image first and then use it to build monolith and polylith images
for suffix in '' 'monolith' 'polylith'; do
# Name of the repo/image
IMAGE_NAME=$DOCKER_HUB_USER/dendrite$(if [ $suffix != "" ]; then echo "-$suffix"; fi)
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Use `latest` insted of `master`
[ "$VERSION" == "master" ] && VERSION=latest
# Ensure the whole tag is lowercase
IMAGE_NAME=$(echo $IMAGE_NAME | tr '[A-Z]' '[a-z]')
echo IMAGE_NAME=$IMAGE_NAME
echo VERSION=$VERSION
docker buildx build --push \
--file build/docker/Dockerfile$(if [ $suffix != "" ]; then echo ".$suffix"; fi) \
--tag $IMAGE_NAME:$VERSION \
--platform linux/amd64,linux/arm/v7,linux/arm64 .
done