fix: remove new service start process
This commit is contained in:
@@ -1502,10 +1502,10 @@ export function convertTolOldVolumeNames(type) {
|
|||||||
return 'nc'
|
return 'nc'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export async function getAvailableServices(): Promise<any> {
|
// export async function getAvailableServices(): Promise<any> {
|
||||||
const { data } = await axios.get(`https://gist.githubusercontent.com/andrasbacsai/4aac36d8d6214dbfc34fa78110554a50/raw/291a957ee6ac01d480465623e183a30230ad921f/availableServices.json`)
|
// const { data } = await axios.get(`https://gist.githubusercontent.com/andrasbacsai/4aac36d8d6214dbfc34fa78110554a50/raw/5b27e6c37d78aaeedc1148d797112c827a2f43cf/availableServices.json`)
|
||||||
return data
|
// return data
|
||||||
}
|
// }
|
||||||
export async function cleanupDockerStorage(host, lowDiskSpace, force) {
|
export async function cleanupDockerStorage(host, lowDiskSpace, force) {
|
||||||
// Cleanup old coolify images
|
// Cleanup old coolify images
|
||||||
try {
|
try {
|
||||||
|
@@ -2,7 +2,7 @@ import type { FastifyReply, FastifyRequest } from 'fastify';
|
|||||||
import fs from 'fs/promises';
|
import fs from 'fs/promises';
|
||||||
import yaml from 'js-yaml';
|
import yaml from 'js-yaml';
|
||||||
import bcrypt from 'bcryptjs';
|
import bcrypt from 'bcryptjs';
|
||||||
import { prisma, uniqueName, asyncExecShell, getServiceImage, getServiceImages, configureServiceType, getServiceFromDB, getContainerUsage, removeService, isDomainConfigured, saveUpdateableFields, fixType, decrypt, encrypt, getServiceMainPort, createDirectories, ComposeFile, makeLabelForServices, getFreePort, getDomain, errorHandler, supportedServiceTypesAndVersions, generatePassword, isDev, stopTcpHttpProxy, getAvailableServices, convertTolOldVolumeNames } from '../../../../lib/common';
|
import { prisma, uniqueName, asyncExecShell, getServiceImage, getServiceImages, configureServiceType, getServiceFromDB, getContainerUsage, removeService, isDomainConfigured, saveUpdateableFields, fixType, decrypt, encrypt, getServiceMainPort, createDirectories, ComposeFile, makeLabelForServices, getFreePort, getDomain, errorHandler, supportedServiceTypesAndVersions, generatePassword, isDev, stopTcpHttpProxy } from '../../../../lib/common';
|
||||||
import { day } from '../../../../lib/dayjs';
|
import { day } from '../../../../lib/dayjs';
|
||||||
import { checkContainer, dockerInstance, getEngine, removeContainer } from '../../../../lib/docker';
|
import { checkContainer, dockerInstance, getEngine, removeContainer } from '../../../../lib/docker';
|
||||||
import cuid from 'cuid';
|
import cuid from 'cuid';
|
||||||
@@ -10,69 +10,137 @@ import cuid from 'cuid';
|
|||||||
import type { OnlyId } from '../../../../types';
|
import type { OnlyId } from '../../../../types';
|
||||||
import type { ActivateWordpressFtp, CheckService, DeleteServiceSecret, DeleteServiceStorage, GetServiceLogs, SaveService, SaveServiceDestination, SaveServiceSecret, SaveServiceSettings, SaveServiceStorage, SaveServiceType, SaveServiceVersion, ServiceStartStop, SetWordpressSettings } from './types';
|
import type { ActivateWordpressFtp, CheckService, DeleteServiceSecret, DeleteServiceStorage, GetServiceLogs, SaveService, SaveServiceDestination, SaveServiceSecret, SaveServiceSettings, SaveServiceStorage, SaveServiceType, SaveServiceVersion, ServiceStartStop, SetWordpressSettings } from './types';
|
||||||
|
|
||||||
async function startServiceNew(request: FastifyRequest<OnlyId>) {
|
// async function startServiceNew(request: FastifyRequest<OnlyId>) {
|
||||||
try {
|
// try {
|
||||||
const { id } = request.params;
|
// const { id } = request.params;
|
||||||
const teamId = request.user.teamId;
|
// const teamId = request.user.teamId;
|
||||||
const service = await getServiceFromDB({ id, teamId });
|
// const service = await getServiceFromDB({ id, teamId });
|
||||||
const { type, version, destinationDockerId, destinationDocker, serviceSecret, exposePort } =
|
// const { type, version, destinationDockerId, destinationDocker, serviceSecret, exposePort } =
|
||||||
service;
|
// service;
|
||||||
const network = destinationDockerId && destinationDocker.network;
|
// const network = destinationDockerId && destinationDocker.network;
|
||||||
const host = getEngine(destinationDocker.engine);
|
// const host = getEngine(destinationDocker.engine);
|
||||||
const port = getServiceMainPort(type);
|
// const port = getServiceMainPort(type);
|
||||||
|
|
||||||
const { workdir } = await createDirectories({ repository: type, buildId: id });
|
// const { workdir } = await createDirectories({ repository: type, buildId: id });
|
||||||
const image = getServiceImage(type);
|
// const image = getServiceImage(type);
|
||||||
const config = (await getAvailableServices()).find((name) => name.name === type).compose
|
// const config = (await getAvailableServices()).find((name) => name.name === type).compose
|
||||||
const environmentVariables = {}
|
// const environmentVariables = {}
|
||||||
if (serviceSecret.length > 0) {
|
// if (serviceSecret.length > 0) {
|
||||||
serviceSecret.forEach((secret) => {
|
// serviceSecret.forEach((secret) => {
|
||||||
environmentVariables[secret.name] = secret.value;
|
// environmentVariables[secret.name] = secret.value;
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
config.services[id] = JSON.parse(JSON.stringify(config.services[type]))
|
// config.newVolumes = {}
|
||||||
config.services[id].container_name = id
|
// for (const service of Object.entries(config.services)) {
|
||||||
config.services[id].image = `${image}:${version}`
|
// const name = service[0]
|
||||||
config.services[id].ports = (exposePort ? [`${exposePort}:${port}`] : []),
|
// const details: any = service[1]
|
||||||
config.services[id].restart = "always"
|
// config.services[`${id}-${name}`] = JSON.parse(JSON.stringify(details))
|
||||||
config.services[id].networks = [network]
|
// config.services[`${id}-${name}`].container_name = `${id}-${name}`
|
||||||
config.services[id].labels = makeLabelForServices(type)
|
// config.services[`${id}-${name}`].restart = "always"
|
||||||
config.services[id].deploy = {
|
// config.services[`${id}-${name}`].networks = [network]
|
||||||
restart_policy: {
|
// config.services[`${id}-${name}`].labels = makeLabelForServices(type)
|
||||||
condition: 'on-failure',
|
// if (name === config.name) {
|
||||||
delay: '5s',
|
// config.services[`${id}-${name}`].image = `${details.image.split(':')[0]}:${version}`
|
||||||
max_attempts: 3,
|
// config.services[`${id}-${name}`].ports = (exposePort ? [`${exposePort}:${port}`] : [])
|
||||||
window: '120s'
|
// config.services[`${id}-${name}`].environment = environmentVariables
|
||||||
}
|
// }
|
||||||
}
|
// config.services[`${id}-${name}`].deploy = {
|
||||||
config.networks = {
|
// restart_policy: {
|
||||||
[network]: {
|
// condition: 'on-failure',
|
||||||
external: true
|
// delay: '5s',
|
||||||
}
|
// max_attempts: 3,
|
||||||
}
|
// window: '120s'
|
||||||
config.volumes = {}
|
// }
|
||||||
config.services[id].volumes.forEach((volume, index) => {
|
// }
|
||||||
let oldVolumeName = volume.split(':')[0]
|
// if (config.services[`${id}-${name}`]?.volumes?.length > 0) {
|
||||||
const path = volume.split(':')[1]
|
// config.services[`${id}-${name}`].volumes.forEach((volume, index) => {
|
||||||
oldVolumeName = convertTolOldVolumeNames(type)
|
// let oldVolumeName = volume.split(':')[0]
|
||||||
const volumeName = `${id}-${oldVolumeName}`
|
// const path = volume.split(':')[1]
|
||||||
config.volumes[volumeName] = {
|
// // if (config?.volumes[oldVolumeName]) delete config?.volumes[oldVolumeName]
|
||||||
name: volumeName
|
// const newName = convertTolOldVolumeNames(type)
|
||||||
}
|
// if (newName) oldVolumeName = newName
|
||||||
config.services[id].volumes[index] = `${volumeName}:${path}`
|
|
||||||
})
|
|
||||||
delete config.services[type]
|
|
||||||
config.services[id].environment = environmentVariables
|
|
||||||
const composeFileDestination = `${workdir}/docker-compose.yaml`;
|
|
||||||
await fs.writeFile(composeFileDestination, yaml.dump(config));
|
|
||||||
await asyncExecShell(`DOCKER_HOST=${host} docker compose -f ${composeFileDestination} pull`);
|
|
||||||
await asyncExecShell(`DOCKER_HOST=${host} docker compose -f ${composeFileDestination} up -d`);
|
|
||||||
return {}
|
|
||||||
} catch ({ status, message }) {
|
|
||||||
return errorHandler({ status, message })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// const volumeName = `${id}-${oldVolumeName}`
|
||||||
|
// config.newVolumes[volumeName] = {
|
||||||
|
// name: volumeName
|
||||||
|
// }
|
||||||
|
// config.services[`${id}-${name}`].volumes[index] = `${volumeName}:${path}`
|
||||||
|
// })
|
||||||
|
// config.services[`${id}-${config.name}`] = {
|
||||||
|
// ...config.services[`${id}-${config.name}`],
|
||||||
|
// environment: environmentVariables
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// config.networks = {
|
||||||
|
// [network]: {
|
||||||
|
// external: true
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// config.volumes = config.newVolumes
|
||||||
|
|
||||||
|
// // config.services[`${id}-${name}`]?.volumes?.length > 0 && config.services[`${id}-${name}`].volumes.forEach((volume, index) => {
|
||||||
|
// // let oldVolumeName = volume.split(':')[0]
|
||||||
|
// // const path = volume.split(':')[1]
|
||||||
|
// // oldVolumeName = convertTolOldVolumeNames(type)
|
||||||
|
// // const volumeName = `${id}-${oldVolumeName}`
|
||||||
|
// // config.volumes[volumeName] = {
|
||||||
|
// // name: volumeName
|
||||||
|
// // }
|
||||||
|
// // config.services[`${id}-${name}`].volumes[index] = `${volumeName}:${path}`
|
||||||
|
// // })
|
||||||
|
// // config.services[`${id}-${config.name}`] = {
|
||||||
|
// // ...config.services[`${id}-${config.name}`],
|
||||||
|
// // environment: environmentVariables
|
||||||
|
// // }
|
||||||
|
// delete config.services[name]
|
||||||
|
|
||||||
|
// }
|
||||||
|
// console.log(config.services)
|
||||||
|
// console.log(config.volumes)
|
||||||
|
|
||||||
|
// // config.services[id] = JSON.parse(JSON.stringify(config.services[type]))
|
||||||
|
// // config.services[id].container_name = id
|
||||||
|
// // config.services[id].image = `${image}:${version}`
|
||||||
|
// // config.services[id].ports = (exposePort ? [`${exposePort}:${port}`] : []),
|
||||||
|
// // config.services[id].restart = "always"
|
||||||
|
// // config.services[id].networks = [network]
|
||||||
|
// // config.services[id].labels = makeLabelForServices(type)
|
||||||
|
// // config.services[id].deploy = {
|
||||||
|
// // restart_policy: {
|
||||||
|
// // condition: 'on-failure',
|
||||||
|
// // delay: '5s',
|
||||||
|
// // max_attempts: 3,
|
||||||
|
// // window: '120s'
|
||||||
|
// // }
|
||||||
|
// // }
|
||||||
|
// // config.networks = {
|
||||||
|
// // [network]: {
|
||||||
|
// // external: true
|
||||||
|
// // }
|
||||||
|
// // }
|
||||||
|
// // config.volumes = {}
|
||||||
|
// // config.services[id].volumes.forEach((volume, index) => {
|
||||||
|
// // let oldVolumeName = volume.split(':')[0]
|
||||||
|
// // const path = volume.split(':')[1]
|
||||||
|
// // oldVolumeName = convertTolOldVolumeNames(type)
|
||||||
|
// // const volumeName = `${id}-${oldVolumeName}`
|
||||||
|
// // config.volumes[volumeName] = {
|
||||||
|
// // name: volumeName
|
||||||
|
// // }
|
||||||
|
// // config.services[id].volumes[index] = `${volumeName}:${path}`
|
||||||
|
// // })
|
||||||
|
// // delete config.services[type]
|
||||||
|
// // config.services[id].environment = environmentVariables
|
||||||
|
// const composeFileDestination = `${workdir}/docker-compose.yaml`;
|
||||||
|
// // await fs.writeFile(composeFileDestination, yaml.dump(config));
|
||||||
|
// // await asyncExecShell(`DOCKER_HOST=${host} docker compose -f ${composeFileDestination} pull`);
|
||||||
|
// // await asyncExecShell(`DOCKER_HOST=${host} docker compose -f ${composeFileDestination} up -d`);
|
||||||
|
// return {}
|
||||||
|
// } catch ({ status, message }) {
|
||||||
|
// return errorHandler({ status, message })
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
export async function listServices(request: FastifyRequest) {
|
export async function listServices(request: FastifyRequest) {
|
||||||
try {
|
try {
|
||||||
|
Reference in New Issue
Block a user