From a71086c10de1726629bd0f5cfa0f9514e3cad023 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Mon, 13 Dec 2021 09:20:03 -0500 Subject: [PATCH] Build and deploy docker image on master commit or tag Automate docker image deployment to dockerhub using repository triggers --- .github/workflows/dockerhub.yml | 48 +++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .github/workflows/dockerhub.yml diff --git a/.github/workflows/dockerhub.yml b/.github/workflows/dockerhub.yml new file mode 100644 index 0000000..5a1d54f --- /dev/null +++ b/.github/workflows/dockerhub.yml @@ -0,0 +1,48 @@ +name: Publish Docker image to Dockerhub + +on: + push: + branches: + - 'master' + tags: + - '*.*.*' + # don't trigger if just updating docs + paths-ignore: + - '**.md' + +jobs: + push_to_registry: + name: Push Docker image to Docker Hub + runs-on: ubuntu-latest + steps: + - name: Check out the repo + uses: actions/checkout@v2 + + - name: Log in to Docker Hub + if: github.event_name != 'pull_request' + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v3 + with: + images: krateng/maloja + # generate Docker tags based on the following events/attributes + tags: | + type=raw,value=latest,enable=${{ endsWith(github.ref, 'master') }} + type=ref,event=branch,enable=${{ !endsWith(github.ref, 'master') }} + type=semver,pattern={{version}} + flavor: | + latest=false + + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} +