From a470be7956da5aac3d04c6ed163501e1983a927b Mon Sep 17 00:00:00 2001 From: VKTB <45173816+VKTB@users.noreply.github.com> Date: Tue, 12 Nov 2024 17:34:52 +0000 Subject: [PATCH] Only push Docker images to Harbor on workflow_dispatch #133 --- .github/workflows/ci-build.yml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 4e04606..0f6228f 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -1,6 +1,12 @@ name: CI on: workflow_dispatch: + inputs: + push-docker-image-to-harbor: + description: 'Push Docker Image to Harbor' + type: boolean + default: false + pull_request: push: branches: @@ -82,12 +88,11 @@ jobs: run: nox -s safety docker: - # This job triggers only if all the other jobs succeed and does different things depending on the context. - # The job builds the Docker image in all cases and also pushes the image to Harbor only if something is - # pushed to the main branch. needs: [tests, linting, formatting, safety] name: Docker runs-on: ubuntu-20.04 + env: + PUSH_DOCKER_IMAGE_TO_HARBOR: ${{ inputs.push-docker-image-to-harbor }} steps: - name: Check out repo uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.5.2 @@ -105,11 +110,11 @@ jobs: with: images: harbor.stfc.ac.uk/datagateway/scigateway-auth - - name: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && 'Build and push Docker image to Harbor' || 'Build Docker image' }} + - name: ${{ fromJSON(env.PUSH_DOCKER_IMAGE_TO_HARBOR) && 'Build and push Docker image to Harbor' || 'Build Docker image' }} uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 # v4.0.0 with: context: . - push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} + push: ${{ fromJSON(env.PUSH_DOCKER_IMAGE_TO_HARBOR) }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} target: prod