appservice/deploy-to-deployment-slot/README.md #152
This file contains 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
on: | |
schedule: | |
- cron: '0 5 * * 4' | |
workflow_dispatch: | |
name: 'appservice/deploy-to-deployment-slot/README.md' | |
jobs: | |
validate: | |
runs-on: 'ubuntu-latest' | |
steps: | |
- uses: 'azure/login@v1' | |
with: | |
subscription-id: '${{ secrets.AZURE_SUBSCRIPTION_ID }}' | |
client-id: '${{ secrets.AZURE_CLIENT_ID }}' | |
tenant-id: '${{ secrets.AZURE_TENANT_ID }}' | |
- uses: 'actions/checkout@v3' | |
- run: | | |
if [[ -z $REGION ]]; then | |
export REGION=westus | |
fi | |
if [[ -z $REGION ]]; then | |
export REGION=westus | |
fi | |
if [[ -z $REGION ]]; then | |
export REGION=westus | |
fi | |
if [[ -z $REGION ]]; then | |
export REGION=westus | |
fi | |
if [[ -z $REGION ]]; then | |
export REGION=westus | |
fi | |
if [[ -z $RESOURCE_GROUP ]]; then | |
export RESOURCE_GROUP=joazrg-$RANDOM | |
echo "Using '"$RESOURCE_GROUP"' as resource group" | |
fi | |
az group create --name $RESOURCE_GROUP --location $REGION | |
if [[ -z $APPSERVICE_PLAN ]]; then | |
export APPSERVICE_PLAN=joaz-asp-$RANDOM | |
fi | |
az appservice plan create \ | |
--resource-group $RESOURCE_GROUP \ | |
--location $REGION \ | |
--name $APPSERVICE_PLAN \ | |
--is-linux \ | |
--sku P1v3 | |
cd appservice/tomcat-helloworld | |
mvn clean install | |
export APPSERVICE_TOMCAT_HELLOWORLD=appservice-tomcat-helloworld-$RANDOM | |
mvn azure-webapp:deploy \ | |
-DappName=$APPSERVICE_TOMCAT_HELLOWORLD \ | |
-DappServicePlan=$APPSERVICE_PLAN \ | |
-DresourceGroup=$RESOURCE_GROUP | |
sleep 60 | |
cd ../.. | |
az webapp deployment slot create \ | |
--resource-group $RESOURCE_GROUP \ | |
--name $APPSERVICE_TOMCAT_HELLOWORLD \ | |
--slot staging | |
az webapp show --name $APPSERVICE_TOMCAT_HELLOWORLD \ | |
--resource-group $RESOURCE_GROUP \ | |
--query=defaultHostName | |
az webapp deployment slot list --name $APPSERVICE_TOMCAT_HELLOWORLD \ | |
--resource-group $RESOURCE_GROUP \ | |
--query='[0].defaultHostName' | |
cd appservice/deploy-to-deployment-slot | |
mvn clean install | |
mvn azure-webapp:deploy \ | |
-DappName=$APPSERVICE_TOMCAT_HELLOWORLD \ | |
-DappServicePlan=$APPSERVICE_PLAN \ | |
-DresourceGroup=$RESOURCE_GROUP \ | |
-DdeploymentSlotName=staging | |
sleep 60 | |
cd ../.. | |
export RESULT=$(az webapp deployment slot list --resource-group $RESOURCE_GROUP --name $APPSERVICE_TOMCAT_HELLOWORLD --output tsv --query '[0].state') | |
if [[ "$RESULT" != Running ]]; then | |
echo 'Deployment slot is NOT running' | |
az group delete --name $RESOURCE_GROUP --yes || true | |
exit 1 | |
fi | |
sleep 60 | |
export URL=https://$(az webapp deployment slot list --resource-group $RESOURCE_GROUP --name $APPSERVICE_TOMCAT_HELLOWORLD --output tsv --query '[0].defaultHostName') | |
export RESULT=$(curl $URL) | |
az group delete --name $RESOURCE_GROUP --yes || true | |
if [[ "$RESULT" != *"Hello Staging"* ]]; then | |
echo "Response did not contain 'Hello Staging'" | |
exit 1 | |
fi | |
permissions: | |
contents: 'read' | |
id-token: 'write' |