Skip to content

Commit 9feecee

Browse files
Fix build tool - az login (#1119)
1 parent 8cd7494 commit 9feecee

File tree

2 files changed

+48
-23
lines changed

2 files changed

+48
-23
lines changed

build/src/patch.js

+43-20
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ async function patch(patchPath, registry, registryPath) {
2626
if (patchConfig.deleteUntaggedImages && patchConfig.imageIds) {
2727
await deleteUntaggedImages(patchConfig.imageIds, registry);
2828
}
29-
29+
3030
console.log('\n(*) Done!')
3131
}
3232

@@ -36,17 +36,16 @@ async function patchImage(imageId, patchPath, dockerFilePath, bumpVersion, regis
3636

3737
// Get repository and tag list for imageId
3838
let repoAndTagList = await getImageRepositoryAndTags(imageId, registry);
39-
if(repoAndTagList.length === 0) {
39+
if (repoAndTagList.length === 0) {
4040
console.log('(*) No tags to patch. Skipping.');
4141
return;
4242
}
4343

44-
console.log(`(*) Tags to update: ${
45-
JSON.stringify(repoAndTagList.reduce((prev, repoAndTag) => { return prev + repoAndTag.repository + ':' + repoAndTag.tag + ' ' }, ''), undefined, 4)
44+
console.log(`(*) Tags to update: ${JSON.stringify(repoAndTagList.reduce((prev, repoAndTag) => { return prev + repoAndTag.repository + ':' + repoAndTag.tag + ' ' }, ''), undefined, 4)
4645
}`);
4746

4847
// Bump breakfix number of it applies
49-
if(bumpVersion) {
48+
if (bumpVersion) {
5049
repoAndTagList = updateVersionTags(repoAndTagList);
5150
}
5251

@@ -59,7 +58,7 @@ async function patchImage(imageId, patchPath, dockerFilePath, bumpVersion, regis
5958
let retry = false;
6059
do {
6160
try {
62-
await asyncUtils.spawn('docker', [
61+
await asyncUtils.spawn('docker', [
6362
'build',
6463
'--pull',
6564
'--build-arg',
@@ -76,7 +75,7 @@ async function patchImage(imageId, patchPath, dockerFilePath, bumpVersion, regis
7675
} else {
7776
throw ex;
7877
}
79-
}
78+
}
8079
} while (retry);
8180

8281
// Push updates
@@ -145,7 +144,9 @@ async function deleteUntaggedImages(imageIds, registry) {
145144
'delete',
146145
'--yes',
147146
'--name', registryName,
148-
'--image', fullImageId
147+
'--image', fullImageId,
148+
'--username', '$TOKEN_NAME',
149+
'--password', '$PASSWORD'
149150
], spawnOpts);
150151
});
151152

@@ -159,22 +160,44 @@ async function getImageRepositoryAndTags(imageId, registry) {
159160

160161
// Get list of repositories
161162
console.log(`(*) Getting repository list for ACR "${registryName}"...`)
162-
const repositoryListOutput = await asyncUtils.spawn('az',
163-
['acr', 'repository', 'list', '--name', registryName],
163+
const repositoryListOutput = await asyncUtils.spawn('az', [
164+
'acr',
165+
'repository',
166+
'list',
167+
'--name',
168+
registryName,
169+
'--username',
170+
'$TOKEN_NAME',
171+
'--password',
172+
'$PASSWORD'
173+
],
164174
{ shell: true, stdio: 'pipe' });
165175
const repositoryList = JSON.parse(repositoryListOutput);
166176

167177
let repoAndTagList = [];
168178
await asyncUtils.forEach(repositoryList, async (repository) => {
169179
console.log(`(*) Checking in for "${imageId}" in "${repository}"...`);
170-
const tagListOutput = await asyncUtils.spawn('az',
171-
['acr', 'repository', 'show-tags', '--detail', '--name', registryName, '--repository', repository, "--query", `"[?digest=='${imageId}'].name"`],
172-
{ shell: true, stdio: 'pipe' });
180+
const tagListOutput = await asyncUtils.spawn('az', [
181+
'acr',
182+
'repository',
183+
'show-tags',
184+
'--detail',
185+
'--name',
186+
registryName,
187+
'--repository',
188+
repository,
189+
"--query",
190+
`"[?digest=='${imageId}'].name"`,
191+
'--username',
192+
'$TOKEN_NAME',
193+
'--password',
194+
'$PASSWORD'
195+
], { shell: true, stdio: 'inherit' });
173196
const additionalTags = JSON.parse(tagListOutput);
174197
repoAndTagList = repoAndTagList.concat(additionalTags.map((tag) => {
175-
return {
176-
repository:repository,
177-
tag:tag
198+
return {
199+
repository: repository,
200+
tag: tag
178201
};
179202
}));
180203
});
@@ -190,8 +213,8 @@ async function getImageManifests(imageIds, registry) {
190213
// Get list of repositories
191214
console.log(`(*) Getting repository list for ACR "${registryName}"...`)
192215
const repositoryListOutput = await asyncUtils.spawn('az',
193-
['acr', 'repository', 'list', '--name', registryName],
194-
{ shell: true, stdio: 'pipe' });
216+
['acr', 'repository', 'list', '--name', registryName, '--username', '$TOKEN_NAME', '--password', '$PASSWORD'],
217+
{ shell: true, stdio: 'inherit' });
195218
const repositoryList = JSON.parse(repositoryListOutput);
196219

197220
// Query each repository for images, then add any tags found to the list
@@ -201,8 +224,8 @@ async function getImageManifests(imageIds, registry) {
201224
await asyncUtils.forEach(repositoryList, async (repository) => {
202225
console.log(`(*) Getting manifests from "${repository}"...`);
203226
const registryManifestListOutput = await asyncUtils.spawn('az',
204-
['acr', 'repository', 'show-manifests', '--name', registryName, '--repository', repository, "--query", query],
205-
{ shell: true, stdio: 'pipe' });
227+
['acr', 'repository', 'show-manifests', '--name', registryName, '--repository', repository, "--query", query, '--username', '$TOKEN_NAME', '--password', '$PASSWORD'],
228+
{ shell: true, stdio: 'inherit' });
206229
let registryManifestList = JSON.parse(registryManifestListOutput);
207230
registryManifestList = registryManifestList.map((manifest) => {
208231
manifest.repository = repository;

build/src/push.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ async function isDefinitionVersionAlreadyPublished(definitionId, release, regist
235235
async function isImageAlreadyPublished(registryName, repositoryName, tagName) {
236236
registryName = registryName.replace(/\.azurecr\.io.*/, '');
237237
// Check if repository exists
238-
const repositoriesOutput = await asyncUtils.spawn('az', ['acr', 'repository', 'list', '--name', registryName], { shell: true, stdio: 'pipe' });
238+
const repositoriesOutput = await asyncUtils.spawn('az', ['acr', 'repository', 'list', '--name', registryName, '--username', '$TOKEN_NAME', '--password', '$PASSWORD'], { shell: true, stdio: 'inherit' });
239239
const repositories = JSON.parse(repositoriesOutput);
240240
if (repositories.indexOf(repositoryName) < 0) {
241241
console.log('(*) Repository does not exist. Image version has not been published yet.')
@@ -246,8 +246,10 @@ async function isImageAlreadyPublished(registryName, repositoryName, tagName) {
246246
const tagListOutput = await asyncUtils.spawn('az', ['acr', 'repository', 'show-tags',
247247
'--name', registryName,
248248
'--repository', repositoryName,
249-
'--query', `"[?@=='${tagName}']"`
250-
], { shell: true, stdio: 'pipe' });
249+
'--query', `"[?@=='${tagName}']"`,
250+
'--username', '$TOKEN_NAME',
251+
'--password', '$PASSWORD'
252+
], { shell: true, stdio: 'inherit' });
251253
const tagList = JSON.parse(tagListOutput);
252254
if (tagList.length > 0) {
253255
console.log('(*) Image version has already been published.')

0 commit comments

Comments
 (0)