mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
Docker compose support (#111)
* feat(WIP): compose implementation * feat: add volumes, networks, services name hash generate * feat: add compose config test unique * feat: add tests for each unique config * feat: implement lodash for docker compose parsing * feat: add tests for generating compose file * refactor: implement logs docker compose * refactor: composeFile set not empty * feat: implement providers for compose deployments * feat: add Files volumes to compose * feat: add stop compose button * refactor: change strategie of building compose * feat: create .env file in composepath * refactor: simplify git and github function * chore: update deps * refactor: update migrations and add badge to recognize compose type * chore: update lock yaml * refactor: use code editor * feat: add monitoring for app types * refactor: reset stats on change appName * refactor: add option to clean monitoring folder * feat: show current command that will run * feat: add prefix * fix: add missing types * refactor: add docker provider and expose by default as false * refactor: customize error page * refactor: unified deployments to be a single one * feat: add vitest to ci/cd * revert: back to initial version * refactor: add maxconcurrency vitest * refactor: add pool forks to vitest * feat: add pocketbase template * fix: update path resolution compose * removed * feat: add template pocketbase * feat: add pocketbase template * feat: add support button * feat: add plausible template * feat: add calcom template * feat: add version to each template * feat: add code editor to enviroment variables and swarm settings json * refactor: add loader when download the image * fix: use base64 to generate keys plausible * feat: add recognized domain names by enviroment compose * refactor: show alert to redeploy in each card advanced tab * refactor: add validation to prevent create compose if not have permissions * chore: add templates section to contributing * chore: add example contributing
This commit is contained in:
37
templates/calcom/docker-compose.yml
Normal file
37
templates/calcom/docker-compose.yml
Normal file
@@ -0,0 +1,37 @@
|
||||
version: '3.8'
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16-alpine
|
||||
networks:
|
||||
- dokploy-network
|
||||
volumes:
|
||||
- calcom-data:/var/lib/postgresql/data
|
||||
environment:
|
||||
- POSTGRES_USER=postgres
|
||||
- POSTGRES_PASSWORD=password
|
||||
- POSTGRES_DB=db
|
||||
- DATABASE_URL=postgres://postgres:password@postgres:5432/db
|
||||
|
||||
calcom:
|
||||
image: calcom/cal.com:v2.7.6
|
||||
depends_on:
|
||||
- postgres
|
||||
environment:
|
||||
- NEXTAUTH_SECRET=asklmdaklsmdklasmdklasd
|
||||
- CALENDSO_ENCRYPTION_KEY=asklmdaklsmdklasmdklasd
|
||||
- DATABASE_URL=postgres://postgres:password@postgres:5432/db
|
||||
- NEXT_PUBLIC_WEBAPP_URL=http://${CALCOM_HOST}
|
||||
- NEXTAUTH_URL=http://${CALCOM_HOST}/api/auth
|
||||
networks:
|
||||
- dokploy-network
|
||||
labels:
|
||||
- "traefik.enable=true"
|
||||
- "traefik.http.routers.${HASH}.rule=Host(`${CALCOM_HOST}`)"
|
||||
- "traefik.http.services.${HASH}.loadbalancer.server.port=${CALCOM_PORT}"
|
||||
|
||||
networks:
|
||||
dokploy-network:
|
||||
external: true
|
||||
|
||||
volumes:
|
||||
calcom-data:
|
||||
21
templates/calcom/index.ts
Normal file
21
templates/calcom/index.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import {
|
||||
generateHash,
|
||||
generateRandomDomain,
|
||||
type Template,
|
||||
type Schema,
|
||||
} from "../utils";
|
||||
|
||||
// https://cal.com/
|
||||
export function generate(schema: Schema): Template {
|
||||
const mainServiceHash = generateHash(schema.projectName);
|
||||
const randomDomain = generateRandomDomain(schema);
|
||||
const envs = [
|
||||
`CALCOM_HOST=${randomDomain}`,
|
||||
"CALCOM_PORT=3000",
|
||||
`HASH=${mainServiceHash}`,
|
||||
];
|
||||
|
||||
return {
|
||||
envs,
|
||||
};
|
||||
}
|
||||
57
templates/plausible/docker-compose.yml
Normal file
57
templates/plausible/docker-compose.yml
Normal file
@@ -0,0 +1,57 @@
|
||||
services:
|
||||
plausible_db:
|
||||
# Plausible v2.1.0 was tested against PostgreSQL versions 15 and 16
|
||||
# https://github.com/plausible/analytics/blob/v2.1.0/.github/workflows/elixir.yml#L21-L32
|
||||
image: postgres:16-alpine
|
||||
restart: always
|
||||
networks:
|
||||
- dokploy-network
|
||||
volumes:
|
||||
- db-data:/var/lib/postgresql/data
|
||||
environment:
|
||||
- POSTGRES_PASSWORD=postgres
|
||||
|
||||
plausible_events_db:
|
||||
image: clickhouse/clickhouse-server:24.3.3.102-alpine
|
||||
restart: always
|
||||
networks:
|
||||
- dokploy-network
|
||||
volumes:
|
||||
- event-data:/var/lib/clickhouse
|
||||
- event-logs:/var/log/clickhouse-server
|
||||
- ./clickhouse/clickhouse-config.xml:/etc/clickhouse-server/config.d/logging.xml:ro
|
||||
- ./clickhouse/clickhouse-user-config.xml:/etc/clickhouse-server/users.d/logging.xml:ro
|
||||
ulimits:
|
||||
nofile:
|
||||
soft: 262144
|
||||
hard: 262144
|
||||
|
||||
plausible:
|
||||
image: ghcr.io/plausible/community-edition:v2.1.0
|
||||
restart: always
|
||||
command: sh -c "sleep 10 && /entrypoint.sh db createdb && /entrypoint.sh db migrate && /entrypoint.sh run"
|
||||
depends_on:
|
||||
- plausible_db
|
||||
- plausible_events_db
|
||||
ports:
|
||||
- ${PLAUSIBLE_PORT}
|
||||
networks:
|
||||
- dokploy-network
|
||||
env_file:
|
||||
- .env
|
||||
|
||||
labels:
|
||||
- "traefik.enable=true"
|
||||
- "traefik.http.routers.${HASH}.rule=Host(`${PLAUSIBLE_HOST}`)"
|
||||
- "traefik.http.services.${HASH}.loadbalancer.server.port=${PLAUSIBLE_PORT}"
|
||||
volumes:
|
||||
db-data:
|
||||
driver: local
|
||||
event-data:
|
||||
driver: local
|
||||
event-logs:
|
||||
driver: local
|
||||
|
||||
networks:
|
||||
dokploy-network:
|
||||
external: true
|
||||
66
templates/plausible/index.ts
Normal file
66
templates/plausible/index.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import {
|
||||
generateHash,
|
||||
generateRandomDomain,
|
||||
type Template,
|
||||
type Schema,
|
||||
generateBase64,
|
||||
} from "../utils";
|
||||
|
||||
export function generate(schema: Schema): Template {
|
||||
const mainServiceHash = generateHash(schema.projectName);
|
||||
const randomDomain = generateRandomDomain(schema);
|
||||
const secretBase = generateBase64(64);
|
||||
const toptKeyBase = generateBase64(32);
|
||||
|
||||
const envs = [
|
||||
`PLAUSIBLE_HOST=${randomDomain}`,
|
||||
"PLAUSIBLE_PORT=8000",
|
||||
`BASE_URL=http://${randomDomain}`,
|
||||
`SECRET_KEY_BASE=${secretBase}`,
|
||||
`TOTP_VAULT_KEY=${toptKeyBase}`,
|
||||
`HASH=${mainServiceHash}`,
|
||||
];
|
||||
|
||||
const mounts: Template["mounts"] = [
|
||||
{
|
||||
mountPath: "./clickhouse/clickhouse-config.xml",
|
||||
content: `
|
||||
<clickhouse>
|
||||
<logger>
|
||||
<level>warning</level>
|
||||
<console>true</console>
|
||||
</logger>
|
||||
|
||||
<!-- Stop all the unnecessary logging -->
|
||||
<query_thread_log remove="remove"/>
|
||||
<query_log remove="remove"/>
|
||||
<text_log remove="remove"/>
|
||||
<trace_log remove="remove"/>
|
||||
<metric_log remove="remove"/>
|
||||
<asynchronous_metric_log remove="remove"/>
|
||||
<session_log remove="remove"/>
|
||||
<part_log remove="remove"/>
|
||||
</clickhouse>
|
||||
|
||||
`,
|
||||
},
|
||||
{
|
||||
mountPath: "./clickhouse/clickhouse-user-config.xml",
|
||||
content: `
|
||||
<clickhouse>
|
||||
<profiles>
|
||||
<default>
|
||||
<log_queries>0</log_queries>
|
||||
<log_query_threads>0</log_query_threads>
|
||||
</default>
|
||||
</profiles>
|
||||
</clickhouse>
|
||||
`,
|
||||
},
|
||||
];
|
||||
|
||||
return {
|
||||
envs,
|
||||
mounts,
|
||||
};
|
||||
}
|
||||
21
templates/pocketbase/docker-compose.yml
Normal file
21
templates/pocketbase/docker-compose.yml
Normal file
@@ -0,0 +1,21 @@
|
||||
version: "3.7"
|
||||
services:
|
||||
pocketbase:
|
||||
image: spectado/pocketbase:0.22.12
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- ${POCKETBASE_PORT}
|
||||
networks:
|
||||
- dokploy-network
|
||||
labels:
|
||||
- traefik.enable=true
|
||||
- traefik.http.routers.${HASH}.rule=Host(`${POCKETBASE_HOST}`)
|
||||
- traefik.http.services.${HASH}.loadbalancer.server.port=${POCKETBASE_PORT}
|
||||
volumes:
|
||||
- /etc/dokploy/templates/${HASH}/data:/pb_data
|
||||
- /etc/dokploy/templates/${HASH}/public:/pb_public
|
||||
- /etc/dokploy/templates/${HASH}/migrations:/pb_migrations
|
||||
|
||||
networks:
|
||||
dokploy-network:
|
||||
external: true
|
||||
22
templates/pocketbase/index.ts
Normal file
22
templates/pocketbase/index.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import {
|
||||
generateHash,
|
||||
generateRandomDomain,
|
||||
type Template,
|
||||
type Schema,
|
||||
} from "../utils";
|
||||
|
||||
// https://pocketbase.io/docs/
|
||||
export function generate(schema: Schema): Template {
|
||||
const mainServiceHash = generateHash(schema.projectName);
|
||||
const randomDomain = generateRandomDomain(schema);
|
||||
|
||||
const envs = [
|
||||
`POCKETBASE_HOST=${randomDomain}`,
|
||||
"POCKETBASE_PORT=80",
|
||||
`HASH=${mainServiceHash}`,
|
||||
];
|
||||
|
||||
return {
|
||||
envs,
|
||||
};
|
||||
}
|
||||
50
templates/templates.ts
Normal file
50
templates/templates.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import type { TemplateData } from "./types/templates-data.type";
|
||||
|
||||
export const templates: TemplateData[] = [
|
||||
{
|
||||
id: "pocketbase",
|
||||
name: "Pocketbase",
|
||||
version: "v0.22.12",
|
||||
description:
|
||||
"Pocketbase is a self-hosted alternative to Firebase that allows you to build and host your own backend services.",
|
||||
links: {
|
||||
github: "https://github.com/pocketbase/pocketbase",
|
||||
website: "https://pocketbase.io/",
|
||||
docs: "https://pocketbase.io/docs/",
|
||||
},
|
||||
logo: "pocketbase.svg",
|
||||
load: () => import("./pocketbase/index").then((m) => m.generate),
|
||||
tags: ["database", "cms", "headless"],
|
||||
},
|
||||
{
|
||||
id: "plausible",
|
||||
name: "Plausible",
|
||||
version: "v2.1.0",
|
||||
description:
|
||||
"Plausible is a open source, self-hosted web analytics platform that lets you track website traffic and user behavior.",
|
||||
logo: "plausible.svg",
|
||||
links: {
|
||||
github: "https://github.com/plausible/plausible",
|
||||
website: "https://plausible.io/",
|
||||
docs: "https://plausible.io/docs",
|
||||
},
|
||||
tags: ["analytics"],
|
||||
load: () => import("./plausible/index").then((m) => m.generate),
|
||||
},
|
||||
{
|
||||
id: "calcom",
|
||||
name: "Calcom",
|
||||
version: "2.7.6",
|
||||
description:
|
||||
"Calcom is a open source alternative to Calendly that allows to create scheduling and booking services.",
|
||||
|
||||
links: {
|
||||
github: "https://github.com/calcom/cal.com",
|
||||
website: "https://cal.com/",
|
||||
docs: "https://cal.com/docs",
|
||||
},
|
||||
logo: "calcom.jpg",
|
||||
tags: ["scheduling", "booking"],
|
||||
load: () => import("./calcom/index").then((m) => m.generate),
|
||||
},
|
||||
];
|
||||
67
templates/types/templates-data.type.ts
Normal file
67
templates/types/templates-data.type.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import type { templates } from "../templates";
|
||||
import type { Schema, Template } from "../utils";
|
||||
|
||||
/**
|
||||
* Type representing the keys of the templates.
|
||||
*/
|
||||
export type TemplatesKeys = (typeof templates)[number]["id"];
|
||||
|
||||
/**
|
||||
* Interface representing the data structure for a template.
|
||||
*/
|
||||
export type TemplateData = {
|
||||
/**
|
||||
* Unique identifier for the template.
|
||||
*/
|
||||
id: string;
|
||||
|
||||
/**
|
||||
* Name of the template.
|
||||
*/
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* Description of the template Max(150 Characters).
|
||||
*/
|
||||
description: string;
|
||||
|
||||
/**
|
||||
* Links related to the template.
|
||||
*/
|
||||
links: {
|
||||
/**
|
||||
* GitHub repository link for the template.
|
||||
*/
|
||||
github: string;
|
||||
|
||||
/**
|
||||
* Optional documentation link for the template.
|
||||
*/
|
||||
docs?: string;
|
||||
|
||||
/**
|
||||
* Optional website link for the template.
|
||||
*/
|
||||
website?: string;
|
||||
};
|
||||
/**
|
||||
* Version of the template.
|
||||
*/
|
||||
version: string;
|
||||
|
||||
/**
|
||||
* Tags associated with the template.
|
||||
*/
|
||||
tags: string[];
|
||||
|
||||
/**
|
||||
* Name of the logo file with extension (e.g. pocketbase.png).
|
||||
*/
|
||||
logo: string;
|
||||
|
||||
/**
|
||||
* Function to load the template, returning a promise that resolves with a function
|
||||
* taking a schema and returning a template.
|
||||
*/
|
||||
load: () => Promise<(schema: Schema) => Template>;
|
||||
};
|
||||
68
templates/utils/index.ts
Normal file
68
templates/utils/index.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import { randomBytes } from "node:crypto";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { templates } from "../templates";
|
||||
import type { TemplatesKeys } from "../types/templates-data.type";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
export interface Schema {
|
||||
serverIp: string;
|
||||
projectName: string;
|
||||
}
|
||||
|
||||
export interface Template {
|
||||
envs: string[];
|
||||
mounts?: {
|
||||
mountPath: string;
|
||||
content?: string;
|
||||
}[];
|
||||
}
|
||||
|
||||
export const generateRandomDomain = ({
|
||||
serverIp,
|
||||
projectName,
|
||||
}: Schema): string => {
|
||||
const hash = randomBytes(3).toString("hex");
|
||||
const slugIp = serverIp.replaceAll(".", "-");
|
||||
return `${projectName}-${hash}-${slugIp}.traefik.me`;
|
||||
};
|
||||
|
||||
export const generateHash = (projectName: string, quantity = 3): string => {
|
||||
const hash = randomBytes(quantity).toString("hex");
|
||||
return `${projectName}-${hash}`;
|
||||
};
|
||||
|
||||
export const generatePassword = (quantity = 16): string => {
|
||||
return randomBytes(Math.ceil(quantity / 2))
|
||||
.toString("hex")
|
||||
.slice(0, quantity);
|
||||
};
|
||||
|
||||
export const generateBase64 = (bytes = 32): string => {
|
||||
return randomBytes(bytes).toString("base64");
|
||||
};
|
||||
|
||||
export const loadTemplateModule = async (
|
||||
id: TemplatesKeys,
|
||||
): Promise<(schema: Schema) => Template> => {
|
||||
const templateLoader = templates.find((t) => t.id === id);
|
||||
if (!templateLoader) {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: `Template ${id} not found or not implemented yet`,
|
||||
});
|
||||
}
|
||||
|
||||
const generate = await templateLoader.load();
|
||||
return generate;
|
||||
};
|
||||
|
||||
export const readComposeFile = async (id: string) => {
|
||||
const cwd = process.cwd();
|
||||
const composeFile = await readFile(
|
||||
join(cwd, ".next", "templates", id, "docker-compose.yml"),
|
||||
"utf8",
|
||||
);
|
||||
|
||||
return composeFile;
|
||||
};
|
||||
Reference in New Issue
Block a user