Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

Merge branch 'next' into grafana-service

Andras Bacsai78076f7854c8
diff --cc apps/api/src/lib/services/handlers.ts
index 41ce8e0e7e,30c994b0b1..cc66467373
--- a/apps/api/src/lib/services/handlers.ts
+++ b/apps/api/src/lib/services/handlers.ts
@@@ -2593,57 -2641,23 +2644,78 @@@ async function startTaigaService(reques
}
}
+async function startGrafanaService(request: FastifyRequest<ServiceStartStop>) {
+ try {
+ const { id } = request.params;
+ const teamId = request.user.teamId;
+ const service = await getServiceFromDB({ id, teamId });
+ const { type, version, destinationDockerId, destinationDocker, serviceSecret, exposePort, persistentStorage } =
+ service;
+ const network = destinationDockerId && destinationDocker.network;
+ const port = getServiceMainPort('grafana');
+
+ const { workdir } = await createDirectories({ repository: type, buildId: id });
+ const image = getServiceImage(type);
+
+ const config = {
+ grafana: {
+ image: `${image}:${version}`,
+ volumes: [`${id}-grafana:/var/lib/grafana`],
+ environmentVariables: {}
+ }
+ };
+ if (serviceSecret.length > 0) {
+ serviceSecret.forEach((secret) => {
+ config.grafana.environmentVariables[secret.name] = secret.value;
+ });
+ }
+ const { volumeMounts } = persistentVolumes(id, persistentStorage, config)
+ const composeFile: ComposeFile = {
+ version: '3.8',
+ services: {
+ [id]: {
+ container_name: id,
+ image: config.grafana.image,
+ volumes: config.grafana.volumes,
+ environment: config.grafana.environmentVariables,
+ ...(exposePort ? { ports: [`${exposePort}:${port}`] } : {}),
+ labels: makeLabelForServices('grafana'),
+ ...defaultComposeConfiguration(network),
+ }
+ },
+ networks: {
+ [network]: {
+ external: true
+ }
+ },
+ volumes: volumeMounts
+ };
+ const composeFileDestination = `${workdir}/docker-compose.yaml`;
+ await fs.writeFile(composeFileDestination, yaml.dump(composeFile));
+ await startServiceContainers(destinationDocker.id, composeFileDestination)
+ return {}
+ } catch ({ status, message }) {
+ return errorHandler({ status, message })
+ }
- }
++}
++
+ export async function migrateAppwriteDB(request: FastifyRequest<OnlyId>, reply: FastifyReply) {
+ try {
+ const { id } = request.params
+ const teamId = request.user.teamId;
+ const {
+ destinationDockerId,
+ destinationDocker,
+ } = await getServiceFromDB({ id, teamId });
+ if (destinationDockerId) {
+ await executeDockerCmd({
+ dockerId: destinationDocker.id,
+ command: `docker exec ${id} migrate`
+ })
+ return await reply.code(201).send()
+ }
+ throw { status: 500, message: 'Could cleanup logs.' }
+ } catch ({ status, message }) {
+ return errorHandler({ status, message })
+ }
+ }