1
Fork 0

Add back docker push conditions to build action

This commit is contained in:
viktorstrate 2021-03-29 12:36:14 +02:00
parent 804b4576ec
commit 1ba62ab03a
No known key found for this signature in database
GPG Key ID: 3F855605109C1E8A
1 changed files with 18 additions and 15 deletions

View File

@ -7,7 +7,7 @@ on:
branches: master branches: master
tags: tags:
- v* - v*
env: env:
DOCKER_USERNAME: viktorstrate DOCKER_USERNAME: viktorstrate
DOCKER_IMAGE: viktorstrate/photoview DOCKER_IMAGE: viktorstrate/photoview
@ -17,7 +17,7 @@ jobs:
build: build:
name: Build Docker Image name: Build Docker Image
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
strategy: strategy:
matrix: matrix:
target_platform: target_platform:
@ -25,7 +25,7 @@ jobs:
- "linux/arm64" - "linux/arm64"
- "linux/arm/v7" - "linux/arm/v7"
- "linux/arm/v6" - "linux/arm/v6"
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
@ -51,15 +51,15 @@ jobs:
id: prepare id: prepare
run: | run: |
DOCKER_PLATFORMS=${{ matrix.target_platform }} DOCKER_PLATFORMS=${{ matrix.target_platform }}
VERSION=edge VERSION=edge
if [[ $GITHUB_REF == refs/tags/* ]]; then if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/v} VERSION=${GITHUB_REF#refs/tags/v}
fi fi
OUTPUT_PLATFORM=$(echo ${{ matrix.target_platform }} | sed 's/\//-/g') OUTPUT_PLATFORM=$(echo ${{ matrix.target_platform }} | sed 's/\//-/g')
echo ::set-output name=output_platform::${OUTPUT_PLATFORM} echo ::set-output name=output_platform::${OUTPUT_PLATFORM}
TAG="--tag ${DOCKER_IMAGE}:${OUTPUT_PLATFORM}-${GITHUB_SHA::8}" TAG="--tag ${DOCKER_IMAGE}:${OUTPUT_PLATFORM}-${GITHUB_SHA::8}"
echo ::set-output name=docker_username::${DOCKER_USERNAME} echo ::set-output name=docker_username::${DOCKER_USERNAME}
@ -77,16 +77,19 @@ jobs:
- name: Docker Build - name: Docker Build
run: | run: |
docker buildx build --output "type=image,push=false" ${{ steps.prepare.outputs.buildx_args }} docker buildx build --output "type=image,push=false" ${{ steps.prepare.outputs.buildx_args }}
- name: Docker Login - name: Docker Login
if: success() && github.event_name != 'pull_request' && github.repository == 'photoview/photoview'
run: | run: |
echo "${DOCKER_PASSWORD}" | docker login --username "${{ steps.prepare.outputs.docker_username }}" --password-stdin echo "${DOCKER_PASSWORD}" | docker login --username "${{ steps.prepare.outputs.docker_username }}" --password-stdin
- name: Push to Docker Hub - name: Push to Docker Hub
if: success() && github.event_name != 'pull_request' && github.repository == 'photoview/photoview'
run: | run: |
docker buildx build --output "type=image,push=true" ${{ steps.prepare.outputs.buildx_args }} docker buildx build --output "type=image,push=true" ${{ steps.prepare.outputs.buildx_args }}
- name: Clear - name: Clear
if: always() && github.event_name != 'pull_request' && github.repository == 'photoview/photoview'
run: | run: |
rm -f ${HOME}/.docker/config.json rm -f ${HOME}/.docker/config.json
@ -94,34 +97,34 @@ jobs:
name: Combine Docker Images name: Combine Docker Images
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
if: github.event_name != 'pull_request' && github.repository == 'photoview/photoview' if: github.event_name != 'pull_request' && github.repository == 'photoview/photoview'
needs: [build] needs: [build]
steps: steps:
- name: Docker Login - name: Docker Login
run: | run: |
echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin
- name: Create Manifests - name: Create Manifests
run: | run: |
DOCKER_IMAGES="${DOCKER_IMAGE}:linux-amd64-${GITHUB_SHA::8}" DOCKER_IMAGES="${DOCKER_IMAGE}:linux-amd64-${GITHUB_SHA::8}"
DOCKER_IMAGES="${DOCKER_IMAGES} ${DOCKER_IMAGE}:linux-arm64-${GITHUB_SHA::8}" DOCKER_IMAGES="${DOCKER_IMAGES} ${DOCKER_IMAGE}:linux-arm64-${GITHUB_SHA::8}"
DOCKER_IMAGES="${DOCKER_IMAGES} ${DOCKER_IMAGE}:linux-arm-v7-${GITHUB_SHA::8}" DOCKER_IMAGES="${DOCKER_IMAGES} ${DOCKER_IMAGE}:linux-arm-v7-${GITHUB_SHA::8}"
DOCKER_IMAGES="${DOCKER_IMAGES} ${DOCKER_IMAGE}:linux-arm-v6-${GITHUB_SHA::8}" DOCKER_IMAGES="${DOCKER_IMAGES} ${DOCKER_IMAGE}:linux-arm-v6-${GITHUB_SHA::8}"
VERSION=edge VERSION=edge
if [[ $GITHUB_REF == refs/tags/* ]]; then if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/v} VERSION=${GITHUB_REF#refs/tags/v}
fi fi
TAGS=("${VERSION}") TAGS=("${VERSION}")
if [[ $VERSION =~ ^(([0-9]{1,3})\.[0-9]{1,3})\.[0-9]{1,3}$ ]]; then if [[ $VERSION =~ ^(([0-9]{1,3})\.[0-9]{1,3})\.[0-9]{1,3}$ ]]; then
VERSION_MINOR=${BASH_REMATCH[1]} VERSION_MINOR=${BASH_REMATCH[1]}
VERSION_MAJOR=${BASH_REMATCH[2]} VERSION_MAJOR=${BASH_REMATCH[2]}
TAGS+=("${VERSION_MAJOR}", "${VERSION_MINOR}") TAGS+=("${VERSION_MAJOR}", "${VERSION_MINOR}")
fi fi
for TAG in ${TAGS[*]}; do for TAG in ${TAGS[*]}; do
echo "Creating tag: ${TAG}" echo "Creating tag: ${TAG}"
docker manifest create ${DOCKER_IMAGE}:${TAG} ${DOCKER_IMAGES} docker manifest create ${DOCKER_IMAGE}:${TAG} ${DOCKER_IMAGES}