Skip to content

DEPLOY-TO-AZURE

DEPLOY-TO-AZURE #37

name: DEPLOY-TO-AZURE
on:
workflow_dispatch:
permissions:
teams:
- 'reactor/team'
permissions: read-all
env:
GROUP_NAME: ${{ secrets.AZURE_GROUP_NAME }}
SERVICE_NAME: ${{ secrets.AZURE_SERVICE_NAME }}
APP_NAME: ${{ secrets.AZURE_APP_NAME }}
JAR_PATH: ${{ github.workspace }}/build/libs/projectreactor-home.jar
DEFAULT_DEPLOYMENT: blue
NEW_DEPLOYMENT: green
jobs:
deploy:
runs-on: ubuntu-latest
outputs:
NEWDEPLOYMENT: ${{ steps.deploy.outputs.NEWDEPLOYMENT }}
ACTIVEDEPLOYMENT: ${{ steps.deploy.outputs.ACTIVEDEPLOYMENT }}
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4
- uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4
with:
distribution: 'temurin'
java-version: 8
- name: Build
uses: gradle/gradle-build-action@4c39dd82cd5e1ec7c6fa0173bb41b4b6bb3b86ff # v3
with:
arguments: build -x spotlessCheck
- name: Login Via Azure CLI
uses: azure/login@6c251865b4e6290e7b78be643ea2d005bc51f69a # v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS_SPRING_IO }}
- name: Deploy To Staging
uses: azure/CLI@965c8d7571d2231a54e321ddd07f7b10317f34d9 # v2
id: deploy
with:
inlineScript: |
az extension add --name spring
# Create the Azure app if it does not already exist
APP_EXISTS=$(az spring app show --resource-group ${{ env.GROUP_NAME }} --service ${{ env.SERVICE_NAME }} --name ${{ env.APP_NAME }} 2>/dev/null)
if [[ -z "$APP_EXISTS" ]]; then
echo "creating app ..."
az spring app create \
--resource-group ${{ env.GROUP_NAME }} \
--service ${{ env.SERVICE_NAME }} \
--name ${{ env.APP_NAME }} \
--deployment-name ${{ env.DEFAULT_DEPLOYMENT }} \
--assign-endpoint \
--memory 2Gi
fi
ACTIVEDEPLOYMENT=$(az spring app show -n ${{env.APP_NAME}} --query properties.activeDeployment.name -o tsv -s ${{env.SERVICE_NAME}} -g ${{env.GROUP_NAME}})
if [ "$ACTIVEDEPLOYMENT" = "${{env.DEFAULT_DEPLOYMENT}}" ]; then
NEWDEPLOYMENT="${{env.NEW_DEPLOYMENT}}"
else
NEWDEPLOYMENT="${{env.DEFAULT_DEPLOYMENT}}"
fi
echo 'new deployment: ' $NEWDEPLOYMENT
echo 'active deployment': $ACTIVEDEPLOYMENT
echo "NEWDEPLOYMENT=$NEWDEPLOYMENT" >> $GITHUB_OUTPUT
echo "ACTIVEDEPLOYMENT=$ACTIVEDEPLOYMENT" >> $GITHUB_OUTPUT
NEWDEPLOYMENTEXISTS=$(az spring app deployment list --app ${{env.APP_NAME}} --query "[?name=='$NEWDEPLOYMENT'].name" -o tsv -s ${{env.SERVICE_NAME}} -g ${{env.GROUP_NAME}})
if [ "$NEWDEPLOYMENTEXISTS" = "$NEWDEPLOYMENT" ]; then
echo $NEWDEPLOYMENT ' already exists'
else
echo 'creating deployment ' $NEWDEPLOYMENT
az spring app deployment create --app ${{env.APP_NAME}} -n $NEWDEPLOYMENT -s ${{env.SERVICE_NAME}} -g ${{env.GROUP_NAME}}
fi
echo 'workspace:' ${{ github.workspace }}
az spring app deploy -n ${{env.APP_NAME}} --artifact-path ${{env.JAR_PATH}} -d $NEWDEPLOYMENT -s ${{env.SERVICE_NAME}} -g ${{env.GROUP_NAME}} \
--build-env BP_JVM_VERSION=11 --jvm-options='-Xmx1g -Xms1g'
switch-to-production:
runs-on: ubuntu-latest
needs: deploy
steps:
- uses: azure/login@6c251865b4e6290e7b78be643ea2d005bc51f69a # v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS_SPRING_IO }}
- name: Set Staging To Production
uses: azure/CLI@965c8d7571d2231a54e321ddd07f7b10317f34d9 # v2
with:
inlineScript: |
az extension add --name spring
az spring app set-deployment -d ${{ needs.deploy.outputs.NEWDEPLOYMENT }} -n ${{env.APP_NAME}} -s ${{env.SERVICE_NAME}} -g ${{env.GROUP_NAME}}
az spring app deployment delete --app ${{env.APP_NAME}} -n ${{ needs.deploy.outputs.ACTIVEDEPLOYMENT }} -s ${{env.SERVICE_NAME}} -g ${{env.GROUP_NAME}}