Skip to content

Commit

Permalink
Merge pull request #85 from FlowFuse/pull-missing-stack
Browse files Browse the repository at this point in the history
Pull missing Stack containers on first use
  • Loading branch information
hardillb authored Feb 21, 2024
2 parents d314ec0 + d1bb0f3 commit 00ba933
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,40 @@ const createContainer = async (project, domain) => {
contOptions.Env.push('NODE_EXTRA_CA_CERTS=/usr/local/ssl-certs/chain.pem')
}

const containerList = await this._docker.listImages()
let containerFound = false
for (const cont of containerList) {
if (cont.RepoTags.includes(stack.container)) {
containerFound = true
break
}
}

if (!containerFound) {
this._app.log.info(`Container for stack ${stack.name} not found, pulling ${stack.container}`)
// https://github.com/apocas/dockerode/issues/703
try {
await new Promise((resolve, reject) => {
this._docker.pull(stack.container, (err, stream) => {
if (!err) {
this._docker.modem.followProgress(stream, onFinished)
function onFinished (err, output) {
if (!err) {
resolve(true)
return
}
reject(err)
}
} else {
reject(err)
}
})
})
} catch (err) {
this._app.log.debug(`Error pulling image ${stack.container} ${err.message}`)
}
}

const container = await this._docker.createContainer(contOptions)
return container.start()
.then(async () => {
Expand Down

0 comments on commit 00ba933

Please sign in to comment.