Migrate build to build-push-action@v2

This commit is contained in:
Xiaonan Shen 2020-11-19 18:41:16 -08:00
parent 539fa59e63
commit b0ccfe82cb
2 changed files with 33 additions and 31 deletions

View File

@ -14,9 +14,11 @@ on:
- build/entrypoint.sh
- build/gpgparams
- build/VERSION
pull_request:
env:
DOCKER_REPO: shenxn/protonmail-bridge
DOCKER_REPO_DEV: shenxn/protonmail-bridge-dev
jobs:
build:
@ -24,10 +26,34 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@master
- name: Set up Docker buildx
uses: crazy-max/ghaction-docker-buildx@v2
- name: Build image
run: bash build/build-docker.sh
env:
DOCKER_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
- name: Set version
id: version
run: echo "::set-output name=version::`cat build/VERSION`"
- name: Set repo
id: repo
run: if [[ $GITHUB_REF == "refs/heads/master" ]]; then echo "::set-output name=repo::${DOCKER_REPO}"; else echo "::set-output name=repo::${DOCKER_REPO_DEV}"; fi
- name: Docker meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
with:
images: ${{ steps.repo.outputs.repo }}
- 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
if: ${{ github.event_name != 'pull_request' }}
with:
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- uses: docker/build-push-action@v2
with:
context: ./build
file: ./build/Dockerfile
platforms: linux/amd64,linux/arm64/v8,linux/arm/v7
tags: |
${{ steps.repo.outputs.repo }}:build
${{ steps.repo.outputs.repo }}:${{ steps.version.outputs.version }}-build
labels: ${{ steps.docker_meta.outputs.labels }}
push: ${{ github.event_name != 'pull_request' }}

View File

@ -1,24 +0,0 @@
#!/bin/bash
set -ex
# Enter the right path
SCRIPT=`realpath $0`
SCRIPTPATH=`dirname $SCRIPT`
cd $SCRIPTPATH
# Set docker tag
VERSION=`cat VERSION`
if [[ $GITHUB_REF == "refs/heads/master" ]]; then
TAG_TYPE="build"
TAG_VERSION="${VERSION}-build"
else
TAG_TYPE="build-dev"
TAG_VERSION="${VERSION}-build-dev"
fi
# Docker login
echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin
# Build multiarch and push
docker buildx build $BUILD_ARGS --platform linux/amd64,linux/arm64/v8,linux/arm/v7 -t ${DOCKER_REPO}:${TAG_TYPE} -t ${DOCKER_REPO}:${TAG_VERSION} --push .