From c70c136695a47b284f3197d5f4f5b0c9532ae680 Mon Sep 17 00:00:00 2001 From: Chandler May Date: Fri, 20 Oct 2023 14:17:00 -0400 Subject: [PATCH] CI builds and pushes to Docker Hub. --- .github/workflows/docker-build-and-push.yml | 61 +++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 .github/workflows/docker-build-and-push.yml diff --git a/.github/workflows/docker-build-and-push.yml b/.github/workflows/docker-build-and-push.yml new file mode 100644 index 0000000..23b77b0 --- /dev/null +++ b/.github/workflows/docker-build-and-push.yml @@ -0,0 +1,61 @@ +# Based on: +# https://docs.github.com/en/actions/publishing-packages/publishing-docker-images + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +# GitHub recommends pinning actions to a commit SHA. +# To get a newer version, you will need to update the SHA. +# You can also reference a tag or branch, but the action may change without warning. + +name: Build and push Docker image + +on: + workflow_dispatch: + push: + branches: + - 'main' + tags: + - 'v*.*.*' + pull_request: + branches: + - 'main' + +jobs: + push_to_registry: + name: Push Docker image to Docker Hub + runs-on: ubuntu-latest + steps: + - name: Check out the repo + uses: actions/checkout@v3 + + - name: Log in to Docker Hub + if: github.event_name != 'pull_request' + uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@35e9aff4f5d665b5aa8a8f2adffaf8a1b5f49cc0 + with: + images: hltcoe/concrete-python + tags: | + type=schedule + type=ref,event=branch + type=ref,event=tag + type=ref,event=pr + # set latest tag for default branch + type=raw,value=latest,enable={{is_default_branch}},priority=2000 + + - name: Build and push Docker image + uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 + with: + context: . + file: ./Dockerfile + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }}