82 lines
2.6 KiB
TypeScript
82 lines
2.6 KiB
TypeScript
import * as fs from 'node:fs/promises';
|
|
import * as path from 'node:path';
|
|
|
|
import { Qenv } from '@push.rocks/qenv';
|
|
import { SmartNetwork } from '@push.rocks/smartnetwork';
|
|
import { tap } from '@git.zone/tstest/tapbundle';
|
|
import { TapNodeTools } from '@git.zone/tstest/tapbundle_serverside';
|
|
|
|
const tapNodeTools = new TapNodeTools(tap);
|
|
|
|
const testQenv = new Qenv('./', './.nogit/');
|
|
|
|
import * as cloudly from '../../ts/index.js';
|
|
|
|
const stopFunctions: Array<() => Promise<void>> = [];
|
|
|
|
const getPublicPort = async () => {
|
|
if (process.env.SERVEZONE_TEST_PORT) {
|
|
return process.env.SERVEZONE_TEST_PORT;
|
|
}
|
|
const smartnetwork = new SmartNetwork();
|
|
const publicPort = await smartnetwork.findFreePort(30000, 40000, { randomize: true });
|
|
if (!publicPort) {
|
|
throw new Error('Could not find a free Cloudly test port in range 30000-40000');
|
|
}
|
|
return String(publicPort);
|
|
};
|
|
|
|
const smartmongo = await tapNodeTools.createSmartmongo();
|
|
stopFunctions.push(async () => {
|
|
await smartmongo.stopAndDumpToDir('./.nogit/mongodump');
|
|
});
|
|
const smartstorage = await tapNodeTools.createSmartStorage();
|
|
await smartstorage.createBucket('cloudly_test_bucket');
|
|
stopFunctions.push(async () => {
|
|
await smartstorage.stop();
|
|
});
|
|
|
|
export const testCloudlyAdminAccount = {
|
|
username: 'testadmin',
|
|
password: 'testpassword',
|
|
};
|
|
|
|
export const testCloudlyConfig: cloudly.ICloudlyConfig = {
|
|
environment: 'integration',
|
|
letsEncryptEmail: 'test@serve.zone',
|
|
publicUrl: '127.0.0.1',
|
|
publicPort: await getPublicPort(),
|
|
mongoDescriptor: await smartmongo.getMongoDescriptor(),
|
|
s3Descriptor: await smartstorage.getStorageDescriptor({
|
|
bucketName: 'cloudly_test_bucket'
|
|
}),
|
|
sslMode: 'none',
|
|
servezoneAdminaccount: `${testCloudlyAdminAccount.username}:${testCloudlyAdminAccount.password}`,
|
|
...(() => {
|
|
if (process.env.NPMCI_SECRET01) {
|
|
return {
|
|
hetznerToken: process.env.NPMCI_SECRET01,
|
|
};
|
|
}
|
|
})(),
|
|
};
|
|
|
|
const alpineImageTarballPath = path.join(process.cwd(), '.nogit/testfiles/alpine.tar');
|
|
const existingAlpineImageTarball = await fs.stat(alpineImageTarballPath).catch(() => undefined);
|
|
if (!existingAlpineImageTarball?.isFile() || existingAlpineImageTarball.size === 0) {
|
|
await tapNodeTools.testFileProvider.getDockerAlpineImageAsLocalTarball();
|
|
}
|
|
|
|
export const createCloudly = async () => {
|
|
const cloudlyInstance = new cloudly.Cloudly(testCloudlyConfig);
|
|
return cloudlyInstance;
|
|
};
|
|
|
|
export const stopCloudly = async () => {
|
|
await Promise.all(stopFunctions.map((stopFunction) => stopFunction()));
|
|
};
|
|
|
|
export const getEnvVarOnDemand = async (envVarName: string) => {
|
|
return testQenv.getEnvVarOnDemand(envVarName);
|
|
};
|