Skip to content

Commit

Permalink
Refactor workflow to use outputs for environment variable management.
Browse files Browse the repository at this point in the history
  • Loading branch information
backwind1233 committed Nov 28, 2024
1 parent f8cc983 commit 9bed76b
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions .github/workflows/setupOpenLibertyAks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,29 @@ env:
resourceGroupForOpenLibertyAks: rg-ol-aks-${{ github.repository_owner }}-${{ github.run_id }}-${{ github.run_number }}
aksRepoUserName: WASdev
aksRepoBranchName: 048e776e9efe2ffed8368812e198c1007ba94b2c
location: ${{ github.event.inputs.location }}
cleanupOptions: ${{ github.event.inputs.cleanupOptions }}
deployRequiredSupportingResourcesOnly: ${{ github.event.inputs.deployRequiredSupportingResourcesOnly }}

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
if: github.event_name == 'schedule'
id: update-env
run: |
echo "location=westus" >> $GITHUB_ENV
echo "cleanupOptions=delete_immediately" >> $GITHUB_ENV
echo "deployRequiredSupportingResourcesOnly=false" >> $GITHUB_ENV
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 @@ -125,7 +132,7 @@ jobs:
azcliversion: ${{ env.azCliVersion }}
inlineScript: |
echo "create resource group" ${{ env.resourceGroupForDB }}
az group create --verbose --name ${{ env.resourceGroupForDB }} --location ${{ env.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 @@ -136,7 +143,7 @@ jobs:
az postgres flexible-server create \
--resource-group ${{ env.resourceGroupForDB }} \
--name ${{ env.dbServerName }} \
--location ${{ env.location }} \
--location ${{ needs.preflight.outputs.location }} \
--admin-user ${{ env.dbAdminUser }} \
--admin-password ${{ env.dbPassword }} \
--version 16 \
Expand Down Expand Up @@ -173,7 +180,7 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: check whether to skip current job
if: env.deployRequiredSupportingResourcesOnly == 'ture'
if: ${{ needs.preflight.outputs.deployRequiredSupportingResourcesOnly == 'ture' }}
run: |
echo "skip current job"
exit 0
Expand Down Expand Up @@ -218,15 +225,15 @@ jobs:
azcliversion: ${{ env.azCliVersion }}
inlineScript: |
echo "create resource group" ${{ env.resourceGroupForOpenLibertyAks }}
az group create --verbose --name ${{ env.resourceGroupForOpenLibertyAks }} --location ${{ env.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#/${{ env.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 @@ -266,7 +273,7 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: check whether to skip current job
if: env.deployRequiredSupportingResourcesOnly == 'ture'
if: ${{ needs.preflight.outputs.deployRequiredSupportingResourcesOnly == 'ture' }}
run: |
echo "skip current job"
exit 0
Expand All @@ -283,7 +290,7 @@ jobs:
az monitor log-analytics workspace create \
--resource-group ${{ env.resourceGroupForOpenLibertyAks }} \
--workspace-name ${{ env.workspaceName }} \
--location ${{ env.location }}
--location ${{ needs.preflight.outputs.location }}
- name: Enable Container Insights
id: enable-container-insights
uses: azure/CLI@v1
Expand All @@ -310,15 +317,15 @@ jobs:
az monitor app-insights component create \
--resource-group ${{ env.resourceGroupForOpenLibertyAks }} \
--app ${{ env.appInsightsName }} \
--location ${{ env.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
steps:
- name: check whether to skip current job
if: env.deployRequiredSupportingResourcesOnly == 'ture'
if: ${{ needs.preflight.outputs.deployRequiredSupportingResourcesOnly == 'ture' }}
run: |
echo "skip current job"
exit 0
Expand Down Expand Up @@ -529,18 +536,18 @@ jobs:
creds: ${{ env.azureCredentials }}
- name: Handle cleanup options
run: |
if [ "${{ env.cleanupOptions }}" == "delete_immediately" ]; then
if [ "${{ needs.preflight.outputs.cleanupOptions }}" == "delete_immediately" ]; then
echo "Resources will be deleted immediately."
elif [ "${{ env.cleanupOptions }}" == "delete_after_30m" ]; then
elif [ "${{ needs.preflight.outputs.cleanupOptions }}" == "delete_after_30m" ]; then
echo "Sleeping for 30m before deleting resources."
sleep 30m
elif [ "${{ env.cleanupOptions }}" == "delete_after_2hours" ]; then
elif [ "${{ needs.preflight.outputs.cleanupOptions }}" == "delete_after_2hours" ]; then
echo "Sleeping for 2h before deleting resources."
sleep 2h
elif [ "${{ env.cleanupOptions }}" == "delete_after_5hours" ]; then
elif [ "${{ needs.preflight.outputs.cleanupOptions }}" == "delete_after_5hours" ]; then
echo "Sleeping for 5h before deleting resources."
sleep 5h
elif [ "${{ env.cleanupOptions }}" == "never_delete" ]; then
elif [ "${{ needs.preflight.outputs.cleanupOptions }}" == "never_delete" ]; then
echo "Resources will not be deleted automatically."
exit 0
fi
Expand Down

0 comments on commit 9bed76b

Please sign in to comment.