75 lines
2.1 KiB
YAML
75 lines
2.1 KiB
YAML
# ref: https://docs.docker.com/ci-cd/github-actions/
|
|
# https://blog.oddbit.com/post/2020-09-25-building-multi-architecture-im/
|
|
|
|
name: Docker
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- master
|
|
tags:
|
|
- 'v*'
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Prepare
|
|
id: prepare
|
|
run: |
|
|
DOCKER_IMAGE=${{ secrets.DOCKER_IMAGE }}
|
|
VERSION=latest
|
|
|
|
# If this is git tag, use the tag name as a docker tag
|
|
if [[ $GITHUB_REF == refs/tags/* ]]; then
|
|
VERSION=${GITHUB_REF#refs/tags/v}
|
|
fi
|
|
TAGS="${DOCKER_IMAGE}:${VERSION}"
|
|
|
|
# If the VERSION looks like a version number, assume that
|
|
# this is the most recent version of the image and also
|
|
# tag it 'latest'.
|
|
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
|
|
TAGS="$TAGS,${DOCKER_IMAGE}:latest"
|
|
fi
|
|
|
|
# Set output parameters.
|
|
echo ::set-output name=tags::${TAGS}
|
|
echo ::set-output name=docker_image::${DOCKER_IMAGE}
|
|
|
|
# https://github.com/actions/checkout
|
|
- name: Checkout
|
|
uses: actions/checkout@v2
|
|
|
|
- name: Docker Login
|
|
if: github.event_name != 'pull_request'
|
|
uses: docker/login-action@v1
|
|
with:
|
|
username: ${{ secrets.DOCKER_USERNAME }}
|
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
|
|
|
- name: Set up Docker Buildx
|
|
id: buildx
|
|
uses: docker/setup-buildx-action@v1
|
|
|
|
- name: Environment
|
|
run: |
|
|
echo home=$HOME
|
|
echo git_ref=$GITHUB_REF
|
|
echo git_sha=$GITHUB_SHA
|
|
echo image=${{ steps.prepare.outputs.docker_image }}
|
|
echo tags=${{ steps.prepare.outputs.tags }}
|
|
echo avail_platforms=${{ steps.buildx.outputs.platforms }}
|
|
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v2
|
|
with:
|
|
builder: ${{ steps.buildx.outputs.name }}
|
|
context: .
|
|
file: ./Dockerfile
|
|
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8
|
|
push: true
|
|
tags: ${{ steps.prepare.outputs.tags }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|