Move from Docker Hub builds to GitHub Actions

This allows us to create do a multi-arch build, resulting in
an image which is useful even on low-end IoT devices.
This commit is contained in:
Bojan Čekrlić 2020-01-31 21:07:42 +01:00
parent 0feeccbfc3
commit 1caf4104ba
6 changed files with 101 additions and 8 deletions

26
.github/workflows/master.yml vendored Normal file
View file

@ -0,0 +1,26 @@
name: Docker image
on:
push:
branches: master
jobs:
buildx:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Get release version
run: echo ::set-env name=RELEASE_VERSION::$(echo ${GITHUB_REF:10})
- name: Set up Docker Buildx
id: buildx
uses: crazy-max/ghaction-docker-buildx@v1
with:
version: latest
- name: Build master
env:
DOCKER_USERNAME: 'boky'
DOCKER_PASSWORD: '${{ secrets.DOCKER_ACCESS_TOKEN }}'
PLATFORMS: "linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x"
run: ./build.sh -t boky/postfix --push

22
.github/workflows/pull_request.yml vendored Normal file
View file

@ -0,0 +1,22 @@
name: Validate pull request
on:
pull_request:
branches: master
jobs:
buildx:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Docker Buildx
id: buildx
uses: crazy-max/ghaction-docker-buildx@v1
with:
version: latest
- name: Run Buildx
env:
PLATFORMS: "linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x"
run: ./build.sh -t boky/postfix

24
.github/workflows/tags.yml vendored Normal file
View file

@ -0,0 +1,24 @@
name: Docker tag image
on:
push:
tags: ['*']
jobs:
buildx:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Docker Buildx
id: buildx
uses: crazy-max/ghaction-docker-buildx@v1
with:
version: latest
- name: Build branch / tag
env:
DOCKER_USERNAME: 'boky'
DOCKER_PASSWORD: '${{ secrets.DOCKER_ACCESS_TOKEN }}'
PLATFORMS: "linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x"
run: ./build.sh -t boky/postfix:$(echo ${GITHUB_REF:10}) --push

View file

@ -1,4 +1,4 @@
# docker-postfix
# docker-postfix ![Docker image](https://github.com/bokysan/docker-postfix/workflows/Docker%20image/badge.svg)
Simple postfix relay host for your Docker containers. Based on Alpine Linux.

View file

@ -2,7 +2,7 @@
if [ $# -eq 0 ]; then
echo "No alpine build versions supplied"
echo "example usage: ./push.sh latest 3.10 3.9"
echo "example usage: $0 latest 3.10 3.9"
exit 1
fi
@ -11,10 +11,6 @@ docker login
# build, tag, and push alpine versions supplied as script arguments
base_repo=boky/postfix
for alpine_version in "$@"
do
docker build -t "$base_repo":"$alpine_version" --build-arg=ALPINE_VERSION="$alpine_version" .
docker push "$base_repo":"$alpine_version"
for alpine_version in "$@"; do
$(dirname $0)/build.sh -t "$base_repo" --build-arg=ALPINE_VERSION="$alpine_version"
done

25
build.sh Executable file
View file

@ -0,0 +1,25 @@
#!/usr/bin/env bash
# Do a multistage build
export DOCKER_BUILDKIT=1
export DOCKER_CLI_EXPERIMENTAL=enabled
if ! docker buildx inspect multiarch > /dev/null; then
docker buildx create --name multiarch
fi
docker buildx use multiarch
if [[ "$*" == *--push* ]]; then
if [[ -n "$DOCKER_USERNAME" ]] && [[ -n "$DOCKER_PASSWORD" ]]; then
echo "Logging into docker registry $DOCKER_REGISTRY_URL...."
echo "$DOCKER_PASSWORD" | docker login --username $DOCKER_USERNAME --password-stdin $DOCKER_REGISTRY_URL
fi
fi
if [[ -z "$PLATFORMS" ]]; then
PLATFORMS="linux/amd64,linux/arm64,linux/arm/v7"
fi
docker buildx build --platform $PLATFORMS . $*