diff --git a/.github/workflows/setupOpenLibertyAks.yml b/.github/workflows/setupOpenLibertyAks.yml index 291a97e..198fbce 100644 --- a/.github/workflows/setupOpenLibertyAks.yml +++ b/.github/workflows/setupOpenLibertyAks.yml @@ -50,7 +50,24 @@ jobs: # Make it so the bicep file that causes Liberty on AKS to be deployed is available to this workflow. preflight: runs-on: ubuntu-20.04 + outputs: + location: ${{ steps.update-env.outputs.location }} + cleanupOptions: ${{ steps.update-env.outputs.cleanupOptions }} + deployRequiredSupportingResourcesOnly: ${{ steps.update-env.outputs.deployRequiredSupportingResourcesOnly }} steps: + # if the workflow is triggered by a schedule event, update the environment variables. + - name: Update environment variables if triggered by a schedule event + id: update-env + run: | + if [ "${{ github.event_name }}" == "schedule" ]; then + echo "::set-output name=location::westus" + echo "::set-output name=cleanupOptions::delete_immediately" + echo "::set-output name=deployRequiredSupportingResourcesOnly::false" + else + echo "::set-output name=location::${{ github.event.inputs.location }}" + echo "::set-output name=cleanupOptions::${{ github.event.inputs.cleanupOptions }}" + echo "::set-output name=deployRequiredSupportingResourcesOnly::${{ github.event.inputs.deployRequiredSupportingResourcesOnly }}" + fi - name: Set up bicep run: | curl -Lo bicep https://github.com/Azure/bicep/releases/download/v0.29.47/bicep-linux-x64 @@ -114,7 +131,7 @@ jobs: azcliversion: ${{ env.azCliVersion }} inlineScript: | echo "create resource group" ${{ env.resourceGroupForDB }} - az group create --verbose --name ${{ env.resourceGroupForDB }} --location ${{ inputs.location }} + az group create --verbose --name ${{ env.resourceGroupForDB }} --location ${{ needs.preflight.outputs.location }} - name: Set Up Azure Postgresql to Test dbTemplate id: setup-postgresql uses: azure/CLI@v1 @@ -125,7 +142,7 @@ jobs: az postgres flexible-server create \ --resource-group ${{ env.resourceGroupForDB }} \ --name ${{ env.dbServerName }} \ - --location ${{ inputs.location }} \ + --location ${{ needs.preflight.outputs.location }} \ --admin-user ${{ env.dbAdminUser }} \ --admin-password ${{ env.dbPassword }} \ --version 16 \ @@ -160,8 +177,12 @@ jobs: deploy-openliberty-on-aks: needs: preflight runs-on: ubuntu-20.04 - if: ${{ inputs.deployRequiredSupportingResourcesOnly == false }} steps: + - name: check whether to skip current job + if: ${{ needs.preflight.outputs.deployRequiredSupportingResourcesOnly == 'ture' }} + run: | + echo "skip current job" + exit 0 - name: Checkout ${{ env.aksRepoUserName }}/azure.liberty.aks uses: actions/checkout@v2 with: @@ -203,7 +224,7 @@ jobs: azcliversion: ${{ env.azCliVersion }} inlineScript: | echo "create resource group" ${{ env.resourceGroupForOpenLibertyAks }} - az group create --verbose --name ${{ env.resourceGroupForOpenLibertyAks }} --location ${{ inputs.location }} + az group create --verbose --name ${{ env.resourceGroupForOpenLibertyAks }} --location ${{ needs.preflight.outputs.location }} - name: Checkout cargotracker uses: actions/checkout@v2 with: @@ -211,7 +232,7 @@ jobs: - name: Prepare parameter file run: | echo "replace placeholders using real parameter" - sed -i "s/#location#/${{ inputs.location }}/g; \ + sed -i "s/#location#/${{ needs.preflight.outputs.location }}/g; \ s/#testbranchName#/${aksRepoBranchName}/g; \ s/#gitUserName#/${aksRepoUserName}/g" \ cargotracker/src/test/aks/parameters.json @@ -249,8 +270,12 @@ jobs: deploy-azure-monitor: needs: [preflight, deploy-openliberty-on-aks] runs-on: ubuntu-20.04 - if: ${{ inputs.deployRequiredSupportingResourcesOnly == false }} steps: + - name: check whether to skip current job + if: ${{ needs.preflight.outputs.deployRequiredSupportingResourcesOnly == 'ture' }} + run: | + echo "skip current job" + exit 0 - uses: azure/login@v1 id: azure-login with: @@ -264,7 +289,7 @@ jobs: az monitor log-analytics workspace create \ --resource-group ${{ env.resourceGroupForOpenLibertyAks }} \ --workspace-name ${{ env.workspaceName }} \ - --location ${{ inputs.location }} + --location ${{ needs.preflight.outputs.location }} - name: Enable Container Insights id: enable-container-insights uses: azure/CLI@v1 @@ -291,14 +316,18 @@ jobs: az monitor app-insights component create \ --resource-group ${{ env.resourceGroupForOpenLibertyAks }} \ --app ${{ env.appInsightsName }} \ - --location ${{ inputs.location }} \ + --location ${{ needs.preflight.outputs.location }} \ --workspace ${workspaceId} # Build app, push to ACR and apply it to Open Liberty servers running on AKS. deploy-cargo-tracker: needs: [preflight, deploy-db,deploy-azure-monitor] runs-on: ubuntu-20.04 - if: ${{ inputs.deployRequiredSupportingResourcesOnly == false }} steps: + - name: check whether to skip current job + if: ${{ needs.preflight.outputs.deployRequiredSupportingResourcesOnly == 'ture' }} + run: | + echo "skip current job" + exit 0 - uses: actions/checkout@v4 - uses: actions/setup-java@v4 with: @@ -495,7 +524,7 @@ jobs: echo "${appURL}" >> $GITHUB_STEP_SUMMARY # Delete azure resources cleanup: - name: provisioned resources will ${{ inputs.cleanupOptions }} automatically + name: provisioned resources will ${{ needs.preflight.outputs.cleanupOptions }} automatically if: always() needs: [preflight, deploy-db, deploy-openliberty-on-aks, deploy-azure-monitor, deploy-cargo-tracker] runs-on: ubuntu-latest @@ -506,25 +535,25 @@ jobs: creds: ${{ env.azureCredentials }} - name: Handle cleanup options run: | - if [ "${{ github.event.inputs.cleanupOptions }}" == "delete_immediately" ]; then + if [ "${{ needs.preflight.outputs.cleanupOptions }}" == "delete_immediately" ]; then echo "Resources will be deleted immediately." - elif [ "${{ github.event.inputs.cleanupOptions }}" == "delete_after_30m" ]; then + elif [ "${{ needs.preflight.outputs.cleanupOptions }}" == "delete_after_30m" ]; then echo "Sleeping for 30m before deleting resources." sleep 30m - elif [ "${{ github.event.inputs.cleanupOptions }}" == "delete_after_2hours" ]; then + elif [ "${{ needs.preflight.outputs.cleanupOptions }}" == "delete_after_2hours" ]; then echo "Sleeping for 2h before deleting resources." sleep 2h - elif [ "${{ github.event.inputs.cleanupOptions }}" == "delete_after_5hours" ]; then + elif [ "${{ needs.preflight.outputs.cleanupOptions }}" == "delete_after_5hours" ]; then echo "Sleeping for 5h before deleting resources." sleep 5h - elif [ "${{ github.event.inputs.cleanupOptions }}" == "never_delete" ]; then + elif [ "${{ needs.preflight.outputs.cleanupOptions }}" == "never_delete" ]; then echo "Resources will not be deleted automatically." exit 0 fi - name: Delete Azure resources. uses: azure/CLI@v1 - if: ${{ github.event.inputs.cleanupOptions != 'never_delete' }} + if: ${{ needs.preflight.outputs.cleanupOptions != 'never_delete' }} with: azcliversion: ${{ env.azCliVersion }} inlineScript: |