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

tidy up the docker build #769

Merged
merged 1 commit into from
Oct 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 29 additions & 43 deletions .github/workflows/dockerbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,51 +14,37 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: crazy-max/ghaction-docker-buildx@v3

- name: Prepare
id: prepare
run: |
DOCKER_IMAGE=robertslando/zwave2mqtt
DOCKER_PLATFORMS=linux/arm64,linux/amd64,linux/arm/v6,linux/arm/v7,linux/386

echo ::set-output name=docker_image::${DOCKER_IMAGE}
echo ::set-output name=docker_platforms::${DOCKER_PLATFORMS} \

- name: Just build on PR
if: ${{ github.event_name == 'pull_request' }}
run: |
docker buildx build \
-f docker/Dockerfile \
--platform ${{ steps.prepare.outputs.docker_platforms }} \
-t ${{ steps.prepare.outputs.docker_image }}:dev \
.

- uses: docker/setup-buildx-action@v1
- uses: docker/setup-qemu-action@v1
- name: Login to dockerhub
if: ${{ github.event_name != 'pull_request' }}
run: |
docker login --username $DOCKER_USERNAME --password $DOCKER_PASSWORD
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Dev
if: ${{ github.ref == 'refs/heads/master'}}
run: |
docker buildx build \
-f docker/Dockerfile \
--platform ${{ steps.prepare.outputs.docker_platforms }} \
-t ${{ steps.prepare.outputs.docker_image }}:dev \
--push \
.

- name: Latest & tag
if: ${{ github.event_name == 'release' }}
- name: Prepare
run: |
docker buildx build \
-f docker/Dockerfile \
--platform ${{ steps.prepare.outputs.docker_platforms }} \
-t ${{ steps.prepare.outputs.docker_image }}:$(echo ${GITHUB_REF} | sed "s/refs\/tags\/v//") \
-t ${{ steps.prepare.outputs.docker_image }}:latest \
--push \
.
DOCKER_REPO=robertslando/zwave2mqtt
if [ "$GITHUB_REF" == "refs/heads/master" ]; then
TAGS="${DOCKER_REPO}:dev\n"
fi
if [ "$GITHUB_EVENT_NAME" == "release" ]; then
TAGS="${TAGS}${DOCKER_REPO}:latest\n"
TAGS="${TAGS}${DOCKER_REPO}:$(echo ${GITHUB_REF} | sed "s/refs\/tags\/v//")\n"
fi

TAGS="${TAGS}${DOCKER_REPO}:sha-${GITHUB_SHA}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New tag?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, sorry forgot to call out

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it used for caching?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, more for allowing someone to use something ahead of a release without opening themselves to a breaking change coming in next time they pull

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And what about the 'just build on pr' part? It will push also pull requests with the format robertslando/zwave2mqtt:sha-<sha>?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only prs on this repo, prs from forks don't get the secret to push

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh missed the if in the login part

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its more that forks don't get access to the secrets, otherwise anyone could just get your dockerhub creds


echo TAGS="${TAGS}" >> $GITHUB_ENV
echo DOCKER_REPO="${DOCKER_REPO}" >> $GITHUB_ENV

- name: build+push
uses: docker/build-push-action@v2
with:
cache-from: type=registry,ref=${{ env.DOCKER_REPO }}:sha-${{ env.GITHUB_SHA }}
platforms: linux/arm64,linux/amd64,linux/arm/v6,linux/arm/v7,linux/386
file: docker/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ env.TAGS }}