From 8747119dc427da8e3b80bbafd5e01390b371b6a7 Mon Sep 17 00:00:00 2001 From: Ryan Kendall Date: Fri, 2 Feb 2024 10:48:10 +0000 Subject: [PATCH] ci: run docker build on push to master --- .../workflows/build-and-push-docker-image.yml | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .github/workflows/build-and-push-docker-image.yml diff --git a/.github/workflows/build-and-push-docker-image.yml b/.github/workflows/build-and-push-docker-image.yml new file mode 100644 index 0000000..48f4f45 --- /dev/null +++ b/.github/workflows/build-and-push-docker-image.yml @@ -0,0 +1,48 @@ +name: Build and push docker image + +on: + workflow_dispatch: + workflow_call: + push: + branches: + - master + +jobs: + build_and_push_docker_image: + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v3.3.0 + + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Determine tag + id: determine_tag + run: | + base_image="ghcr.io/dfe-digital/buying-for-schools-admin" + branch="${{ github.ref_name }}" + commit="$(echo $GITHUB_SHA | head -c7)" + + if [ "$branch" == "master" ]; then + echo tags=${base_image}:${commit},${base_image}:latest >> $GITHUB_OUTPUT + else + echo tags=${base_image}:${commit},${base_image}:${branch} >> $GITHUB_OUTPUT + fi + + - name: Build and push + uses: docker/build-push-action@v4 + with: + context: . + push: true + tags: ${{ steps.determine_tag.outputs.tags }} + + +