Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 28 additions & 14 deletions apps/api/src/sandbox/docker/docker-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,22 +476,36 @@ export class DockerProvider implements OnModuleInit {
const apiUrl = `${registryUrl}/v2/${parts[1]}/${parts[2]}/manifests/${tag}`
const encodedCredentials = Buffer.from(`${registry.username}:${registry.password}`).toString('base64')

const response = await axios({
method: 'get',
url: apiUrl,
headers: {
Authorization: `Basic ${encodedCredentials}`,
},
validateStatus: (status) => status < 500,
timeout: 30000,
})
const maxAttempts = 3

if (response.status === 200) {
this.logger.debug(`Image ${imageName} exists in registry`)
return true
}
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
try {
const response = await axios({
method: 'get',
url: apiUrl,
headers: {
Authorization: `Basic ${encodedCredentials}`,
},
validateStatus: (status) => status < 500,
timeout: 30000,
})

if (response.status === 200) {
this.logger.debug(`Image ${imageName} exists in registry`)
return true
}

this.logger.debug(`Image ${imageName} does not exist in registry (status: ${response.status})`)
this.logger.debug(`Image ${imageName} does not exist in registry (status: ${response.status})`)
return false
} catch (error) {
this.logger.warn(
`Error checking if image ${imageName} exists in registry (attempt ${attempt}/${maxAttempts}): ${error.message}`,
)
if (attempt < maxAttempts) {
await new Promise((resolve) => setTimeout(resolve, attempt * 2000))
}
}
}
return false
} catch (error) {
this.logger.error(`Error checking if image ${imageName} exists in registry: ${error.message}`)
Expand Down
Loading