diff --git a/.github/workflows/jib-build.yml b/.github/workflows/jib-build.yml new file mode 100644 index 00000000..08f20935 --- /dev/null +++ b/.github/workflows/jib-build.yml @@ -0,0 +1,51 @@ +name: Build & push docker image and deploy to environment + +on: + workflow_call: + + outputs: + app_version: + description: The version of the app as generated by create_app_version + value: ${{ jobs.docker_build.outputs.version }} + +permissions: + contents: read + packages: write + +jobs: + docker_build: + name: Build docker image + runs-on: ubuntu-latest + outputs: + version: ${{ steps.app_version.outputs.version }} + steps: + - id: app_version + name: Application version creators + uses: ministryofjustice/hmpps-github-actions/.github/actions/build-test-and-deploy/create_app_version@v2 # WORKFLOW_VERSION + + - uses: actions/checkout@v4 + - name: refresh cache + id: initial-cache + uses: actions/cache@v4 + env: + cache-name: kotlin-cache + with: + path: | + - gradle-{{ checksum "build.gradle.kts" }} + - gradle- + key: ${{ runner.os }}-gradle-${{ env.cache-name }}-${{ hashFiles('build.gradle.kts') }} + + - uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '21' + cache: 'gradle' + cache-dependency-path: | + *.gradle* + **/gradle-wrapper.properties + - run: ./gradlew jib --image="${IMAGE_NAME}:${BUILD_NUMBER}" -Djib.to.auth.username=${GITHUB_USERNAME} -Djib.to.auth.password=${GITHUB_PASSWORD} -Djib.to.tags=latest -Djib.container.environment=BUILD_NUMBER="${BUILD_NUMBER}" + env: + GITHUB_USERNAME: ${{ github.actor }} + GITHUB_PASSWORD: ${{ github.token }} + BUILD_NUMBER: ${{ steps.app_version.outputs.version }} + IMAGE_NAME: "ghcr.io/ministryofjustice/probation-offender-search" diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 5739798f..a2bb14a9 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -35,24 +35,16 @@ jobs: name: Validate the kotlin uses: ./.github/workflows/kotlin_integration_tests.yml secrets: inherit - build: - name: Build docker image from hmpps-github-actions - if: github.ref == 'refs/heads/main' - uses: ministryofjustice/hmpps-github-actions/.github/workflows/docker_build.yml@v2 # WORKFLOW_VERSION - needs: - - kotlin_validate - with: - docker_registry: 'ghcr.io' - registry_org: 'ministryofjustice' - additional_docker_tag: "" - push: ${{ inputs.push || true }} - docker_multiplatform: false - additional_docker_build_args: "" + docker_build: + if: ${{ github.ref == 'refs/heads/main' || inputs.push }} + name: Push image + uses: ./.github/workflows/jib-build.yml + needs: kotlin_validate deploy_dev: name: Deploy to the dev environment if: github.ref == 'refs/heads/main' needs: - - build + - docker_build - helm_lint uses: ministryofjustice/hmpps-github-actions/.github/workflows/deploy_env.yml@v2 # WORKFLOW_VERSION secrets: inherit @@ -62,7 +54,7 @@ jobs: deploy_preprod: name: Deploy to the preprod environment needs: - - build + - docker_build - helm_lint uses: ministryofjustice/hmpps-github-actions/.github/workflows/deploy_env.yml@v2 # WORKFLOW_VERSION secrets: inherit @@ -72,7 +64,7 @@ jobs: deploy_prod: name: Deploy to the prod environment needs: - - build + - docker_build - helm_lint - deploy_dev - deploy_preprod