mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
Merge pull request #13 from Dokploy/add-docker-compose
Add docker compose
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -6,6 +6,8 @@
|
|||||||
.pnp.js
|
.pnp.js
|
||||||
/redis-data
|
/redis-data
|
||||||
traefik.yml
|
traefik.yml
|
||||||
|
.docker
|
||||||
|
.env.production
|
||||||
|
|
||||||
# testing
|
# testing
|
||||||
/coverage
|
/coverage
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ feat: add new feature
|
|||||||
```bash
|
```bash
|
||||||
git clone https://github.com/dokploy/dokploy.git
|
git clone https://github.com/dokploy/dokploy.git
|
||||||
cd dokploy
|
cd dokploy
|
||||||
npm install
|
pnpm install
|
||||||
cp .env.example .env
|
cp .env.example .env
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -62,28 +62,40 @@ cp .env.example .env
|
|||||||
|
|
||||||
Is required to have **Docker** installed on your machine.
|
Is required to have **Docker** installed on your machine.
|
||||||
|
|
||||||
|
|
||||||
|
### Setup
|
||||||
|
|
||||||
|
Run the command that will spin up all the required services and files.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm run dev
|
pnpm run setup
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Now run the development server.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm run dev
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
Go to http://localhost:3000 to see the development server
|
Go to http://localhost:3000 to see the development server
|
||||||
|
|
||||||
## Build
|
## Build
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm run build
|
pnpm run build
|
||||||
```
|
```
|
||||||
|
|
||||||
## Docker
|
## Docker
|
||||||
|
|
||||||
To build the docker image
|
To build the docker image
|
||||||
```bash
|
```bash
|
||||||
npm run docker:build
|
pnpm run docker:build
|
||||||
```
|
```
|
||||||
|
|
||||||
To push the docker image
|
To push the docker image
|
||||||
```bash
|
```bash
|
||||||
npm run docker:push
|
pnpm run docker:push
|
||||||
```
|
```
|
||||||
|
|
||||||
## Password Reset
|
## Password Reset
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ export const Login2FA = ({ authId }: Props) => {
|
|||||||
duration: 2000,
|
duration: 2000,
|
||||||
});
|
});
|
||||||
|
|
||||||
push("/dashboard");
|
push("/dashboard/projects");
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
toast.error("Signin failed", {
|
toast.error("Signin failed", {
|
||||||
|
|||||||
20
migration.ts
Normal file
20
migration.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { drizzle } from "drizzle-orm/postgres-js";
|
||||||
|
import { migrate } from "drizzle-orm/postgres-js/migrator";
|
||||||
|
import postgres from "postgres";
|
||||||
|
|
||||||
|
const connectionString = process.env.DATABASE_URL || "";
|
||||||
|
|
||||||
|
const sql = postgres(connectionString, { max: 1 });
|
||||||
|
const db = drizzle(sql);
|
||||||
|
|
||||||
|
await migrate(db, { migrationsFolder: "drizzle" })
|
||||||
|
.then(() => {
|
||||||
|
console.log("Migration complete");
|
||||||
|
sql.end();
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.log("Migration failed", error);
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
sql.end();
|
||||||
|
});
|
||||||
@@ -9,12 +9,14 @@
|
|||||||
"start": "node dist/server.mjs",
|
"start": "node dist/server.mjs",
|
||||||
"build-server": "tsx esbuild.config.ts",
|
"build-server": "tsx esbuild.config.ts",
|
||||||
"build-next": "next build",
|
"build-next": "next build",
|
||||||
|
"setup": "tsx -r dotenv/config setup.ts && sleep 5 && pnpm run migration:run",
|
||||||
"reset-password": "node dist/reset-password.mjs",
|
"reset-password": "node dist/reset-password.mjs",
|
||||||
"dev": "tsx watch -r dotenv/config ./server/server.ts --project tsconfig.server.json ",
|
"dev": "tsx watch -r dotenv/config ./server/server.ts --project tsconfig.server.json ",
|
||||||
"migration:generate": "drizzle-kit generate:pg --config ./server/db/drizzle.config.ts",
|
"migration:generate": "drizzle-kit generate:pg --config ./server/db/drizzle.config.ts",
|
||||||
"migration:run": "tsx -r dotenv/config migration.ts",
|
"migration:run": "tsx -r dotenv/config migration.ts",
|
||||||
"migration:drop": "drizzle-kit drop --config ./server/db/drizzle.config.ts",
|
"migration:drop": "drizzle-kit drop --config ./server/db/drizzle.config.ts",
|
||||||
"db:push": "drizzle-kit push:pg --config ./server/db/drizzle.config.ts",
|
"db:push": "drizzle-kit push:pg --config ./server/db/drizzle.config.ts",
|
||||||
|
"db:truncate": "tsx -r dotenv/config ./server/db/reset.ts",
|
||||||
"db:studio": "drizzle-kit studio",
|
"db:studio": "drizzle-kit studio",
|
||||||
"lint": "biome lint",
|
"lint": "biome lint",
|
||||||
"db:seed": "dotenv tsx ./server/db/seed.ts",
|
"db:seed": "dotenv tsx ./server/db/seed.ts",
|
||||||
@@ -127,6 +129,7 @@
|
|||||||
"initVersion": "7.25.2"
|
"initVersion": "7.25.2"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "18.x"
|
"node": "^18.18.0",
|
||||||
}
|
"pnpm": "^8.15.4"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ export async function getServerSideProps(
|
|||||||
return {
|
return {
|
||||||
redirect: {
|
redirect: {
|
||||||
permanent: false,
|
permanent: false,
|
||||||
destination: "/dashboard",
|
destination: "/dashboard/projects",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ export async function getServerSideProps(
|
|||||||
return {
|
return {
|
||||||
redirect: {
|
redirect: {
|
||||||
permanent: false,
|
permanent: false,
|
||||||
destination: "/dashboard",
|
destination: "/dashboard/projects",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -213,7 +213,7 @@ export async function getServerSideProps(
|
|||||||
return {
|
return {
|
||||||
redirect: {
|
redirect: {
|
||||||
permanent: false,
|
permanent: false,
|
||||||
destination: "/dashboard",
|
destination: "/dashboard/projects",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ export async function getServerSideProps(
|
|||||||
return {
|
return {
|
||||||
redirect: {
|
redirect: {
|
||||||
permanent: false,
|
permanent: false,
|
||||||
destination: "/dashboard",
|
destination: "/dashboard/projects",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ export async function getServerSideProps(
|
|||||||
return {
|
return {
|
||||||
redirect: {
|
redirect: {
|
||||||
permanent: false,
|
permanent: false,
|
||||||
destination: "/dashboard",
|
destination: "/dashboard/projects",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ export async function getServerSideProps(
|
|||||||
return {
|
return {
|
||||||
redirect: {
|
redirect: {
|
||||||
permanent: false,
|
permanent: false,
|
||||||
destination: "/dashboard",
|
destination: "/dashboard/projects",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ export async function getServerSideProps(
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
console.log(user);
|
|
||||||
if (user.rol === "user") {
|
if (user.rol === "user") {
|
||||||
return {
|
return {
|
||||||
redirect: {
|
redirect: {
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
import Docker from "dockerode";
|
import Docker from "dockerode";
|
||||||
|
import path from "node:path";
|
||||||
|
|
||||||
export const BASE_PATH = "/etc/dokploy";
|
export const BASE_PATH =
|
||||||
|
process.env.NODE_ENV === "production"
|
||||||
|
? "/etc/dokploy"
|
||||||
|
: path.join(process.cwd(), ".docker");
|
||||||
export const MAIN_TRAEFIK_PATH = `${BASE_PATH}/traefik`;
|
export const MAIN_TRAEFIK_PATH = `${BASE_PATH}/traefik`;
|
||||||
export const DYNAMIC_TRAEFIK_PATH = `${BASE_PATH}/traefik/dynamic`;
|
export const DYNAMIC_TRAEFIK_PATH = `${BASE_PATH}/traefik/dynamic`;
|
||||||
export const LOGS_PATH = `${BASE_PATH}/logs`;
|
export const LOGS_PATH = `${BASE_PATH}/logs`;
|
||||||
|
|||||||
@@ -10,9 +10,10 @@ const db = drizzle(pg);
|
|||||||
|
|
||||||
const clearDb = async (): Promise<void> => {
|
const clearDb = async (): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const tablesQuery = sql<string>`DROP SCHEMA public CASCADE; CREATE SCHEMA public;`;
|
const tablesQuery = sql<string>`DROP SCHEMA public CASCADE; CREATE SCHEMA public; DROP schema drizzle CASCADE;`;
|
||||||
const tables = await db.execute(tablesQuery);
|
const tables = await db.execute(tablesQuery);
|
||||||
console.log(tables);
|
console.log(tables);
|
||||||
|
await pg.end();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error to clean database", error);
|
console.error("Error to clean database", error);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -34,31 +34,32 @@ void app.prepare().then(async () => {
|
|||||||
handle(req, res);
|
handle(req, res);
|
||||||
});
|
});
|
||||||
|
|
||||||
setupDirectories();
|
|
||||||
createDefaultMiddlewares();
|
|
||||||
await initializeNetwork();
|
|
||||||
await initializeSwarm();
|
|
||||||
createDefaultTraefikConfig();
|
|
||||||
createDefaultServerTraefikConfig();
|
|
||||||
await initializeTraefik();
|
|
||||||
await initializeRedis();
|
|
||||||
await initializePostgres();
|
|
||||||
|
|
||||||
// WEBSOCKET
|
// WEBSOCKET
|
||||||
setupDeploymentLogsWebSocketServer(server);
|
setupDeploymentLogsWebSocketServer(server);
|
||||||
setupDockerContainerLogsWebSocketServer(server);
|
setupDockerContainerLogsWebSocketServer(server);
|
||||||
setupDockerContainerTerminalWebSocketServer(server);
|
setupDockerContainerTerminalWebSocketServer(server);
|
||||||
setupTerminalWebSocketServer(server);
|
setupTerminalWebSocketServer(server);
|
||||||
setupDockerStatsMonitoringSocketServer(server);
|
setupDockerStatsMonitoringSocketServer(server);
|
||||||
|
|
||||||
if (process.env.NODE_ENV === "production") {
|
if (process.env.NODE_ENV === "production") {
|
||||||
// Cron Jobs
|
setupDirectories();
|
||||||
|
createDefaultMiddlewares();
|
||||||
|
await initializeSwarm();
|
||||||
|
await initializeNetwork();
|
||||||
|
createDefaultTraefikConfig();
|
||||||
|
createDefaultServerTraefikConfig();
|
||||||
|
await initializeTraefik();
|
||||||
|
await initializeRedis();
|
||||||
|
await initializePostgres();
|
||||||
initCronJobs();
|
initCronJobs();
|
||||||
welcomeServer();
|
welcomeServer();
|
||||||
|
|
||||||
|
// Timeout to wait for the database to be ready
|
||||||
await new Promise((resolve) => setTimeout(resolve, 7000));
|
await new Promise((resolve) => setTimeout(resolve, 7000));
|
||||||
await migration();
|
await migration();
|
||||||
}
|
}
|
||||||
server.listen(PORT);
|
server.listen(PORT);
|
||||||
|
console.log("Server Started:", PORT);
|
||||||
deploymentWorker.run();
|
deploymentWorker.run();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Main Server Error", e);
|
console.error("Main Server Error", e);
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ export const initializePostgres = async () => {
|
|||||||
|
|
||||||
console.log("Postgres Started ✅");
|
console.log("Postgres Started ✅");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
|
||||||
await docker.createService(settings);
|
await docker.createService(settings);
|
||||||
console.log("Postgres Not Found: Starting ✅");
|
console.log("Postgres Not Found: Starting ✅");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ export const dockerSwarmInitialized = async () => {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ export const createDefaultTraefikConfig = () => {
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
file: {
|
file: {
|
||||||
directory: DYNAMIC_TRAEFIK_PATH,
|
directory: "/etc/dokploy/traefik/dynamic",
|
||||||
watch: true,
|
watch: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
26
setup.ts
Normal file
26
setup.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import {
|
||||||
|
createDefaultMiddlewares,
|
||||||
|
createDefaultServerTraefikConfig,
|
||||||
|
createDefaultTraefikConfig,
|
||||||
|
initializeTraefik,
|
||||||
|
} from "./server/setup/traefik-setup";
|
||||||
|
import { initializeRedis } from "./server/setup/redis-setup";
|
||||||
|
import { initializePostgres } from "./server/setup/postgres-setup";
|
||||||
|
import { setupDirectories } from "./server/setup/config-paths";
|
||||||
|
import { initializeNetwork, initializeSwarm } from "./server/setup/setup";
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
setupDirectories();
|
||||||
|
createDefaultMiddlewares();
|
||||||
|
await initializeSwarm();
|
||||||
|
await initializeNetwork();
|
||||||
|
createDefaultTraefikConfig();
|
||||||
|
createDefaultServerTraefikConfig();
|
||||||
|
await initializeTraefik();
|
||||||
|
await initializeRedis();
|
||||||
|
await initializePostgres();
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Error to setup dokploy", e);
|
||||||
|
}
|
||||||
|
})();
|
||||||
@@ -39,5 +39,5 @@
|
|||||||
".next/types/**/*.ts",
|
".next/types/**/*.ts",
|
||||||
"env.js"
|
"env.js"
|
||||||
, "next.config.mjs" ],
|
, "next.config.mjs" ],
|
||||||
"exclude": ["node_modules", "dokploy", "config", "dist","webpack.config.server.js"]
|
"exclude": ["node_modules", "dokploy", "config", "dist","webpack.config.server.js","migration.ts","setup.ts"]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user