Skip to content

Commit 1fd6ac8

Browse files
authored
Pipeline - Adding swapping for the production slot (#2302)
1 parent 226f479 commit 1fd6ac8

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

.github/workflows/build-and-deploy.yml

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,31 @@ jobs:
101101
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
102102
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
103103

104+
- name: Set deployment slot
105+
id: slot
106+
run: |
107+
ENVIRONMENT="${{ github.event.inputs.environment || 'staging' }}"
108+
if [ "$ENVIRONMENT" = "production" ]; then
109+
echo "slot_name=pre-production" >> $GITHUB_OUTPUT
110+
echo "Deploying to pre-production slot for production environment"
111+
else
112+
echo "slot_name=" >> $GITHUB_OUTPUT
113+
echo "Deploying without slot (staging environment)"
114+
fi
115+
104116
- name: Configure Auth0 and Build Info app settings
105117
run: |
118+
SLOT_NAME="${{ steps.slot.outputs.slot_name }}"
119+
if [ -n "$SLOT_NAME" ]; then
120+
SLOT_FLAG="--slot $SLOT_NAME"
121+
else
122+
SLOT_FLAG=""
123+
fi
124+
106125
az webapp config appsettings set \
107126
--name ${{ secrets.AZURE_WEBAPP_NAME }} \
108127
--resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \
128+
$SLOT_FLAG \
109129
--settings \
110130
TINA_WEBHOOK_SECRET=${{ secrets.TINA_WEBHOOK_SECRET }} \
111131
AUTH0_DOMAIN=${{ vars.AUTH0_DOMAIN }} \
@@ -131,11 +151,31 @@ jobs:
131151
COMMIT_HASH=${{ env.COMMIT_HASH }} \
132152
--output none
133153
134-
- name: Deploy to Azure Web App
154+
- name: Deploy to Azure Web App (Production with slot)
155+
if: github.event.inputs.environment == 'production'
135156
uses: azure/webapps-deploy@v3
136157
with:
137158
app-name: ${{ secrets.AZURE_WEBAPP_NAME }}
138159
images: ${{ needs.build.outputs.image_tag }}
160+
slot-name: ${{ steps.slot.outputs.slot_name }}
161+
162+
- name: Deploy to Azure Web App (Staging)
163+
if: github.event.inputs.environment != 'production'
164+
uses: azure/webapps-deploy@v3
165+
with:
166+
app-name: ${{ secrets.AZURE_WEBAPP_NAME }}
167+
images: ${{ needs.build.outputs.image_tag }}
168+
169+
- name: Swap slots (production only)
170+
if: github.event.inputs.environment == 'production'
171+
run: |
172+
echo "🔄 Swapping pre-production slot with production slot..."
173+
az webapp deployment slot swap \
174+
--name ${{ secrets.AZURE_WEBAPP_NAME }} \
175+
--resource-group ${{ secrets.AZURE_RESOURCE_GROUP }} \
176+
--slot pre-production \
177+
--target-slot production
178+
echo "✅ Slot swap completed successfully!"
139179
140180
- name: Verify deployment
141181
run: |

0 commit comments

Comments
 (0)