Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function createNewRunner(userId, dockerTag) {
logger.info(`Creating new instance runner ${dockerTag}`)
// Verify that dockerode parses the tag to be something sensible before
// pulling the image. The Docker daemon pulls *all* available tags if one
// isn't specified. So we verify that the tag isn't empty.
const tagParse = parseRepositoryTag(dockerTag)
if (!tagParse.hasOwnProperty('tag')) {
throw new HttpError(400, 'No tag version specified')
}
await createNewInstanceRunner(userId, dockerTag)
// We won't wait for the promise to resolve because
// especially with larger images it can take a while to download.
// Instead, we update the download's status in the database.
// It should also be noted that this updates the image for all other
// users too if they use the same tag.
docker.pull(dockerTag).then(async (stream) => {
logger.info(`Pulling image ${dockerTag}...`)
// eslint-disable-next-line no-unused-vars
pullImage(
imageNameIncludingTag: string,
authObj: DockerAuthObj | undefined
) {
const self = this
const parsedTag = dockerodeUtils.parseRepositoryTag(
imageNameIncludingTag
)
const repository = parsedTag.repository
const tag = parsedTag.tag || 'latest'
return Promise.resolve()
.then(function() {
return self.dockerode.createImage({
fromImage: repository,
tag: tag,
authconfig: authObj,
})
})
.then(function(stream) {
return new Promise(function(resolve, reject) {
let errorMessage = ''