mirror of
https://github.com/ershisan99/coolify.git
synced 2025-12-31 05:09:24 +00:00
v1.0.19 (#64)
This commit is contained in:
74
src/routes/api/v1/services/deploy/code-server/index.ts
Normal file
74
src/routes/api/v1/services/deploy/code-server/index.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
import type { Request } from '@sveltejs/kit';
|
||||
import yaml from 'js-yaml';
|
||||
import { promises as fs } from 'fs';
|
||||
import { docker } from '$lib/api/docker';
|
||||
import { baseServiceConfiguration } from '$lib/api/applications/common';
|
||||
import { cleanupTmp, execShellAsync } from '$lib/api/common';
|
||||
|
||||
export async function post(request: Request) {
|
||||
let { baseURL } = request.body;
|
||||
const traefikURL = baseURL;
|
||||
baseURL = `https://${baseURL}`;
|
||||
const workdir = '/tmp/code-server';
|
||||
const deployId = 'code-server';
|
||||
// const environment = [
|
||||
// { name: 'DOCKER_USER', value: 'root' }
|
||||
|
||||
// ];
|
||||
// const generateEnvsCodeServer = {};
|
||||
// for (const env of environment) generateEnvsCodeServer[env.name] = env.value;
|
||||
|
||||
const stack = {
|
||||
version: '3.8',
|
||||
services: {
|
||||
[deployId]: {
|
||||
image: 'codercom/code-server',
|
||||
command: 'code-server --disable-telemetry',
|
||||
networks: [`${docker.network}`],
|
||||
volumes: [`${deployId}-code-server-data:/home/coder`],
|
||||
// environment: generateEnvsCodeServer,
|
||||
deploy: {
|
||||
...baseServiceConfiguration,
|
||||
labels: [
|
||||
'managedBy=coolify',
|
||||
'type=service',
|
||||
'serviceName=code-server',
|
||||
'configuration=' +
|
||||
JSON.stringify({
|
||||
baseURL
|
||||
}),
|
||||
'traefik.enable=true',
|
||||
'traefik.http.services.' + deployId + '.loadbalancer.server.port=8080',
|
||||
'traefik.http.routers.' + deployId + '.entrypoints=websecure',
|
||||
'traefik.http.routers.' +
|
||||
deployId +
|
||||
'.rule=Host(`' +
|
||||
traefikURL +
|
||||
'`) && PathPrefix(`/`)',
|
||||
'traefik.http.routers.' + deployId + '.tls.certresolver=letsencrypt',
|
||||
'traefik.http.routers.' + deployId + '.middlewares=global-compress'
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
networks: {
|
||||
[`${docker.network}`]: {
|
||||
external: true
|
||||
}
|
||||
},
|
||||
volumes: {
|
||||
[`${deployId}-code-server-data`]: {
|
||||
external: true
|
||||
},
|
||||
},
|
||||
};
|
||||
await execShellAsync(`mkdir -p ${workdir}`);
|
||||
await fs.writeFile(`${workdir}/stack.yml`, yaml.dump(stack));
|
||||
await execShellAsync('docker stack rm code-server');
|
||||
await execShellAsync(`cat ${workdir}/stack.yml | docker stack deploy --prune -c - ${deployId}`);
|
||||
cleanupTmp(workdir);
|
||||
return {
|
||||
status: 200,
|
||||
body: { message: 'OK' }
|
||||
};
|
||||
}
|
||||
25
src/routes/api/v1/services/deploy/code-server/password.ts
Normal file
25
src/routes/api/v1/services/deploy/code-server/password.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { execShellAsync } from '$lib/api/common';
|
||||
import type { Request } from '@sveltejs/kit';
|
||||
import yaml from "js-yaml"
|
||||
|
||||
export async function get(request: Request) {
|
||||
// const { POSTGRESQL_USERNAME, POSTGRESQL_PASSWORD, POSTGRESQL_DATABASE } = JSON.parse(
|
||||
// JSON.parse(
|
||||
// await execShellAsync(
|
||||
// "docker service inspect code-server_code-server --format='{{json .Spec.Labels.configuration}}'"
|
||||
// )
|
||||
// )
|
||||
// ).generateEnvsPostgres;
|
||||
const containers = (await execShellAsync("docker ps -a --format='{{json .Names}}'"))
|
||||
.replace(/"/g, '')
|
||||
.trim()
|
||||
.split('\n');
|
||||
const codeServer = containers.find((container) => container.startsWith('code-server'));
|
||||
const configYaml = yaml.load(await execShellAsync(
|
||||
`docker exec ${codeServer} cat /home/coder/.config/code-server/config.yaml`
|
||||
))
|
||||
return {
|
||||
status: 200,
|
||||
body: { message: 'OK', password: configYaml.password }
|
||||
};
|
||||
}
|
||||
77
src/routes/api/v1/services/deploy/minio/index.ts
Normal file
77
src/routes/api/v1/services/deploy/minio/index.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import type { Request } from '@sveltejs/kit';
|
||||
import yaml from 'js-yaml';
|
||||
import generator from 'generate-password';
|
||||
import { promises as fs } from 'fs';
|
||||
import { docker } from '$lib/api/docker';
|
||||
import { baseServiceConfiguration } from '$lib/api/applications/common';
|
||||
import { cleanupTmp, execShellAsync } from '$lib/api/common';
|
||||
|
||||
export async function post(request: Request) {
|
||||
let { baseURL } = request.body;
|
||||
const traefikURL = baseURL;
|
||||
baseURL = `https://${baseURL}`;
|
||||
const workdir = '/tmp/minio';
|
||||
const deployId = 'minio';
|
||||
const secrets = [
|
||||
{ name: 'MINIO_ROOT_USER', value: generator.generate({ length: 12, numbers: true, strict: true }) },
|
||||
{ name: 'MINIO_ROOT_PASSWORD', value: generator.generate({ length: 24, numbers: true, strict: true }) }
|
||||
|
||||
];
|
||||
const generateEnvsMinIO = {};
|
||||
for (const secret of secrets) generateEnvsMinIO[secret.name] = secret.value;
|
||||
|
||||
const stack = {
|
||||
version: '3.8',
|
||||
services: {
|
||||
[deployId]: {
|
||||
image: 'minio/minio',
|
||||
command: 'server /data',
|
||||
networks: [`${docker.network}`],
|
||||
environment: generateEnvsMinIO,
|
||||
volumes: [`${deployId}-minio-data:/data`],
|
||||
deploy: {
|
||||
...baseServiceConfiguration,
|
||||
labels: [
|
||||
'managedBy=coolify',
|
||||
'type=service',
|
||||
'serviceName=minio',
|
||||
'configuration=' +
|
||||
JSON.stringify({
|
||||
baseURL,
|
||||
generateEnvsMinIO
|
||||
}),
|
||||
'traefik.enable=true',
|
||||
'traefik.http.services.' + deployId + '.loadbalancer.server.port=9000',
|
||||
'traefik.http.routers.' + deployId + '.entrypoints=websecure',
|
||||
'traefik.http.routers.' +
|
||||
deployId +
|
||||
'.rule=Host(`' +
|
||||
traefikURL +
|
||||
'`) && PathPrefix(`/`)',
|
||||
'traefik.http.routers.' + deployId + '.tls.certresolver=letsencrypt',
|
||||
'traefik.http.routers.' + deployId + '.middlewares=global-compress'
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
networks: {
|
||||
[`${docker.network}`]: {
|
||||
external: true
|
||||
}
|
||||
},
|
||||
volumes: {
|
||||
[`${deployId}-minio-data`]: {
|
||||
external: true
|
||||
},
|
||||
},
|
||||
};
|
||||
await execShellAsync(`mkdir -p ${workdir}`);
|
||||
await fs.writeFile(`${workdir}/stack.yml`, yaml.dump(stack));
|
||||
await execShellAsync('docker stack rm minio');
|
||||
await execShellAsync(`cat ${workdir}/stack.yml | docker stack deploy --prune -c - ${deployId}`);
|
||||
cleanupTmp(workdir);
|
||||
return {
|
||||
status: 200,
|
||||
body: { message: 'OK' }
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user