Skip to content

Commit aa3bf65

Browse files
committed
make mooncake upload configurable
1 parent 4c79da6 commit aa3bf65

File tree

5 files changed

+68
-28
lines changed

5 files changed

+68
-28
lines changed

build/azure-pipelines/common/createAsset.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,23 +155,36 @@ async function main() {
155155
console.log(`Blob ${quality}, ${blobName} already exists, not publishing again.`);
156156
return;
157157
}
158-
const mooncakeCredential = new identity_1.ClientSecretCredential(process.env['AZURE_MOONCAKE_TENANT_ID'], process.env['AZURE_MOONCAKE_CLIENT_ID'], process.env['AZURE_MOONCAKE_CLIENT_SECRET']);
159-
const mooncakeBlobServiceClient = new storage_blob_1.BlobServiceClient(`https://vscode.blob.core.chinacloudapi.cn`, mooncakeCredential, storagePipelineOptions);
160-
const mooncakeContainerClient = mooncakeBlobServiceClient.getContainerClient(quality);
161-
const mooncakeBlobClient = mooncakeContainerClient.getBlockBlobClient(blobName);
162-
console.log('Uploading blobs to Azure storage and Mooncake Azure storage...');
163158
const blobOptions = {
164159
blobHTTPHeaders: {
165160
blobContentType: mime.lookup(filePath),
166161
blobContentDisposition: `attachment; filename="${fileName}"`,
167162
blobCacheControl: 'max-age=31536000, public'
168163
}
169164
};
170-
await (0, retry_1.retry)(() => Promise.all([
171-
blobClient.uploadFile(filePath, blobOptions),
172-
mooncakeBlobClient.uploadFile(filePath, blobOptions)
173-
]));
174-
console.log('Blobs successfully uploaded.');
165+
const uploadPromises = [
166+
(0, retry_1.retry)(async () => {
167+
await blobClient.uploadFile(filePath, blobOptions);
168+
console.log('Blob successfully uploaded to Azure storage.');
169+
})
170+
];
171+
const shouldUploadToMooncake = /true/i.test(process.env['VSCODE_PUBLISH_TO_MOONCAKE'] ?? 'true');
172+
if (shouldUploadToMooncake) {
173+
const mooncakeCredential = new identity_1.ClientSecretCredential(process.env['AZURE_MOONCAKE_TENANT_ID'], process.env['AZURE_MOONCAKE_CLIENT_ID'], process.env['AZURE_MOONCAKE_CLIENT_SECRET']);
174+
const mooncakeBlobServiceClient = new storage_blob_1.BlobServiceClient(`https://vscode.blob.core.chinacloudapi.cn`, mooncakeCredential, storagePipelineOptions);
175+
const mooncakeContainerClient = mooncakeBlobServiceClient.getContainerClient(quality);
176+
const mooncakeBlobClient = mooncakeContainerClient.getBlockBlobClient(blobName);
177+
uploadPromises.push((0, retry_1.retry)(async () => {
178+
await mooncakeBlobClient.uploadFile(filePath, blobOptions);
179+
console.log('Blob successfully uploaded to Mooncake Azure storage.');
180+
}));
181+
console.log('Uploading blobs to Azure storage and Mooncake Azure storage...');
182+
}
183+
else {
184+
console.log('Uploading blobs to Azure storage...');
185+
}
186+
await uploadPromises;
187+
console.log('All blobs successfully uploaded.');
175188
const assetUrl = `${process.env['AZURE_CDN_URL']}/${quality}/${blobName}`;
176189
const blobPath = new URL(assetUrl).pathname;
177190
const mooncakeUrl = `${process.env['MOONCAKE_CDN_URL']}${blobPath}`;

build/azure-pipelines/common/createAsset.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,6 @@ async function main(): Promise<void> {
187187
return;
188188
}
189189

