fixes
This commit is contained in:
@@ -1099,6 +1099,7 @@ export const createDirectories = async ({
|
||||
repository: string;
|
||||
buildId: string;
|
||||
}): Promise<{ workdir: string; repodir: string }> => {
|
||||
repository = repository.replaceAll(' ','')
|
||||
const repodir = `/tmp/build-sources/${repository}/`;
|
||||
const workdir = `/tmp/build-sources/${repository}/${buildId}`;
|
||||
let workdirFound = false;
|
||||
|
@@ -7,138 +7,138 @@ export async function getTemplates() {
|
||||
} else {
|
||||
templates = JSON.parse(await (await fs.readFile('/app/template.json')).toString())
|
||||
}
|
||||
if (!isDev) {
|
||||
templates.push({
|
||||
"templateVersion": "1.0.0",
|
||||
"defaultVersion": "latest",
|
||||
"name": "Test-Fake-Service",
|
||||
"description": "",
|
||||
"services": {
|
||||
"$$id": {
|
||||
"name": "Test-Fake-Service",
|
||||
"depends_on": [
|
||||
"$$id-postgresql",
|
||||
"$$id-redis"
|
||||
],
|
||||
"image": "weblate/weblate:$$core_version",
|
||||
"volumes": [
|
||||
"$$id-data:/app/data",
|
||||
],
|
||||
"environment": [
|
||||
`POSTGRES_SECRET=$$secret_postgres_secret`,
|
||||
`WEBLATE_SITE_DOMAIN=$$config_weblate_site_domain`,
|
||||
`WEBLATE_ADMIN_PASSWORD=$$secret_weblate_admin_password`,
|
||||
`POSTGRES_PASSWORD=$$secret_postgres_password`,
|
||||
`POSTGRES_USER=$$config_postgres_user`,
|
||||
`POSTGRES_DATABASE=$$config_postgres_db`,
|
||||
`POSTGRES_HOST=$$id-postgresql`,
|
||||
`POSTGRES_PORT=5432`,
|
||||
`REDIS_HOST=$$id-redis`,
|
||||
],
|
||||
"ports": [
|
||||
"8080"
|
||||
]
|
||||
},
|
||||
"$$id-postgresql": {
|
||||
"name": "PostgreSQL",
|
||||
"depends_on": [],
|
||||
"image": "postgres:14-alpine",
|
||||
"volumes": [
|
||||
"$$id-postgresql-data:/var/lib/postgresql/data",
|
||||
],
|
||||
"environment": [
|
||||
"POSTGRES_USER=$$config_postgres_user",
|
||||
"POSTGRES_PASSWORD=$$secret_postgres_password",
|
||||
"POSTGRES_DB=$$config_postgres_db",
|
||||
],
|
||||
"ports": []
|
||||
},
|
||||
"$$id-redis": {
|
||||
"name": "Redis",
|
||||
"depends_on": [],
|
||||
"image": "redis:7-alpine",
|
||||
"volumes": [
|
||||
"$$id-redis-data:/data",
|
||||
],
|
||||
"environment": [],
|
||||
"ports": [],
|
||||
}
|
||||
},
|
||||
"variables": [
|
||||
{
|
||||
"id": "$$config_weblate_site_domain",
|
||||
"main": "$$id",
|
||||
"name": "WEBLATE_SITE_DOMAIN",
|
||||
"label": "Weblate Domain",
|
||||
"defaultValue": "$$generate_domain",
|
||||
"description": "",
|
||||
},
|
||||
{
|
||||
"id": "$$secret_weblate_admin_password",
|
||||
"main": "$$id",
|
||||
"name": "WEBLATE_ADMIN_PASSWORD",
|
||||
"label": "Weblate Admin Password",
|
||||
"defaultValue": "$$generate_password",
|
||||
"description": "",
|
||||
"extras": {
|
||||
"isVisibleOnUI": true,
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "$$secret_weblate_admin_password2",
|
||||
"name": "WEBLATE_ADMIN_PASSWORD2",
|
||||
"label": "Weblate Admin Password2",
|
||||
"defaultValue": "$$generate_password",
|
||||
"description": "",
|
||||
},
|
||||
{
|
||||
"id": "$$config_postgres_user",
|
||||
"main": "$$id-postgresql",
|
||||
"name": "POSTGRES_USER",
|
||||
"label": "PostgreSQL User",
|
||||
"defaultValue": "$$generate_username",
|
||||
"description": "",
|
||||
},
|
||||
{
|
||||
"id": "$$secret_postgres_password",
|
||||
"main": "$$id-postgresql",
|
||||
"name": "POSTGRES_PASSWORD",
|
||||
"label": "PostgreSQL Password",
|
||||
"defaultValue": "$$generate_password(32)",
|
||||
"description": "",
|
||||
},
|
||||
{
|
||||
"id": "$$secret_postgres_password_hex32",
|
||||
"name": "POSTGRES_PASSWORD_hex32",
|
||||
"label": "PostgreSQL Password hex32",
|
||||
"defaultValue": "$$generate_hex(32)",
|
||||
"description": "",
|
||||
},
|
||||
{
|
||||
"id": "$$config_postgres_something_hex32",
|
||||
"name": "POSTGRES_SOMETHING_HEX32",
|
||||
"label": "PostgreSQL Something hex32",
|
||||
"defaultValue": "$$generate_hex(32)",
|
||||
"description": "",
|
||||
},
|
||||
{
|
||||
"id": "$$config_postgres_db",
|
||||
"main": "$$id-postgresql",
|
||||
"name": "POSTGRES_DB",
|
||||
"label": "PostgreSQL Database",
|
||||
"defaultValue": "weblate",
|
||||
"description": "",
|
||||
},
|
||||
{
|
||||
"id": "$$secret_postgres_secret",
|
||||
"name": "POSTGRES_SECRET",
|
||||
"label": "PostgreSQL Secret",
|
||||
"defaultValue": "",
|
||||
"description": "",
|
||||
},
|
||||
]
|
||||
})
|
||||
}
|
||||
// if (!isDev) {
|
||||
// templates.push({
|
||||
// "templateVersion": "1.0.0",
|
||||
// "defaultVersion": "latest",
|
||||
// "name": "Test-Fake-Service",
|
||||
// "description": "",
|
||||
// "services": {
|
||||
// "$$id": {
|
||||
// "name": "Test-Fake-Service",
|
||||
// "depends_on": [
|
||||
// "$$id-postgresql",
|
||||
// "$$id-redis"
|
||||
// ],
|
||||
// "image": "weblate/weblate:$$core_version",
|
||||
// "volumes": [
|
||||
// "$$id-data:/app/data",
|
||||
// ],
|
||||
// "environment": [
|
||||
// `POSTGRES_SECRET=$$secret_postgres_secret`,
|
||||
// `WEBLATE_SITE_DOMAIN=$$config_weblate_site_domain`,
|
||||
// `WEBLATE_ADMIN_PASSWORD=$$secret_weblate_admin_password`,
|
||||
// `POSTGRES_PASSWORD=$$secret_postgres_password`,
|
||||
// `POSTGRES_USER=$$config_postgres_user`,
|
||||
// `POSTGRES_DATABASE=$$config_postgres_db`,
|
||||
// `POSTGRES_HOST=$$id-postgresql`,
|
||||
// `POSTGRES_PORT=5432`,
|
||||
// `REDIS_HOST=$$id-redis`,
|
||||
// ],
|
||||
// "ports": [
|
||||
// "8080"
|
||||
// ]
|
||||
// },
|
||||
// "$$id-postgresql": {
|
||||
// "name": "PostgreSQL",
|
||||
// "depends_on": [],
|
||||
// "image": "postgres:14-alpine",
|
||||
// "volumes": [
|
||||
// "$$id-postgresql-data:/var/lib/postgresql/data",
|
||||
// ],
|
||||
// "environment": [
|
||||
// "POSTGRES_USER=$$config_postgres_user",
|
||||
// "POSTGRES_PASSWORD=$$secret_postgres_password",
|
||||
// "POSTGRES_DB=$$config_postgres_db",
|
||||
// ],
|
||||
// "ports": []
|
||||
// },
|
||||
// "$$id-redis": {
|
||||
// "name": "Redis",
|
||||
// "depends_on": [],
|
||||
// "image": "redis:7-alpine",
|
||||
// "volumes": [
|
||||
// "$$id-redis-data:/data",
|
||||
// ],
|
||||
// "environment": [],
|
||||
// "ports": [],
|
||||
// }
|
||||
// },
|
||||
// "variables": [
|
||||
// {
|
||||
// "id": "$$config_weblate_site_domain",
|
||||
// "main": "$$id",
|
||||
// "name": "WEBLATE_SITE_DOMAIN",
|
||||
// "label": "Weblate Domain",
|
||||
// "defaultValue": "$$generate_domain",
|
||||
// "description": "",
|
||||
// },
|
||||
// {
|
||||
// "id": "$$secret_weblate_admin_password",
|
||||
// "main": "$$id",
|
||||
// "name": "WEBLATE_ADMIN_PASSWORD",
|
||||
// "label": "Weblate Admin Password",
|
||||
// "defaultValue": "$$generate_password",
|
||||
// "description": "",
|
||||
// "extras": {
|
||||
// "isVisibleOnUI": true,
|
||||
// }
|
||||
// },
|
||||
// {
|
||||
// "id": "$$secret_weblate_admin_password2",
|
||||
// "name": "WEBLATE_ADMIN_PASSWORD2",
|
||||
// "label": "Weblate Admin Password2",
|
||||
// "defaultValue": "$$generate_password",
|
||||
// "description": "",
|
||||
// },
|
||||
// {
|
||||
// "id": "$$config_postgres_user",
|
||||
// "main": "$$id-postgresql",
|
||||
// "name": "POSTGRES_USER",
|
||||
// "label": "PostgreSQL User",
|
||||
// "defaultValue": "$$generate_username",
|
||||
// "description": "",
|
||||
// },
|
||||
// {
|
||||
// "id": "$$secret_postgres_password",
|
||||
// "main": "$$id-postgresql",
|
||||
// "name": "POSTGRES_PASSWORD",
|
||||
// "label": "PostgreSQL Password",
|
||||
// "defaultValue": "$$generate_password(32)",
|
||||
// "description": "",
|
||||
// },
|
||||
// {
|
||||
// "id": "$$secret_postgres_password_hex32",
|
||||
// "name": "POSTGRES_PASSWORD_hex32",
|
||||
// "label": "PostgreSQL Password hex32",
|
||||
// "defaultValue": "$$generate_hex(32)",
|
||||
// "description": "",
|
||||
// },
|
||||
// {
|
||||
// "id": "$$config_postgres_something_hex32",
|
||||
// "name": "POSTGRES_SOMETHING_HEX32",
|
||||
// "label": "PostgreSQL Something hex32",
|
||||
// "defaultValue": "$$generate_hex(32)",
|
||||
// "description": "",
|
||||
// },
|
||||
// {
|
||||
// "id": "$$config_postgres_db",
|
||||
// "main": "$$id-postgresql",
|
||||
// "name": "POSTGRES_DB",
|
||||
// "label": "PostgreSQL Database",
|
||||
// "defaultValue": "weblate",
|
||||
// "description": "",
|
||||
// },
|
||||
// {
|
||||
// "id": "$$secret_postgres_secret",
|
||||
// "name": "POSTGRES_SECRET",
|
||||
// "label": "PostgreSQL Secret",
|
||||
// "defaultValue": "",
|
||||
// "description": "",
|
||||
// },
|
||||
// ]
|
||||
// })
|
||||
// }
|
||||
return templates
|
||||
}
|
||||
export async function defaultServiceConfigurations({ id, teamId }) {
|
||||
|
@@ -701,18 +701,21 @@ export async function startService(request: FastifyRequest<ServiceStartStop>) {
|
||||
const config = {};
|
||||
for (const service in template.services) {
|
||||
let newEnvironments = []
|
||||
for (const environment of template.services[service].environment) {
|
||||
const [env, value] = environment.split("=");
|
||||
if (!value.startsWith('$$secret') && value !== '') {
|
||||
newEnvironments.push(`${env}=${value}`)
|
||||
if (template.services[service]?.environment?.length > 0) {
|
||||
for (const environment of template.services[service].environment) {
|
||||
const [env, value] = environment.split("=");
|
||||
if (!value.startsWith('$$secret') && value !== '') {
|
||||
newEnvironments.push(`${env}=${value}`)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
const secrets = await prisma.serviceSecret.findMany({ where: { serviceId: id } })
|
||||
for (const secret of secrets) {
|
||||
const { name, value } = secret
|
||||
if (value) {
|
||||
if (template.services[service].environment.find(env => env.startsWith(`${name}=`)) && !newEnvironments.find(env => env.startsWith(`${name}=`))) {
|
||||
const foundEnv = !!template.services[service].environment?.find(env => env.startsWith(`${name}=`))
|
||||
const foundNewEnv = !!newEnvironments?.find(env => env.startsWith(`${name}=`))
|
||||
if (foundEnv && !foundNewEnv) {
|
||||
newEnvironments.push(`${name}=${decrypt(value)}`)
|
||||
}
|
||||
}
|
||||
@@ -736,7 +739,7 @@ export async function startService(request: FastifyRequest<ServiceStartStop>) {
|
||||
}
|
||||
|
||||
// Generate files for builds
|
||||
if (template.services[service]?.extras?.files?.length > 0) {
|
||||
if (template.services[service]?.files?.length > 0) {
|
||||
if (!template.services[service].build) {
|
||||
template.services[service].build = {
|
||||
context: workdir,
|
||||
@@ -745,7 +748,7 @@ export async function startService(request: FastifyRequest<ServiceStartStop>) {
|
||||
}
|
||||
let Dockerfile = `
|
||||
FROM ${template.services[service].image}`
|
||||
for (const file of template.services[service].extras.files) {
|
||||
for (const file of template.services[service].files) {
|
||||
const { source, destination, content } = file;
|
||||
await fs.writeFile(source, content);
|
||||
Dockerfile += `
|
||||
@@ -754,6 +757,7 @@ export async function startService(request: FastifyRequest<ServiceStartStop>) {
|
||||
await fs.writeFile(`${workdir}/Dockerfile.${service}`, Dockerfile);
|
||||
}
|
||||
}
|
||||
|
||||
const { volumeMounts } = persistentVolumes(id, persistentStorage, config)
|
||||
const composeFile: ComposeFile = {
|
||||
version: '3.8',
|
||||
@@ -766,7 +770,6 @@ export async function startService(request: FastifyRequest<ServiceStartStop>) {
|
||||
volumes: volumeMounts
|
||||
}
|
||||
const composeFileDestination = `${workdir}/docker-compose.yaml`;
|
||||
console.log(composeFileDestination)
|
||||
await fs.writeFile(composeFileDestination, yaml.dump(composeFile));
|
||||
await startServiceContainers(destinationDocker.id, composeFileDestination)
|
||||
return {}
|
||||
|
Reference in New Issue
Block a user