integration-test #64
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Copyright (c) IBM Corporation. | |
| # Copyright (c) Microsoft Corporation. | |
| name: integration-test | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| enableAppGWIngress: | |
| description: 'Application Gateway Ingress Controller' | |
| required: true | |
| type: boolean | |
| default: true | |
| deployWLO: | |
| description: 'WebSphere Liberty Operator' | |
| required: true | |
| type: boolean | |
| default: false | |
| deployApplication: | |
| description: 'Sample application' | |
| required: true | |
| type: boolean | |
| default: true | |
| autoScaling: | |
| description: 'Autoscaling for app deployment' | |
| required: true | |
| type: boolean | |
| default: false | |
| deleteAzureResources: | |
| description: 'Delete Azure resources at the end' | |
| required: true | |
| type: boolean | |
| default: true | |
| location: | |
| description: 'Location of the Azure resources' | |
| required: true | |
| type: string | |
| default: 'eastus' | |
| configurations_for_it: | |
| description: "JSON string of environment variables used for IT" | |
| required: false | |
| default: '{}' | |
| # Allows you to run this workflow using GitHub workflow dispatch APIs | |
| # PERSONAL_ACCESS_TOKEN=<GITHUB_PERSONAL_ACCESS_TOKEN> | |
| # REPO_NAME=WASdev/azure.liberty.aks | |
| # Enable/disable AGIC, WebSphere Liberty Operator and sample application. Keep/delete Azure resources at the end. | |
| # curl --verbose -XPOST -u "WASdev:${PERSONAL_ACCESS_TOKEN}" -H "Accept: application/vnd.github.everest-preview+json" -H "Content-Type: application/json" https://api.github.com/repos/${REPO_NAME}/actions/workflows/integration-test.yaml/dispatches --data '{"ref": "main", "inputs":{"enableAppGWIngress": "true|false", "deployWLO": "true|false", "deployApplication": "true|false", "autoScaling": "true|false", "deleteAzureResources": "true|false"}}' | |
| repository_dispatch: | |
| types: [integration-test] | |
| # Allows you to run this workflow using GitHub repository dispatch APIs | |
| # PERSONAL_ACCESS_TOKEN=<GITHUB_PERSONAL_ACCESS_TOKEN> | |
| # REPO_NAME=WASdev/azure.liberty.aks | |
| # Enable/disable AGIC, WebSphere Liberty Operator and sample application. Keep/delete Azure resources at the end. | |
| # curl --verbose -X POST https://api.github.com/repos/${REPO_NAME}/dispatches -H "Accept: application/vnd.github.everest-preview+json" -H "Authorization: token ${PERSONAL_ACCESS_TOKEN}" --data '{"event_type": "integration-test", "client_payload": {"enableAppGWIngress": true|false, "deployWLO": true|false, "deployApplication": true|false, "autoScaling": true|false, "deleteAzureResources": true|false}}' | |
| env: | |
| repoName: "azure.liberty.aks" | |
| azureCredentials: ${{ secrets.AZURE_CREDENTIALS }} | |
| userName: ${{ secrets.USER_NAME }} | |
| msTeamsWebhook: ${{ secrets.MSTEAMS_WEBHOOK }} | |
| testResourceGroup: libertyAksTestRG-${{ github.repository_owner }}-${{ github.run_id }}-${{ github.run_number }} | |
| testDeploymentName: libertyAksTestDeployment-${{ github.repository_owner }}-${{ github.run_id }}-${{ github.run_number }} | |
| location: ${{ github.event.inputs.location || 'eastus' }} | |
| jobs: | |
| integration-test: | |
| runs-on: ubuntu-latest | |
| env: ${{ fromJson(inputs.configurations_for_it) }} | |
| steps: | |
| - name: Get versions of external dependencies | |
| id: get-external-deps-versions | |
| run: | | |
| curl -Lo external-deps-versions.properties https://raw.githubusercontent.com/Azure/azure-javaee-iaas/main/external-deps-versions.properties | |
| source external-deps-versions.properties | |
| echo "bicepVersion=${BICEP_VERSION}" >> $GITHUB_ENV | |
| - name: Set up JDK 1.8 | |
| uses: actions/setup-java@v1 | |
| with: | |
| java-version: 1.8 | |
| server-id: github # Value of the distributionManagement/repository/id field of the pom.xml | |
| server-username: MAVEN_USERNAME # env variable for username | |
| server-password: MAVEN_TOKEN # env variable for token | |
| - name: Set Maven env | |
| env: | |
| MAVEN_USERNAME: github | |
| MAVEN_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| shell: bash | |
| run: | | |
| echo "MAVEN_USERNAME=${MAVEN_USERNAME}" >> "$GITHUB_ENV" | |
| echo "MAVEN_TOKEN=${MAVEN_TOKEN}" >> "$GITHUB_ENV" | |
| - name: Set up bicep | |
| run: | | |
| curl -Lo bicep https://github.com/Azure/bicep/releases/download/${{ env.bicepVersion }}/bicep-linux-x64 | |
| chmod +x ./bicep | |
| sudo mv ./bicep /usr/local/bin/bicep | |
| bicep --version | |
| - name: Checkout arm-ttk | |
| uses: actions/checkout@v2 | |
| with: | |
| repository: Azure/arm-ttk | |
| path: arm-ttk | |
| - name: Checkout ${{ env.repoName }} | |
| uses: actions/checkout@v2 | |
| with: | |
| path: ${{ env.repoName }} | |
| ref: ${{ github.event.inputs.ref }} | |
| - name: Build ${{ env.repoName }} | |
| run: | | |
| enableAppGWIngress=false | |
| if ${{ inputs.enableAppGWIngress == true || github.event.client_payload.enableAppGWIngress == true }}; then | |
| enableAppGWIngress=true | |
| fi | |
| echo "enableAppGWIngress=${enableAppGWIngress}" >> $GITHUB_ENV | |
| deployWLO=false | |
| if ${{ inputs.deployWLO == true || github.event.client_payload.deployWLO == true }}; then | |
| deployWLO=true | |
| fi | |
| deployApplication=false | |
| if ${{ inputs.deployApplication == true || github.event.client_payload.deployApplication == true }}; then | |
| deployApplication=true | |
| fi | |
| echo "deployApplication=${deployApplication}" >> $GITHUB_ENV | |
| autoScaling=false | |
| if ${{ inputs.autoScaling == true || github.event.client_payload.autoScaling == true }}; then | |
| autoScaling=true | |
| fi | |
| cd ${{ env.repoName }} | |
| if ${{ env.createCluster == 'false' }}; then | |
| echo "Deploy with an existing AKS cluster" | |
| createCluster=false | |
| clusterName=${{ env.clusterName }} | |
| clusterRGName=${{ env.testResourceGroup }} | |
| else | |
| echo "Deploy with a new AKS cluster" | |
| createCluster=true | |
| clusterName="aks-cluster-${{ github.run_id }}-${{ github.run_number }}" | |
| clusterRGName=${{ env.testResourceGroup }} | |
| fi | |
| mvn -Dgit.repo=${{ env.userName }} -Dgit.tag=$GITHUB_REF_NAME \ | |
| -DcreateCluster=${createCluster} \ | |
| -DclusterName=${clusterName} \ | |
| -DclusterRGName=${clusterRGName} \ | |
| -DcreateACR=true \ | |
| -DenableAppGWIngress=${enableAppGWIngress} -DappgwUsePrivateIP=false -DappGatewayCertificateOption=generateCert -DenableCookieBasedAffinity=true \ | |
| -DdeployWLO=${deployWLO} -Dedition="IBM WebSphere Application Server" -DproductEntitlementSource="Standalone" \ | |
| -DdeployApplication=${deployApplication} -DappImagePath=icr.io/appcafe/open-liberty/samples/getting-started -DappReplicas=2 \ | |
| -DautoScalingParam=${autoScaling} -DcpuUtilizationPercentageParam=80 -DminReplicasParam=1 -DmaxReplicasParam=100 -DrequestCPUMillicoreParam=300 \ | |
| -Dtest.args="-Test All" -Pbicep -Passembly -Ptemplate-validation-tests clean install | |
| - uses: azure/login@v1 | |
| id: azure-login | |
| with: | |
| creds: ${{ env.azureCredentials }} | |
| - name: Provision AKS Cluster as an existing cluster for deployment | |
| if: ${{ env.createCluster == 'false' }} | |
| run: | | |
| # the value of **createCluster** is `false`, which means the offer won't create a new AKS cluster, but use an existing one. | |
| # in order to simulate the same behavior as the offer, we need to create a resource group and an AKS cluster. | |
| az group create -n ${{ env.testResourceGroup }} -l ${{ env.location }} | |
| az feature register \ | |
| --namespace "Microsoft.ContainerService" \ | |
| --name "AppGatewayWithOverlayPreview" | |
| az provider register --namespace Microsoft.ContainerService | |
| az aks create \ | |
| -n ${{ env.clusterName }} \ | |
| -g ${{ env.testResourceGroup }} \ | |
| --enable-managed-identity \ | |
| --network-plugin kubenet \ | |
| --generate-ssh-keys | |
| - name: Start the deployment | |
| run: | | |
| cd ${{ env.repoName }}/target/cli | |
| chmod a+x deploy.azcli | |
| ./deploy.azcli -n ${{ env.testDeploymentName }} -g ${{ env.testResourceGroup }} -l ${{ env.location }} | |
| - name: Verify the deployment | |
| run: | | |
| outputs=$(az deployment group show -n ${{ env.testDeploymentName }} -g ${{ env.testResourceGroup }} --query 'properties.outputs') | |
| appHttpEndpoint=$(echo $outputs | jq -r '.appHttpEndpoint.value') | |
| echo "appHttpEndpoint: ${appHttpEndpoint}" | |
| appHttpsEndpoint=$(echo $outputs | jq -r '.appHttpsEndpoint.value') | |
| echo "appHttpsEndpoint: ${appHttpsEndpoint}" | |
| if [[ $deployApplication == "true" ]]; then | |
| if [[ -z "$appHttpEndpoint" ]]; then | |
| echo "Invalid value of appHttpEndpoint: ${appHttpEndpoint}" | |
| exit 1 | |
| fi | |
| curl --verbose --connect-timeout 60 --max-time 180 --retry 10 --retry-delay 30 --retry-max-time 180 --retry-connrefused $appHttpEndpoint | |
| if [[ $? -ne 0 ]]; then | |
| echo "Failed to access ${appHttpEndpoint}." | |
| exit 1 | |
| fi | |
| elif [[ -n "$appHttpEndpoint" ]]; then | |
| echo "Invalid value of appHttpEndpoint: ${appHttpEndpoint}" | |
| exit 1 | |
| fi | |
| if [[ $deployApplication == "true" && $enableAppGWIngress == "true" ]]; then | |
| if [[ -z "$appHttpsEndpoint" ]]; then | |
| echo "Invalid value of appHttpsEndpoint: ${appHttpsEndpoint}" | |
| exit 1 | |
| fi | |
| curl --verbose --connect-timeout 60 --max-time 180 --retry 10 --retry-delay 30 --retry-max-time 180 --retry-connrefused $appHttpsEndpoint -k | |
| if [[ $? -ne 0 ]]; then | |
| echo "Failed to access ${appHttpsEndpoint}." | |
| exit 1 | |
| fi | |
| elif [[ -n "$appHttpsEndpoint" ]]; then | |
| echo "Invalid value of appHttpsEndpoint: ${appHttpsEndpoint}" | |
| exit 1 | |
| fi | |
| - name: Generate artifact file name and path | |
| id: artifact_file | |
| run: | | |
| version=$(mvn -q -Dexec.executable=echo -Dexec.args='${version.${{ env.repoName }}}' --file ${{ env.repoName }}/pom.xml --non-recursive exec:exec) | |
| artifactName=${{ env.repoName }}-$version-arm-assembly | |
| unzip ${{ env.repoName }}/target/$artifactName.zip -d ${{ env.repoName }}/target/$artifactName | |
| echo "##[set-output name=artifactName;]${artifactName}" | |
| echo "##[set-output name=artifactPath;]${{ env.repoName }}/target/$artifactName" | |
| - name: Archive ${{ env.repoName }} template | |
| uses: actions/[email protected] | |
| if: success() | |
| with: | |
| name: ${{steps.artifact_file.outputs.artifactName}} | |
| path: ${{steps.artifact_file.outputs.artifactPath}} | |
| notification: | |
| needs: integration-test | |
| if: always() | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Output inputs from workflow_dispatch | |
| run: echo "${{ toJSON(github.event.inputs) }}" | |
| - name: Output client_payload from repository_dispatch | |
| run: echo "${{ toJSON(github.event.client_payload) }}" | |
| - name: Send notification | |
| if: ${{ env.msTeamsWebhook != 'NA' }} | |
| run: | | |
| workflowJobs=$(curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${{ env.userName }}/${{ env.repoName }}/actions/runs/${{ github.run_id }}/jobs) | |
| successIntegrationTestJob=$(echo $workflowJobs | jq 'select(.jobs != null) | .jobs | map(select(.name=="integration-test" and .conclusion=="success")) | length') | |
| echo "$successIntegrationTestJob" | |
| if [ -z $successIntegrationTestJob ];then | |
| echo "jobs not retrieved." | |
| elif (($successIntegrationTestJob == 0));then | |
| echo "Job integration-test failed, send notification to Teams" | |
| curl ${{ env.msTeamsWebhook }} \ | |
| -H 'Content-Type: application/json' \ | |
| --data-binary @- << EOF | |
| { | |
| "@context":"http://schema.org/extensions", | |
| "@type":"MessageCard", | |
| "text":"Workflow integration-test of repo ${{ env.repoName }} failed, please take a look at: https://github.com/${{ env.userName }}/${{ env.repoName }}/actions/runs/${{ github.run_id }}" | |
| } | |
| EOF | |
| else | |
| echo "Job integration-test succeeded." | |
| fi | |
| delete-resources: | |
| needs: [notification,integration-test] | |
| runs-on: ubuntu-latest | |
| if: always() | |
| steps: | |
| - uses: azure/login@v1 | |
| id: azure-login | |
| with: | |
| creds: ${{ env.azureCredentials }} | |
| - name: Checkout ${{ env.repoName }} | |
| uses: actions/checkout@v2 | |
| with: | |
| path: ${{ env.repoName }} | |
| ref: ${{ github.event.inputs.ref }} | |
| - name: Delete all Azure resources | |
| id: delete-resources-in-group | |
| if: ${{ (github.event_name == 'workflow_dispatch' && inputs.deleteAzureResources) || (github.event_name == 'repository_dispatch' && github.event.client_payload.deleteAzureResources) }} | |
| run: | | |
| az group delete -n ${{ env.testResourceGroup }} --yes --no-wait |