190-
const mooncakeCredential = new ClientSecretCredential(process.env['AZURE_MOONCAKE_TENANT_ID']!, process.env['AZURE_MOONCAKE_CLIENT_ID']!, process.env['AZURE_MOONCAKE_CLIENT_SECRET']!);
191-
const mooncakeBlobServiceClient = new BlobServiceClient(`https://vscode.blob.core.chinacloudapi.cn`, mooncakeCredential, storagePipelineOptions);
192-
const mooncakeContainerClient = mooncakeBlobServiceClient.getContainerClient(quality);
193-
const mooncakeBlobClient = mooncakeContainerClient.getBlockBlobClient(blobName);
194-
195-
console.log('Uploading blobs to Azure storage and Mooncake Azure storage...');
196-
197190
const blobOptions: BlockBlobParallelUploadOptions = {
198191
blobHTTPHeaders: {
199192
blobContentType: mime.lookup(filePath),
@@ -202,12 +195,33 @@ async function main(): Promise<void> {
202195
}
203196
};
204197

205-
await retry(() => Promise.all([
206-
blobClient.uploadFile(filePath, blobOptions),
207-
mooncakeBlobClient.uploadFile(filePath, blobOptions)
208-
]));
198+
const uploadPromises: Promise<void>[] = [
199+
retry(async () => {
200+
await blobClient.uploadFile(filePath, blobOptions);
201+
console.log('Blob successfully uploaded to Azure storage.');
202+
})
203+
];
204+
205+
const shouldUploadToMooncake = /true/i.test(process.env['VSCODE_PUBLISH_TO_MOONCAKE'] ?? 'true');
206+
207+
if (shouldUploadToMooncake) {
208+
const mooncakeCredential = new ClientSecretCredential(process.env['AZURE_MOONCAKE_TENANT_ID']!, process.env['AZURE_MOONCAKE_CLIENT_ID']!, process.env['AZURE_MOONCAKE_CLIENT_SECRET']!);
209+
const mooncakeBlobServiceClient = new BlobServiceClient(`https://vscode.blob.core.chinacloudapi.cn`, mooncakeCredential, storagePipelineOptions);
210+
const mooncakeContainerClient = mooncakeBlobServiceClient.getContainerClient(quality);
211+
const mooncakeBlobClient = mooncakeContainerClient.getBlockBlobClient(blobName);
212+
213+
uploadPromises.push(retry(async () => {
214+
await mooncakeBlobClient.uploadFile(filePath, blobOptions);
215+
console.log('Blob successfully uploaded to Mooncake Azure storage.');
216+
}));
217+
218+
console.log('Uploading blobs to Azure storage and Mooncake Azure storage...');
219+
} else {
220+
console.log('Uploading blobs to Azure storage...');
221+
}
209222

210-
console.log('Blobs successfully uploaded.');
223+
await uploadPromises;
224+
console.log('All blobs successfully uploaded.');
211225

212226
const assetUrl = `${process.env['AZURE_CDN_URL']}/${quality}/${blobName}`;
213227
const blobPath = new URL(assetUrl).pathname;

build/azure-pipelines/common/retry.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,23 @@
66
Object.defineProperty(exports, "__esModule", { value: true });
77
exports.retry = void 0;
88
async function retry(fn) {
9+
let lastError;
910
for (let run = 1; run <= 10; run++) {
1011
try {
1112
return await fn();
1213
}
1314
catch (err) {
14-
if (!/ECONNRESET/.test(err.message)) {
15+
if (!/ECONNRESET|CredentialUnavailableError|Audience validation failed/i.test(err.message)) {
1516
throw err;
1617
}
18+
lastError = err;
1719
const millis = (Math.random() * 200) + (50 * Math.pow(1.5, run));
18-
console.log(`Failed with ECONNRESET, retrying in ${millis}ms...`);
20+
console.log(`Request failed, retrying in ${millis}ms...`);
1921
// maximum delay is 10th retry: ~3 seconds
2022
await new Promise(c => setTimeout(c, millis));
2123
}
2224
}
23-
throw new Error('Retried too many times');
25+
console.log(`Too many retries, aborting.`);
26+
throw lastError;
2427
}
2528
exports.retry = retry;

build/azure-pipelines/common/retry.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,25 @@
66
'use strict';
77

88
export async function retry<T>(fn: () => Promise<T>): Promise<T> {
9+
let lastError: Error | undefined;
10+
911
for (let run = 1; run <= 10; run++) {
1012
try {
1113
return await fn();
1214
} catch (err) {
13-
if (!/ECONNRESET/.test(err.message)) {
15+
if (!/ECONNRESET|CredentialUnavailableError|Audience validation failed/i.test(err.message)) {
1416
throw err;
1517
}
1618

19+
lastError = err;
1720
const millis = (Math.random() * 200) + (50 * Math.pow(1.5, run));
18-
console.log(`Failed with ECONNRESET, retrying in ${millis}ms...`);
21+
console.log(`Request failed, retrying in ${millis}ms...`);
1922

2023
// maximum delay is 10th retry: ~3 seconds
2124
await new Promise(c => setTimeout(c, millis));
2225
}
2326
}
2427

25-
throw new Error('Retried too many times');
28+
console.log(`Too many retries, aborting.`);
29+
throw lastError;
2630
}

build/azure-pipelines/product-build.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ parameters:
7777
displayName: "Publish to builds.code.visualstudio.com"
7878
type: boolean
7979
default: true
80+
- name: VSCODE_PUBLISH_TO_MOONCAKE
81+
displayName: "Publish to Azure China"
82+
type: boolean
83+
default: true
8084
- name: VSCODE_RELEASE
8185
displayName: "Release build if successful"
8286
type: boolean
@@ -107,6 +111,8 @@ variables:
107111
value: ${{ in(variables['Build.Reason'], 'IndividualCI', 'BatchedCI') }}
108112
- name: VSCODE_PUBLISH
109113
value: ${{ and(eq(parameters.VSCODE_PUBLISH, true), eq(variables.VSCODE_CIBUILD, false)) }}
114+
- name: VSCODE_PUBLISH_TO_MOONCAKE
115+
value: ${{ eq(parameters.VSCODE_PUBLISH_TO_MOONCAKE, true) }}
110116
- name: VSCODE_SCHEDULEDBUILD
111117
value: ${{ eq(variables['Build.Reason'], 'Schedule') }}
112118
- name: VSCODE_STEP_ON_IT

0 commit comments

Comments
 (0)