2022-10-20 14:06:33 +00:00
|
|
|
import { createDirectories, getServiceFromDB, getServiceImage, getServiceMainPort, isDev, makeLabelForServices } from "./common";
|
|
|
|
|
import fs from 'fs/promises';
|
|
|
|
|
export async function getTemplates() {
|
|
|
|
|
let templates = [];
|
|
|
|
|
if (isDev) {
|
|
|
|
|
templates = JSON.parse((await fs.readFile('./template.json')).toString())
|
|
|
|
|
}
|
2022-08-15 14:58:10 +00:00
|
|
|
|
2022-10-20 14:06:33 +00:00
|
|
|
return templates
|
|
|
|
|
}
|
2022-08-15 14:58:10 +00:00
|
|
|
export async function defaultServiceConfigurations({ id, teamId }) {
|
|
|
|
|
const service = await getServiceFromDB({ id, teamId });
|
|
|
|
|
const { destinationDockerId, destinationDocker, type, serviceSecret } = service;
|
|
|
|
|
|
|
|
|
|
const network = destinationDockerId && destinationDocker.network;
|
|
|
|
|
const port = getServiceMainPort(type);
|
|
|
|
|
|
|
|
|
|
const { workdir } = await createDirectories({ repository: type, buildId: id });
|
|
|
|
|
|
|
|
|
|
const image = getServiceImage(type);
|
|
|
|
|
let secrets = [];
|
|
|
|
|
if (serviceSecret.length > 0) {
|
|
|
|
|
serviceSecret.forEach((secret) => {
|
2022-08-16 09:13:22 +00:00
|
|
|
secrets.push(`${secret.name}=${secret.value}`);
|
2022-08-15 14:58:10 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return { ...service, network, port, workdir, image, secrets }
|
|
|
|
|
}
|