All checks were successful
Docker-Image veröffentlichen / publish (push) Successful in 1m44s
60 lines
2.2 KiB
JavaScript
60 lines
2.2 KiB
JavaScript
import { randomBytes, scryptSync } from 'node:crypto'
|
|
import { spawn } from 'node:child_process'
|
|
import { unlink, writeFile } from 'node:fs/promises'
|
|
import { createServer } from 'node:net'
|
|
import { tmpdir } from 'node:os'
|
|
import { join } from 'node:path'
|
|
import { passwordOptions } from '../server/auth.js'
|
|
|
|
const password = randomBytes(24).toString('hex')
|
|
const salt = randomBytes(16)
|
|
const hash = scryptSync(password, salt, 64, passwordOptions)
|
|
const project = 'syncova-test-' + randomBytes(5).toString('hex')
|
|
const envFile = join(tmpdir(), project + '.env')
|
|
const socket = createServer()
|
|
await new Promise((resolve, reject) => socket.once('error', reject).listen(0, '127.0.0.1', resolve))
|
|
const { port } = socket.address()
|
|
await new Promise((resolve) => socket.close(resolve))
|
|
const runtime = {
|
|
ADMIN_USERNAME: 'abnahme',
|
|
ADMIN_PASSWORD_HASH: `scrypt:${salt.toString('hex')}:${hash.toString('hex')}`,
|
|
BIND_ADDRESS: '127.0.0.1',
|
|
HTTP_PORT: String(port),
|
|
COOKIE_SECURE: 'false',
|
|
}
|
|
const env = {
|
|
...process.env,
|
|
SYNCOVA_TEST_PASSWORD: password,
|
|
SYNCOVA_TEST_URL: `http://127.0.0.1:${port}`,
|
|
SYNCOVA_TEST_PROJECT: project,
|
|
SYNCOVA_TEST_ENV: envFile,
|
|
}
|
|
for (const key of Object.keys(runtime)) delete env[key]
|
|
|
|
function run(command, args) {
|
|
return new Promise((resolve, reject) => {
|
|
const child = spawn(command, args, { env, stdio: 'inherit' })
|
|
child.once('error', reject)
|
|
child.once('exit', (code) => code === 0 ? resolve() : reject(new Error(`${command} wurde mit Code ${code} beendet.`)))
|
|
})
|
|
}
|
|
|
|
const compose = ['compose', '--env-file', envFile, '-p', project, '-f', 'compose.yaml']
|
|
await writeFile(envFile, Object.entries(runtime).map(([key, value]) => key + '=' + value).join('\n') + '\n', {
|
|
flag: 'wx', mode: 0o600,
|
|
})
|
|
try {
|
|
await run('docker', [...compose, 'up', '--build', '--wait', '--wait-timeout', '60'])
|
|
await run(process.execPath, ['node_modules/@playwright/test/cli.js', 'test'])
|
|
} catch (error) {
|
|
console.error(error.message)
|
|
process.exitCode = 1
|
|
await run('docker', [...compose, 'logs', '--tail', '40']).catch(() => {})
|
|
} finally {
|
|
await run('docker', [...compose, 'down', '--volumes', '--rmi', 'local']).catch((error) => {
|
|
console.error(error.message)
|
|
process.exitCode = 1
|
|
})
|
|
await unlink(envFile)
|
|
}
|