Skip to content
This repository was archived by the owner on Feb 24, 2021. It is now read-only.

Commit 6207dc4

Browse files
authored
tidy up the docker build (#769)
1 parent e4f9803 commit 6207dc4

File tree

1 file changed

+29
-43
lines changed

1 file changed

+29
-43
lines changed

.github/workflows/dockerbuild.yml

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,51 +14,37 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- uses: actions/checkout@v2
17-
- uses: crazy-max/ghaction-docker-buildx@v3
18-
19-
- name: Prepare
20-
id: prepare
21-
run: |
22-
DOCKER_IMAGE=robertslando/zwave2mqtt
23-
DOCKER_PLATFORMS=linux/arm64,linux/amd64,linux/arm/v6,linux/arm/v7,linux/386
24-
25-
echo ::set-output name=docker_image::${DOCKER_IMAGE}
26-
echo ::set-output name=docker_platforms::${DOCKER_PLATFORMS} \
27-
28-
- name: Just build on PR
29-
if: ${{ github.event_name == 'pull_request' }}
30-
run: |
31-
docker buildx build \
32-
-f docker/Dockerfile \
33-
--platform ${{ steps.prepare.outputs.docker_platforms }} \
34-
-t ${{ steps.prepare.outputs.docker_image }}:dev \
35-
.
3617

18+
- uses: docker/setup-buildx-action@v1
19+
- uses: docker/setup-qemu-action@v1
3720
- name: Login to dockerhub
3821
if: ${{ github.event_name != 'pull_request' }}
39-
run: |
40-
docker login --username $DOCKER_USERNAME --password $DOCKER_PASSWORD
41-
env:
42-
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
43-
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
22+
uses: docker/login-action@v1
23+
with:
24+
username: ${{ secrets.DOCKER_USERNAME }}
25+
password: ${{ secrets.DOCKER_PASSWORD }}
4426

45-
- name: Dev
46-
if: ${{ github.ref == 'refs/heads/master'}}
47-
run: |
48-
docker buildx build \
49-
-f docker/Dockerfile \
50-
--platform ${{ steps.prepare.outputs.docker_platforms }} \
51-
-t ${{ steps.prepare.outputs.docker_image }}:dev \
52-
--push \
53-
.
54-
55-
- name: Latest & tag
56-
if: ${{ github.event_name == 'release' }}
27+
- name: Prepare
5728
run: |
58-
docker buildx build \
59-
-f docker/Dockerfile \
60-
--platform ${{ steps.prepare.outputs.docker_platforms }} \
61-
-t ${{ steps.prepare.outputs.docker_image }}:$(echo ${GITHUB_REF} | sed "s/refs\/tags\/v//") \
62-
-t ${{ steps.prepare.outputs.docker_image }}:latest \
63-
--push \
64-
.
29+
DOCKER_REPO=robertslando/zwave2mqtt
30+
if [ "$GITHUB_REF" == "refs/heads/master" ]; then
31+
TAGS="${DOCKER_REPO}:dev\n"
32+
fi
33+
if [ "$GITHUB_EVENT_NAME" == "release" ]; then
34+
TAGS="${TAGS}${DOCKER_REPO}:latest\n"
35+
TAGS="${TAGS}${DOCKER_REPO}:$(echo ${GITHUB_REF} | sed "s/refs\/tags\/v//")\n"
36+
fi
37+
38+
TAGS="${TAGS}${DOCKER_REPO}:sha-${GITHUB_SHA}"
39+
40+
echo TAGS="${TAGS}" >> $GITHUB_ENV
41+
echo DOCKER_REPO="${DOCKER_REPO}" >> $GITHUB_ENV
42+
43+
- name: build+push
44+
uses: docker/build-push-action@v2
45+
with:
46+
cache-from: type=registry,ref=${{ env.DOCKER_REPO }}:sha-${{ env.GITHUB_SHA }}
47+
platforms: linux/arm64,linux/amd64,linux/arm/v6,linux/arm/v7,linux/386
48+
file: docker/Dockerfile
49+
push: ${{ github.event_name != 'pull_request' }}
50+
tags: ${{ env.TAGS }}

0 commit comments

Comments
 (0)