This commit is contained in:
Andras Bacsai
2021-06-17 20:47:09 +02:00
committed by GitHub
parent dae91267e8
commit d43cd663d2
23 changed files with 1142 additions and 1742 deletions

View 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' }
};
}

View 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 }
};
}

View 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' }
};
}