Skip to content

Commit

Permalink
Move from Docker Hub builds to GitHub Actions
Browse files Browse the repository at this point in the history
This allows us to create do a multi-arch build, resulting in
an image which is useful even on low-end IoT devices.
  • Loading branch information
bokysan committed Jan 31, 2020
1 parent 0feeccb commit 1caf410
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 8 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 22 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 24 additions & 0 deletions .github/workflows/tags.yml
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.


Expand Down
10 changes: 3 additions & 7 deletions push.sh → alpine-versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 changes: 25 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -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 . $*

0 comments on commit 1caf410

Please sign in to comment.