From 4cc3933102fbf4299985fe0c4a239a610f6c4e28 Mon Sep 17 00:00:00 2001 From: Sam Carter Date: Tue, 23 Jan 2024 14:55:37 +0000 Subject: [PATCH] Added new workflows to start the main workflow and initially just build the docker image --- .github/workflows/build-image.yml | 51 +++++++++++++++++++++ .github/workflows/main-build-and-deploy.yml | 38 +++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 .github/workflows/build-image.yml create mode 100644 .github/workflows/main-build-and-deploy.yml diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml new file mode 100644 index 00000000..e9d93d30 --- /dev/null +++ b/.github/workflows/build-image.yml @@ -0,0 +1,51 @@ +name: Build Image and Publish to GCR + +on: + workflow_call: + inputs: + branch: + type: string + required: true + checked-out-sha: + type: string + required: true + +concurrency: + group: ${{ github.workflow }}-${{ github.event.inputs.environment }} + cancel-in-progress: true + +env: + DOCKER_IMAGE: early-years-qualification + GITHUB_CONTAINER_REGISTRY: ghcr.io + ORG_NAME: dfe-digital + +jobs: + + build-image: + + runs-on: ubuntu-22.04 + name: Build & Publish Image + + steps: + + - name: Checkout Repository + uses: actions/checkout@v3 + with: + ref: ${{ github.ref }} + + # - name: GitHub Container Registry Login + # uses: docker/login-action@v3 + # with: + # registry: ${{ env.GITHUB_CONTAINER_REGISTRY }} + # username: ${{ github.repository_owner }} + # password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build Image & Publish To GCR + uses: docker/build-push-action@v4 + with: + context: ./ + file: ./src/Dfe.EarlyYearsQualification.Web/Dockerfile + build-args: COMMIT_SHA=${{ inputs.checked-out-sha }} + tags: | + ${{ env.GITHUB_CONTAINER_REGISTRY }}/${{ env.ORG_NAME }}/${{ env.DOCKER_IMAGE }}:${{ inputs.branch }}-${{ inputs.checked-out-sha }} + # push: true // Commented out for now to test the docker build diff --git a/.github/workflows/main-build-and-deploy.yml b/.github/workflows/main-build-and-deploy.yml new file mode 100644 index 00000000..6d3bde38 --- /dev/null +++ b/.github/workflows/main-build-and-deploy.yml @@ -0,0 +1,38 @@ +name: Main build & deploy + +on: + workflow_dispatch: + push: + branches: ["main"] + paths: + - 'src/**' + - '.github/workflows/main-build-and-deploy.yml' + +jobs: + + set-env: + runs-on: ubuntu-22.04 + name: Set Environment Values + outputs: + branch: ${{ steps.var.outputs.branch }} + checked-out-sha: ${{ steps.var.outputs.checked-out-sha }} + steps: + - uses: actions/checkout@v3 + with: + ref: ${{ github.ref }} + + - id: var + run: | + GIT_BRANCH=${GITHUB_BASE_REF:-${GITHUB_REF#refs/heads/}} + CHECKED_OUT_SHA="$(git log -1 '--format=format:%H')" + echo "branch=$GIT_BRANCH" >> $GITHUB_OUTPUT + echo "checked-out-sha=${CHECKED_OUT_SHA}" >> $GITHUB_OUTPUT + + create-and-publish-image: + needs: set-env + name: Create & Publish Image + uses: ./.github/workflows/build-image.yml + secrets: inherit + with: + branch: ${{ needs.set-env.outputs.branch }} + checked-out-sha: ${{ needs.set-env.outputs.checked-out-sha }} \ No newline at end of file