diff --git a/cypress/dockerNode.ts b/cypress/dockerNode.ts index 33c2829c9d0bb..a0ef5290487e5 100644 --- a/cypress/dockerNode.ts +++ b/cypress/dockerNode.ts @@ -16,6 +16,7 @@ import { existsSync } from 'fs' export const docker = new Docker() const CONTAINER_NAME = 'nextcloud-cypress-tests-server' +const CONTAINER_NAME_REDIS = `${CONTAINER_NAME}-redis` const SERVER_IMAGE = 'ghcr.io/nextcloud/continuous-integration-shallow-server' /** @@ -29,30 +30,8 @@ export const startNextcloud = async function(branch: string = getCurrentGitBranc 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 - } - - // https://github.com/apocas/dockerode/issues/357 - docker.modem.followProgress(stream, onFinished) - - /** - * - * @param err - */ - function onFinished(err) { - if (!err) { - resolve(true) - return - } - reject(err) - } - })) + await pullImage(SERVER_IMAGE) + await pullImage('redis') console.log('└─ Done') } catch (e) { console.log('└─ Failed to pull images') @@ -65,12 +44,20 @@ export const startNextcloud = async function(branch: string = getCurrentGitBranc const oldContainer = docker.getContainer(CONTAINER_NAME) const oldContainerData = await oldContainer.inspect() if (oldContainerData) { - console.log('├─ Existing running container found') - console.log('├─ Removing... ⏳') + console.log('├─ Removing existing container... ⏳') // Forcing any remnants to be removed just in case await oldContainer.remove({ force: true }) - console.log('└─ Done') } + + const oldRedisContainer = docker.getContainer(CONTAINER_NAME_REDIS) + const oldRedisContainerData = await oldRedisContainer.inspect() + if (oldRedisContainerData) { + console.log('├─ Removing existing redis container... ⏳') + // Forcing any remnants to be removed just in case + await oldRedisContainer.remove({ force: true }) + } + + console.log('└─ Done') } catch (error) { console.log('└─ None found!') } @@ -90,6 +77,12 @@ export const startNextcloud = async function(branch: string = getCurrentGitBranc }) await container.start() + const redis = await docker.createContainer({ + Image: 'redis', + name: CONTAINER_NAME_REDIS, + }) + await redis.start() + // Get container's IP const ip = await getContainerIP(container) @@ -103,6 +96,29 @@ export const startNextcloud = async function(branch: string = getCurrentGitBranc } } +const pullImage = async function(name: string) { + return new Promise((resolve, reject): any => docker.pull(name, (err, stream) => { + if (err) { + reject(err) + } + if (stream === null) { + reject(new Error('Could not connect to docker, ensure docker is running.')) + return + } + + // https://github.com/apocas/dockerode/issues/357 + docker.modem.followProgress(stream, onFinished) + + function onFinished(err) { + if (!err) { + resolve(true) + return + } + reject(err) + } + })) +} + /** * Configure Nextcloud */ @@ -117,9 +133,18 @@ export const configureNextcloud = async function() { await runExec(container, ['php', 'occ', 'config:system:set', 'default_locale', '--value', 'en_US'], true) await runExec(container, ['php', 'occ', 'config:system:set', 'force_locale', '--value', 'en_US'], true) await runExec(container, ['php', 'occ', 'config:system:set', 'enforce_theme', '--value', 'light'], true) + // Speed up test and make them less flaky. If a cron execution is needed, it can be triggered manually. await runExec(container, ['php', 'occ', 'background:cron'], true) + // Enable redis + const redis = docker.getContainer(CONTAINER_NAME_REDIS) + const ip = await getContainerIP(redis) + await runExec(container, ['php', 'occ', 'config:system:set', 'memcache.distributed', '--value', '\\OC\\Memcache\\Redis'], true) + await runExec(container, ['php', 'occ', 'config:system:set', 'memcache.locking', '--value', '\\OC\\Memcache\\Redis'], true) + await runExec(container, ['php', 'occ', 'config:system:set', 'redis', 'host', '--value', ip], true) + await runExec(container, ['php', 'occ', 'config:system:set', 'redis', 'port', '--value', '6379', '--type', 'integer'], true) + console.log('└─ Nextcloud is now ready to use 🎉') } @@ -189,7 +214,10 @@ export const stopNextcloud = async function() { const container = docker.getContainer(CONTAINER_NAME) console.log('Stopping Nextcloud container...') container.remove({ force: true }) - console.log('└─ Nextcloud container removed 🥀') + console.log('├─ Removing redis container...') + const redis = docker.getContainer(CONTAINER_NAME_REDIS) + redis.remove({ force: true }) + console.log('└─ All containers removed 🥀') } catch (err) { console.log(err) }