Skip to content

DEPLOY-TO-AZURE

DEPLOY-TO-AZURE #83

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@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b # v4
with:
distribution: 'temurin'
java-version: 8
- name: Setup Gradle
uses: gradle/actions/setup-gradle@707359876a764dbcdb9da0b0ed08291818310c3d
- name: Build
run: ./gradlew build -x spotlessCheck
- name: Login Via Azure CLI
uses: azure/login@a65d910e8af852a8061c627c456678983e180302 # v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS_SPRING_IO }}
- name: Deploy To Staging
uses: azure/CLI@089eac9d8cc39f5d003e94f8b65efc51076c9cbd # 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@a65d910e8af852a8061c627c456678983e180302 # v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS_SPRING_IO }}
- name: Set Staging To Production
uses: azure/CLI@089eac9d8cc39f5d003e94f8b65efc51076c9cbd # 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}}