From d452b872c9ac7ad17d9b0c60ecb391659bdef831 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Wed, 18 Oct 2023 14:37:11 +0200 Subject: fix: Improve dockerNode logging Signed-off-by: Ferdinand Thiessen --- cypress/dockerNode.ts | 56 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 23 deletions(-) (limited to 'cypress') diff --git a/cypress/dockerNode.ts b/cypress/dockerNode.ts index 23bed54b671..e2c0db38c97 100644 --- a/cypress/dockerNode.ts +++ b/cypress/dockerNode.ts @@ -41,28 +41,38 @@ const SERVER_IMAGE = 'ghcr.io/nextcloud/continuous-integration-shallow-server' export const startNextcloud = async function(branch: string = getCurrentGitBranch()): Promise { try { - // Pulling images - console.log('\nPulling images... ⏳') - await new Promise((resolve, reject): any => docker.pull(SERVER_IMAGE, (err, stream) => { - if (err) { - reject(err) - } - // https://github.com/apocas/dockerode/issues/357 - docker.modem.followProgress(stream, onFinished) - - /** - * - * @param err - */ - function onFinished(err) { - if (!err) { - resolve(true) + try { + // Pulling images + console.log('\nPulling images... ⏳') + await new Promise((resolve, reject): any => docker.pull(SERVER_IMAGE, (err, stream) => { + if (err) { + reject(err) + } + if (stream === null) { + reject(new Error('Could not connect to docker, ensure docker is running.')) return } - reject(err) - } - })) - console.log('└─ Done') + + // https://github.com/apocas/dockerode/issues/357 + docker.modem.followProgress(stream, onFinished) + + /** + * + * @param err + */ + function onFinished(err) { + if (!err) { + resolve(true) + return + } + reject(err) + } + })) + console.log('└─ Done') + } catch (e) { + console.log('└─ Failed to pull images') + throw e + } // Remove old container if exists console.log('\nChecking running containers... 🔍') @@ -102,7 +112,7 @@ export const startNextcloud = async function(branch: string = getCurrentGitBranc return ip } catch (err) { console.log('└─ Unable to start the container 🛑') - console.log(err) + console.log('\n', err, '\n') stopNextcloud() throw new Error('Unable to start the container') } @@ -191,7 +201,7 @@ export const stopNextcloud = async function() { * @param {Docker.Container} container the container to get the IP from */ export const getContainerIP = async function( - container = docker.getContainer(CONTAINER_NAME) + container = docker.getContainer(CONTAINER_NAME), ): Promise { let ip = '' let tries = 0 @@ -230,7 +240,7 @@ const runExec = async function( container: Docker.Container, command: string[], verbose = false, - user = 'www-data' + user = 'www-data', ) { const exec = await container.exec({ Cmd: command, -- cgit v1.2.3