diff --git a/.azuredevops/templates/steps/tf_plan.yaml b/.azuredevops/templates/steps/tf_plan.yaml index 04b538e2..1b4e5eca 100644 --- a/.azuredevops/templates/steps/tf_plan.yaml +++ b/.azuredevops/templates/steps/tf_plan.yaml @@ -2,7 +2,6 @@ parameters: - name: tfCommandOptions - type: string default: '' steps: @@ -24,7 +23,13 @@ steps: provider: azurerm command: plan workingDirectory: $(TF_DIRECTORY) - commandOptions: -input=false -var-file=$(tfVarsFile) ${{ parameters.tfCommandOptions }} -out=$(Build.ArtifactStagingDirectory)/$(ENVIRONMENT).tfplan + commandOptions: > + -input=false + -var-file=$(tfVarsFile) + -var="image_commit_hash=$(imageHash)" + -var="registry_host=$(registryHost)" + ${{ parameters.tfCommandOptions }} + -out=$(Build.ArtifactStagingDirectory)/$(ENVIRONMENT).tfplan environmentServiceNameAzureRM: $(SERVICE_CONNECTION) - task: PublishBuildArtifacts@1 diff --git a/.github/workflows/cicd-1-pull-request.yaml b/.github/workflows/cicd-1-pull-request.yaml index cd068ec0..fd6487d3 100644 --- a/.github/workflows/cicd-1-pull-request.yaml +++ b/.github/workflows/cicd-1-pull-request.yaml @@ -98,13 +98,11 @@ jobs: uses: ./.github/workflows/stage-3-build.yaml if: needs.metadata.outputs.does_pull_request_exist == 'true' || (github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened')) with: - build_datetime: "${{ needs.metadata.outputs.build_datetime }}" - build_timestamp: "${{ needs.metadata.outputs.build_timestamp }}" - build_epoch: "${{ needs.metadata.outputs.build_epoch }}" - nodejs_version: "${{ needs.metadata.outputs.nodejs_version }}" - python_version: "${{ needs.metadata.outputs.python_version }}" - terraform_version: "${{ needs.metadata.outputs.terraform_version }}" - version: "${{ needs.metadata.outputs.version }}" + docker_compose_file_csv_list: compose.yaml + excluded_containers_csv_list: azurite,azurite-setup,sql-database,database-setup,db + environment_tag: ${{ needs.metadata.outputs.environment_tag }} + function_app_source_code_path: src + project_name: project-pipeline-name secrets: inherit acceptance-stage: # Recommended maximum execution time is 10 minutes name: "Acceptance stage" diff --git a/.github/workflows/stage-3-build.yaml b/.github/workflows/stage-3-build.yaml index 52421f55..904a8cf6 100644 --- a/.github/workflows/stage-3-build.yaml +++ b/.github/workflows/stage-3-build.yaml @@ -197,6 +197,7 @@ jobs: env: pr_num_tag: ${{ needs.containers-to-build.outputs.pr_num_tag }} short_commit_hash: ${{ needs.containers-to-build.outputs.short_commit_hash }} + project_name: ${{ inputs.project_name }} permissions: id-token: write contents: read @@ -233,8 +234,8 @@ jobs: - name: Tag all Registry Container images env: container_registry: ${{ env.REGISTRY_HOST }} - docker_services: ${{ needs.containers-to-build.outputs.docker_services }} - project_name: ${{ inputs.project_name }} + docker_services: >- + ${{ needs.containers-to-build.outputs.docker_services && join(fromJSON(needs.containers-to-build.outputs.docker_services || '[]'), ',') }} run: | echo Running 'docker buildx imagetools' on remote repositories... @@ -242,15 +243,34 @@ jobs: az acr login --name "${ACR_NAME}" fi - services=($(echo "$docker_services" | jq -r '.[]')) + IFS=',' read -ra services <<< "$docker_services" for service in "${services[@]}"; do image_name="${project_name}-${service}" registry_image=${container_registry,,}/${image_name,,} echo "Adding tag ${short_commit_hash} to ${image_name}..." - docker buildx imagetools create "${registry_image}:${pr_num_tag}" --tag "${registry_image}:${short_commit_hash}" || echo "Tagging failed for $service" + docker buildx imagetools create "${registry_image}:${pr_num_tag}" --tag "${registry_image}:${short_commit_hash}" \ + || echo "Tagging failed for $service" done + - uses: azure/login@v2 + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + + - name: Call deployment pipeline + if: success() + env: + container_registry: ${{ env.REGISTRY_HOST }} + run: | + az pipelines run \ + --branch "main" \ + --name cd-infrastructure-dev-core \ + --org https://dev.azure.com/nhse-dtos \ + --project ${project_name} \ + --parameters "imageHash=${short_commit_hash}" "registryHost=${container_registry,,}" + aggregate-reports: name: Aggregate reports runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index 969c6f2c..38ee8762 100644 --- a/.gitignore +++ b/.gitignore @@ -75,3 +75,5 @@ coverage.xml .pyre/ .pylint.d/ .prof +__azurite_db_blob__.json +__azurite_db_blob_extent__.json diff --git a/scripts/deployments/get-docker-names.sh b/scripts/deployments/get-docker-names.sh index 0fcfc0a4..bbc13963 100644 --- a/scripts/deployments/get-docker-names.sh +++ b/scripts/deployments/get-docker-names.sh @@ -156,13 +156,16 @@ EOF fi changed_services_json="$(jq -c -n '$ARGS.positional | unique' --args "${changed_services[@]}")" -services_json="$(jq -c -n '$ARGS.positional | unique' --args "${docker_services_map[@]}")" + +args=("${docker_services_map[@]}") +services_json=$(jq -c -n '$ARGS.positional | unique' --args "${args[@]}") + IFS=$IFS_OLD echo "List of services to build:" echo "${changed_services_json}" echo "FUNC_NAMES=${changed_services_json}" >> "${GITHUB_OUTPUT}" -echo "ALL_SERVICES=%{services_json}" >> "${GITHUB_OUTPUT}" +echo "ALL_SERVICES=${services_json}" >> "${GITHUB_OUTPUT}" # Assumes all compose files are together in the same folder echo "DOCKER_COMPOSE_DIR=$(dirname "${compose_file}")" >> "${GITHUB_OUTPUT}"