Skip to content

Commit 3f13d6e

Browse files
authored
Merge pull request github#29954 from github/repo-sync
Repo sync
2 parents 9d6ca7d + cdafb46 commit 3f13d6e

File tree

9 files changed

+284
-272
lines changed

9 files changed

+284
-272
lines changed

.github/workflows/azure-prod-build-deploy.yml

+6-59
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ jobs:
3131
env:
3232
DOCKER_IMAGE: ${{ secrets.PROD_REGISTRY_SERVER }}/${{ github.repository }}:${{ github.sha }}
3333
DOCKER_IMAGE_CACHE_REF: ${{ secrets.PROD_REGISTRY_SERVER }}/${{ github.repository }}:main-production
34+
RESOURCE_GROUP_NAME: docs-prod
35+
APP_SERVICE_NAME: ghdocs-prod
36+
SLOT_NAME: canary
3437

3538
steps:
3639
- name: 'Az CLI login'
@@ -97,75 +100,19 @@ jobs:
97100
98101
- name: 'Apply updated docker-compose.prod.yaml config to canary slot'
99102
run: |
100-
az webapp config container set --multicontainer-config-type COMPOSE --multicontainer-config-file docker-compose.prod.yaml --slot canary -n ghdocs-prod -g docs-prod
103+
az webapp config container set --multicontainer-config-type COMPOSE --multicontainer-config-file docker-compose.prod.yaml --slot ${{ env.SLOT_NAME }} -n ${{ env.APP_SERVICE_NAME }} -g ${{ env.RESOURCE_GROUP_NAME }}
101104
102105
# Watch canary slot instances to see when all the instances are ready
103106
- name: Check that canary slot is ready
104-
uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975
105107
env:
106108
CHECK_INTERVAL: 10000
107109
EXPECTED_SHA: ${{ github.sha }}
108110
CANARY_BUILD_URL: https://ghdocs-prod-canary.azurewebsites.net/_build
109-
with:
110-
script: |
111-
const { execSync } = require('child_process')
112-
113-
const getBuildSha = (timeoutSeconds = 5) => {
114-
const url = process.env.CANARY_BUILD_URL;
115-
console.log(`Fetching ${url}`);
116-
const t0 = Date.now();
117-
try {
118-
const o = execSync(`curl --connect-timeout ${timeoutSeconds} ${url}`, {
119-
encoding: "utf8",
120-
});
121-
console.log(`Fetched ${url}. Took ${Date.now() - t0}ms`);
122-
return o.toString().trim();
123-
} catch (err) {
124-
console.log(`Error fetching build sha from ${url}`);
125-
return null;
126-
}
127-
};
128-
129-
const getStatesForSlot = (slot) => {
130-
return JSON.parse(
131-
execSync(
132-
`az webapp list-instances --slot ${slot} --query "[].state" -n ghdocs-prod -g docs-prod`,
133-
{ encoding: 'utf8' }
134-
)
135-
)
136-
}
137-
138-
const waitDuration = parseInt(process.env.CHECK_INTERVAL, 10) || 10000
139-
let attempts = 0
140-
async function doCheck() {
141-
attempts++
142-
console.log('Attempt:', attempts);
143-
const buildSha = getBuildSha();
144-
console.log("Canary build SHA:", buildSha || "*unknown/failed*", "Expected SHA:", process.env.EXPECTED_SHA)
145-
146-
const states = getStatesForSlot('canary')
147-
console.log('Instance states:', states)
148-
149-
const isAllReady = states.every((s) => s === 'READY')
150-
151-
if (buildSha === process.env.EXPECTED_SHA && isAllReady) {
152-
process.exit(0) // success
153-
}
154-
155-
if (attempts * waitDuration > 10 * 60 * 1000) {
156-
console.log(`Giving up after a total of ${(attempts * waitDuration)/1000} seconds`)
157-
process.exit(1) // failure
158-
}
159-
160-
console.log(`checking again in ${waitDuration}ms`)
161-
setTimeout(doCheck, waitDuration)
162-
}
163-
164-
doCheck()
111+
run: src/workflows/check-canary-slots.js
165112

166113
- name: 'Swap canary slot to production'
167114
run: |
168-
az webapp deployment slot swap --slot canary --target-slot production -n ghdocs-prod -g docs-prod
115+
az webapp deployment slot swap --slot ${{ env.SLOT_NAME }} --target-slot production -n ${{ env.APP_SERVICE_NAME }} -g ${{ env.RESOURCE_GROUP_NAME }}
169116
170117
- uses: ./.github/actions/slack-alert
171118
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}

.github/workflows/azure-staging-build-deploy.yml

+3-41
Original file line numberDiff line numberDiff line change
@@ -110,49 +110,11 @@ jobs:
110110
111111
# Watch deployment slot instances to see when all the instances are ready
112112
- name: Check that deployment slot is ready
113-
uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975
114113
env:
115114
CHECK_INTERVAL: 10000
116-
with:
117-
script: |
118-
const { execSync } = require('child_process')
119-
120-
const slotName = process.env.SLOT_NAME
121-
const appServiceName = process.env.APP_SERVICE_NAME
122-
const resourceGroupName = process.env.RESOURCE_GROUP_NAME
123-
124-
const getStatesForSlot = (slot, appService, resourceGroup) => {
125-
return JSON.parse(
126-
execSync(
127-
`az webapp list-instances --slot ${slot} --query "[].state" -n ${appService} -g ${resourceGroup}`,
128-
{ encoding: 'utf8' }
129-
)
130-
)
131-
}
132-
133-
let hasStopped = false
134-
const waitDuration = parseInt(process.env.CHECK_INTERVAL, 10) || 10000
135-
async function doCheck() {
136-
const states = getStatesForSlot(slotName, appServiceName, resourceGroupName)
137-
console.log(`Instance states:`, states)
138-
139-
// We must wait until at-least 1 instance has STOPPED to know we're looking at the "next" deployment and not the "previous" one
140-
// That way we don't immediately succeed just because all the previous instances were READY
141-
if (!hasStopped) {
142-
hasStopped = states.some((s) => s === 'STOPPED')
143-
}
144-
145-
const isAllReady = states.every((s) => s === 'READY')
146-
147-
if (hasStopped && isAllReady) {
148-
process.exit(0) // success
149-
}
150-
151-
console.log(`checking again in ${waitDuration}ms`)
152-
setTimeout(doCheck, waitDuration)
153-
}
154-
155-
doCheck()
115+
EXPECTED_SHA: ${{ github.sha }}
116+
CANARY_BUILD_URL: https://ghdocs-staging-canary.azurewebsites.net/_build
117+
run: src/workflows/check-canary-slots.js
156118

157119
- name: 'Swap deployment slot to production'
158120
run: |

0 commit comments

Comments
 (0)