Skip to content

Test WLS on AKS with Dependency creation #37

Test WLS on AKS with Dependency creation

Test WLS on AKS with Dependency creation #37

name: Test WLS on AKS with Dependency creation
on:
workflow_dispatch:
inputs:
isForDemo:
description: 'If set to true, resources will not be deleted'
required: true
default: 'false'
gitUserNameForArtifactsLocation:
description: 'Replaced into https://raw.githubusercontent.com/#gitUserName#/weblogic-azure/#testbranchName#/weblogic-azure-aks/src/main/arm/'
required: true
default: oracle
testBranchNameForArtifactsLocation:
description: 'Replaced into https://raw.githubusercontent.com/#gitUserName#/weblogic-azure/#testbranchName#/weblogic-azure-aks/src/main/arm/'
required: true
default: main
# sample cURL
# curl --verbose -X POST https://api.github.com/repos/<github_user>/weblogic-azure/dispatches -H 'Accept: application/vnd.github.everest-preview+json' -H 'Authorization: token <personal_access_token>' --data '{"event_type": "aks-integration-test-with-dependency-creation", "client_payload": {"gitUserNameForArtifactsLocation": "<github_user>", "testBranchNameForArtifactsLocation": "<branch_name>", "isForDemo": "false"}}'
repository_dispatch:
types: [aks-integration-test-with-dependency-creation,integration-test-all]
env:
azureCredentials: ${{ secrets.AZURE_CREDENTIALS }}
location: eastus
resourceGroupForWlsAks: wlsd-aks-${{ github.run_id }}-${{ github.run_number }}
dbAdminUser: weblogic
dbPassword: ${{ secrets.DB_PASSWORD }}
dbName: wlsdb${{ github.run_id }}${{ github.run_number }}
ocrSSOPSW: ${{ secrets.ORC_SSOPSW }}
ocrSSOUser: ${{ secrets.ORC_SSOUSER }}
wdtRuntimePassword: ${{ secrets.WDT_RUNTIMEPSW}}
wlsUserName: ${{ secrets.WLS_USERNAME }}
wlsPassword: ${{ secrets.WLS_PSW }}
resourceGroupForDB: wlsd-db-${{ github.run_id }}-${{ github.run_number }}
resourceGroupForStorageAccount: wlsd-sa-${{ github.run_id }}-${{ github.run_number }}
storageAccountName: wlsdsa${{ github.run_id }}${{ github.run_number }}
storageContainerName: wlsdcon${{ github.run_id }}${{ github.run_number }}
jobs:
preflight:
outputs:
artifactName: ${{steps.artifact_file.outputs.artifactName}}
isForDemo: ${{ steps.setup-env-variables-based-on-dispatch-event.outputs.isForDemo }}
gitUserNameForArtifactsLocation: ${{ steps.setup-env-variables-based-on-dispatch-event.outputs.gitUserNameForArtifactsLocation }}
testBranchNameForArtifactsLocation: ${{ steps.setup-env-variables-based-on-dispatch-event.outputs.testBranchNameForArtifactsLocation }}
azCliVersion: ${{steps.get-external-dependencies-version.outputs.azCliVersion}}
runs-on: ubuntu-latest
steps:
- name: Get versions of external dependencies
id: get-external-dependencies-version
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 "azCliVersion=${AZ_CLI_VERSION}" >> $GITHUB_ENV
echo "bicepVersion=${BICEP_VERSION}" >> $GITHUB_ENV
echo "refArmttk=${ARM_TTK_REFERENCE}" >> $GITHUB_ENV
echo "azCliVersion=${AZ_CLI_VERSION}" >> $GITHUB_OUTPUT
- name: Setup environment variables
id: setup-env-variables-based-on-dispatch-event
run: |
if [ ${{ github.event_name }} == 'workflow_dispatch' ]; then
isForDemo=${{ github.event.inputs.isForDemo }}
gitUserNameForArtifactsLocation=${{ github.event.inputs.gitUserNameForArtifactsLocation }}
testBranchNameForArtifactsLocation=${{ github.event.inputs.testBranchNameForArtifactsLocation }}
else
isForDemo=${{ github.event.client_payload.isForDemo }}
gitUserNameForArtifactsLocation=${{ github.event.client_payload.gitUserNameForArtifactsLocation }}
testBranchNameForArtifactsLocation=${{ github.event.client_payload.testBranchNameForArtifactsLocation }}
fi
echo "##[set-output name=isForDemo;]${isForDemo}"
echo "##[set-output name=gitUserNameForArtifactsLocation;]${gitUserNameForArtifactsLocation}"
echo "##[set-output name=testBranchNameForArtifactsLocation;]${testBranchNameForArtifactsLocation}"
echo "isForDemo=${isForDemo}" >> $GITHUB_ENV
echo "gitUserNameForArtifactsLocation=${gitUserNameForArtifactsLocation}" >> $GITHUB_ENV
echo "testBranchNameForArtifactsLocation=${testBranchNameForArtifactsLocation}" >> $GITHUB_ENV
- uses: actions/checkout@v2.3.4
- name: Set up Maven with GitHub token
uses: ./.github/actions/setupmaven
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up bicep
run: |
curl -Lo bicep https://github.com/Azure/bicep/releases/download/${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
ref: ${{ env.refArmttk }}
- name: Checkout weblogic-azure
uses: actions/checkout@v2
with:
path: weblogic-azure
- name: Build and test weblogic-azure/weblogic-azure-aks
run: mvn -Pbicep -Passembly clean install -Ptemplate-validation-tests --file weblogic-azure/weblogic-azure-aks/pom.xml
- name: Generate artifact file name and path
id: artifact_file
run: |
version=$(mvn -q -Dexec.executable=echo -Dexec.args='${version.wls-on-aks-azure-marketplace}' --file weblogic-azure/pom.xml --non-recursive exec:exec)
artifactName=wls-on-aks-azure-marketplace-$version-arm-assembly
unzip weblogic-azure/weblogic-azure-aks/target/$artifactName.zip -d weblogic-azure/weblogic-azure-aks/target/$artifactName
echo "##[set-output name=artifactName;]${artifactName}"
echo "##[set-output name=artifactPath;]weblogic-azure/weblogic-azure-aks/target/$artifactName"
- name: Archive weblogic-azure/weblogic-azure-aks template
uses: actions/upload-artifact@v1
if: success()
with:
name: ${{steps.artifact_file.outputs.artifactName}}
path: ${{steps.artifact_file.outputs.artifactPath}}
deploy-db:
needs: preflight
runs-on: ubuntu-latest
steps:
- name: Get AZ CLI Version
run: |
echo "azCliVersion=${{needs.preflight.outputs.azCliVersion}}" >> $GITHUB_ENV
- uses: azure/login@v1
id: azure-login
with:
creds: ${{ env.azureCredentials }}
- name: Create Resource Group
uses: azure/CLI@v1
with:
azcliversion: ${{ env.azCliVersion }}
inlineScript: |
echo "create resource group" ${{ env.resourceGroupForDB }}
az group create --verbose --name ${{ env.resourceGroupForDB }} --location ${{ env.location }}
- name: Set Up Azure Postgresql to Test dbTemplate
id: setup-postgresql
uses: azure/CLI@v1
with:
azcliversion: ${{ env.azCliVersion }}
inlineScript: |
echo "Deploy DB with name " ${{ env.dbName }}
az postgres server create \
--resource-group ${{ env.resourceGroupForDB }} \
--name ${{ env.dbName }} \
--location ${{ env.location }} \
--admin-user ${{ env.dbAdminUser }} \
--ssl-enforcement Enabled \
--public-network-access Enabled \
--admin-password ${{ env.dbPassword }} \
--sku-name B_Gen5_1
sleep 1m
echo "Allow Access To Azure Services"
az postgres server firewall-rule create \
-g ${{ env.resourceGroupForDB }} \
-s ${{ env.dbName }} \
-n "AllowAllWindowsAzureIps" \
--start-ip-address "0.0.0.0" \
--end-ip-address "0.0.0.0"
deploy-storage-account:
needs: preflight
runs-on: ubuntu-latest
steps:
- name: Get AZ CLI Version
run: |
echo "azCliVersion=${{needs.preflight.outputs.azCliVersion}}" >> $GITHUB_ENV
- name: Checkout Azure-Samples/cargotracker-wls-aks
uses: actions/checkout@v2
with:
repository: Azure-Samples/cargotracker-wls-aks
path: cargotracker
- name: Maven build web app
run: |
mvn clean install -PweblogicOnAks --file cargotracker/pom.xml
- name: Query version string for deployment verification
run: |
PROPERTY_FILE="cargotracker/target/cargo-tracker/WEB-INF/classes/org/eclipse/cargotracker/messages.properties"
PROP_KEY=versionString
deployVersion=$(cat $PROPERTY_FILE | grep "$PROP_KEY" | cut -d '=' -f 2)
echo "deployVersion=${deployVersion}" >> $GITHUB_ENV
- uses: azure/login@v1
id: azure-login
with:
creds: ${{ env.azureCredentials }}
- name: Create Resource Group
uses: azure/CLI@v1
with:
azcliversion: ${{ env.azCliVersion }}
inlineScript: |
echo "create resource group" ${{ env.resourceGroupForStorageAccount }}
az group create --verbose --name ${{ env.resourceGroupForStorageAccount }} --location ${{ env.location }}
- name: Create Storage Account
uses: azure/CLI@v1
with:
azcliversion: ${{ env.azCliVersion }}
inlineScript: |
az storage account create --name ${{ env.storageAccountName }} \
--resource-group ${{ env.resourceGroupForStorageAccount }} \
--location ${{ env.location }} \
--sku Standard_LRS \
--kind StorageV2
- name: Create Storage Container
uses: azure/CLI@v1
with:
azcliversion: ${{ env.azCliVersion }}
inlineScript: |
az storage container create -n ${{ env.storageContainerName }} --account-name ${{ env.storageAccountName }}
- name: Upload built web app war file
uses: azure/CLI@v1
with:
azcliversion: ${{ env.azCliVersion }}
inlineScript: |
az storage blob upload --account-name ${{ env.storageAccountName }} --container-name ${{ env.storageContainerName }} --file cargotracker/target/cargo-tracker.war --name cargo-tracker.war
deploy-wls-on-aks:
needs: [deploy-storage-account, deploy-db, preflight]
runs-on: ubuntu-latest
steps:
- name: Get AZ CLI Version
run: |
echo "azCliVersion=${{needs.preflight.outputs.azCliVersion}}" >> $GITHUB_ENV
- name: Checkout weblogic-azure
uses: actions/checkout@v2
with:
path: weblogic-azure
- name: Download artifact for deployment
uses: actions/download-artifact@v1
with:
name: ${{needs.preflight.outputs.artifactName}}
- uses: azure/login@v1
id: azure-login
with:
creds: ${{ env.azureCredentials }}
- name: Query web app blob url and set to env
uses: azure/CLI@v1
with:
azcliversion: ${{ env.azCliVersion }}
inlineScript: |
sasTokenValidTime=3600
expiryData=$(( `date +%s`+${sasTokenValidTime}))
sasEnd=`date -d@"$expiryData" -u '+%Y-%m-%dT%H:%MZ'`
sasToken=$(az storage account generate-sas \
--permissions r \
--account-name ${{ env.storageAccountName }} \
--services b \
--resource-types sco \
--expiry $sasEnd -o tsv)
cargoTrackerBlobUrl=$(az storage blob url \
--container-name ${{ env.storageContainerName }} \
--name cargo-tracker.war \
--account-name ${{ env.storageAccountName }} \
--sas-token ${sasToken} -o tsv)
echo "cargoTrackerBlobUrl=${cargoTrackerBlobUrl}" >> $GITHUB_ENV
- name: Create Resource Group
uses: azure/CLI@v1
with:
azcliversion: ${{ env.azCliVersion }}
inlineScript: |
echo "create resource group" ${{ env.resourceGroupForWlsAks }}
az group create --verbose --name ${{ env.resourceGroupForWlsAks }} --location ${{ env.location }}
- name: Checkout Azure-Samples/cargotracker-wls-aks
uses: actions/checkout@v2
with:
repository: Azure-Samples/cargotracker-wls-aks
path: cargotracker
- name: Prepare parameter file
run: |
echo "generate parameter file"
bash weblogic-azure/weblogic-azure-aks/src/test/genWlsAksParameters.sh \
${{ needs.preflight.outputs.gitUserNameForArtifactsLocation }} \
${{ needs.preflight.outputs.testBranchNameForArtifactsLocation }} \
"${cargoTrackerBlobUrl}" \
${dbPassword} \
${dbAdminUser}@${dbName} \
jdbc:postgresql:\/\/${dbName}.postgres.database.azure.com:5432\/postgres \
${location} \
${ocrSSOPSW} \
${ocrSSOUser} \
${wdtRuntimePassword} \
${wlsPassword} \
${wlsUserName} \
weblogic-azure/weblogic-azure-aks/src/test/setupWlsAksParameters.jsonc
- name: Deploy WebLogic Server Cluster Domain offer
id: deploy-wls-cluster
uses: azure/CLI@v1
with:
azcliversion: ${{ env.azCliVersion }}
inlineScript: |
artifactName=${{ needs.preflight.outputs.artifactName }}
az deployment group create \
--verbose \
--resource-group ${{ env.resourceGroupForWlsAks }} \
--name wls-on-aks \
--parameters @weblogic-azure/weblogic-azure-aks/src/test/setupWlsAksParameters.jsonc \
--template-file ${artifactName}/mainTemplate.json
- name: Query Application Gateway URL
run: |
appgatewayname=$(az resource list --resource-group ${{ env.resourceGroupForWlsAks }} --query "[?type=='Microsoft.Network/applicationGateways'].name|[0]" -o tsv)
echo $appgatewayname
publicIpAddressId=$(az network application-gateway show --resource-group ${{ env.resourceGroupForWlsAks }} --name ${appgatewayname} --query frontendIPConfigurations[0].publicIPAddress.id -o tsv)
echo $publicIpAddressId
appGatewayURL=$(az network public-ip show --resource-group ${{ env.resourceGroupForWlsAks }} --ids ${publicIpAddressId} --query dnsSettings.fqdn -o tsv)
echo $appGatewayURL
echo "appGatewayURL=${appGatewayURL}" >> $GITHUB_ENV
- name: Verify Cargo Tracker is deployed as expected
run: |
echo "Verifying Cargo Tracker is deployed as expected"
curl --verbose http://${{ env.appGatewayURL }}/cargo-tracker/
response=$(curl --write-out '%{http_code}' --silent --output /dev/null http://${{ env.appGatewayURL }}/cargo-tracker/)
echo "$response"
if [ "$response" -ne 200 ]; then
echo "Cargo Tracker is not accessible"
exit 1
else
echo "Cargo Tracker is accessible"
fi
- name: Install kubectl
run: |
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
curl -LO "https://dl.k8s.io/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
kubectl version --client
- name: Connect to AKS cluster
run: |
echo "connect to cluster"
aksClusterName=$(az resource list --resource-group ${{ env.resourceGroupForWlsAks }} --query "[?type=='Microsoft.ContainerService/managedClusters'].name|[0]" -o tsv)
az aks get-credentials --resource-group ${{ env.resourceGroupForWlsAks }} --name $aksClusterName
- name: Generate&Apply configmap
run: |
wlsConfigmapName=sample-domain1-wdt-config-map
wlsConfigmapJson=cargo-tracker-db.json
modelFilePath=models
mkdir ${modelFilePath}
echo "create configmap"
echo "export exisiting configmap"
kubectl -n sample-domain1-ns get configmap ${wlsConfigmapName} -o json >${wlsConfigmapJson}
echo "query model keys"
keyList=$(cat ${wlsConfigmapJson} | jq '.data | keys[]' | tr -d "\"")
for item in $keyList; do
data=$(cat ${wlsConfigmapJson} | jq ".data[\"${item}\"]")
data=$(echo "${data:1:${#data}-2}")
echo -e "${data}" >${modelFilePath}/${item}
done
# remove current configmap and create a new one
kubectl -n sample-domain1-ns delete configmap ${wlsConfigmapName}
cp cargotracker/src/test/aks/cargo-tracker-jms.yaml ${modelFilePath}/cargo-tracker-jms.yaml
kubectl -n sample-domain1-ns create configmap ${wlsConfigmapName} \
--from-file=${modelFilePath}
kubectl -n sample-domain1-ns label configmap ${wlsConfigmapName} \
weblogic.domainUID=sample-domain1
restartVersion=$(kubectl -n sample-domain1-ns get domain sample-domain1 '-o=jsonpath={.spec.restartVersion}')
# increase restart version
restartVersion=$((restartVersion + 1))
# record timestamp before apply changes
timestampBeforePatchingDomain=$(date +%s)
# get the replica number
replicas=$(kubectl -n sample-domain1-ns get domain sample-domain1 -o json | jq '. | .spec.clusters[] | .replicas')
echo "append configmap and update restart version"
kubectl -n sample-domain1-ns patch domain sample-domain1 \
--type=json \
'-p=[{"op": "replace", "path": "/spec/restartVersion", "value": "'${restartVersion}'" }, {"op": "add", "path": "/spec/configuration/model/configMap", "value": "'${wlsConfigmapName}'" }]'
echo "timestampBeforePatchingDomain=${timestampBeforePatchingDomain}" >> $GITHUB_ENV
echo "replicas=${replicas}" >> $GITHUB_ENV
- name: Verify pods are restarted
run: |
# interval of checking pod status.
checkPodStatusInterval=20
# max attempt to check pod status.
checkPodStatusMaxAttemps=30
# domain and namespaces
wlsDomainUID="sample-domain1"
wlsDomainNS=${wlsDomainUID}-ns
updatedPodNum=0
attempt=0
echo $timestampBeforePatchingDomain $appReplicas $wlsDomainUID $checkPodStatusMaxAttemps $checkPodStatusInterval
while [[ ${updatedPodNum} -le ${appReplicas} ]] && [[ $attempt -le ${checkPodStatusMaxAttemps} ]]; do
echo "attempts ${attempt}"
ret=$(kubectl get pods -n ${wlsDomainNS} -l weblogic.domainUID=${wlsDomainUID} -o json | jq '.items[] | .metadata.creationTimestamp' | tr -d "\"")
counter=0
for item in $ret; do
podCreateTimeStamp=$(date -u -d "${item}" +"%s")
echo "pod create time: $podCreateTimeStamp, base time: ${timestampBeforePatchingDomain}"
if [[ ${podCreateTimeStamp} -gt ${timestampBeforePatchingDomain} ]]; then
counter=$((counter + 1))
fi
done
updatedPodNum=$counter
echo "Number of new pod: ${updatedPodNum}"
attempt=$((attempt + 1))
sleep ${checkPodStatusInterval}
done
if [[ ${attempt} -gt ${checkPodStatusMaxAttemps} ]]; then
echo "Failed to restart all weblogic server pods. "
exit 1
fi
cleanup:
needs: [deploy-wls-on-aks, preflight]
if: ${{ needs.preflight.outputs.isForDemo == 'false' }}
runs-on: ubuntu-latest
steps:
- name: Get AZ CLI Version
run: |
echo "azCliVersion=${{needs.preflight.outputs.azCliVersion}}" >> $GITHUB_ENV
- uses: azure/login@v1
id: azure-login
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Delete Storage Account Resource Group
id: delete-sa-resource-group
uses: azure/CLI@v1
with:
azcliversion: ${{ env.azCliVersion }}
inlineScript: |
echo "delete... " ${{ env.resourceGroupForStorageAccount }}
az group delete --yes --no-wait --verbose --name ${{ env.resourceGroupForStorageAccount }}
- name: Delete DB Resource Group
id: delete-db-resource-group
uses: azure/CLI@v1
with:
azcliversion: ${{ env.azCliVersion }}
inlineScript: |
echo "delete... " ${{ env.resourceGroupForDB }}
az group delete --yes --no-wait --verbose --name ${{ env.resourceGroupForDB }}
- name: Delete AKS Resource Group
id: delete-aks-resource-group
uses: azure/CLI@v1
with:
azcliversion: ${{ env.azCliVersion }}
inlineScript: |
echo "delete... " ${{ env.resourceGroupForWlsAks }}
az group delete --yes --no-wait --verbose --name ${{ env.resourceGroupForWlsAks }}