Skip to content

Commit

Permalink
fix(docker): try to use existing image if pulling fails
Browse files Browse the repository at this point in the history
Signed-off-by: Max <max@nextcloud.com>
  • Loading branch information
max-nextcloud committed Jan 9, 2025
1 parent 3a541ee commit 614a152
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions lib/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,7 @@ export async function startNextcloud(branch = 'master', mountApp: boolean|string
}

try {
// Pulling images
console.log('\nPulling images… ⏳')
await new Promise((resolve, reject) => docker.pull(SERVER_IMAGE, (_err, stream: Stream) => {
const onFinished = function(err: Error | null) {
if (!err) {
return resolve(true)
}
reject(err)
}
// https://github.com/apocas/dockerode/issues/357
docker.modem.followProgress(stream, onFinished)
}))
console.log('└─ Done')
await pullImage()

// Getting latest image
console.log('\nChecking running containers… 🔍')
Expand Down Expand Up @@ -207,6 +195,27 @@ export async function startNextcloud(branch = 'master', mountApp: boolean|string
}
}

const pullImage = function() {
// Pulling images
console.log('\nPulling images… ⏳')
return new Promise((resolve, reject) => docker.pull(SERVER_IMAGE, (_err, stream: Stream) => {
const onFinished = function(err: Error | null) {
if (!err) {
return resolve(true)
}
reject(err)
}
// https://github.com/apocas/dockerode/issues/357
if(stream) {
docker.modem.followProgress(stream, onFinished)
} else {
reject('Failed to open stream')
}
}))
.then(() => console.log('└─ Done'))
.catch(err => console.log(`└─ 🛑 FAILED! Trying to continue with existing image. (${err})`))
}

/**
* Configure Nextcloud
*
Expand Down

0 comments on commit 614a152

Please # to comment.