Skip to content

Commit

Permalink
Merge pull request #37 from azure-javaee/fix_workflow_schedule
Browse files Browse the repository at this point in the history
Update workflow to support both  `schedule` and `workflow_dispatch` trigger
  • Loading branch information
edburns authored Dec 10, 2024
2 parents f1c3a32 + b84d02c commit 078d2cb
Showing 1 changed file with 45 additions and 16 deletions.
61 changes: 45 additions & 16 deletions .github/workflows/setupOpenLibertyAks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 \
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -203,15 +224,15 @@ 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:
path: cargotracker
- 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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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: |
Expand Down

0 comments on commit 078d2cb

Please sign in to comment.