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
|
||||
/redis-data
|
||||
traefik.yml
|
||||
.docker
|
||||
.env.production
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
@@ -54,7 +54,7 @@ feat: add new feature
|
||||
```bash
|
||||
git clone https://github.com/dokploy/dokploy.git
|
||||
cd dokploy
|
||||
npm install
|
||||
pnpm install
|
||||
cp .env.example .env
|
||||
```
|
||||
|
||||
@@ -62,28 +62,40 @@ cp .env.example .env
|
||||
|
||||
Is required to have **Docker** installed on your machine.
|
||||
|
||||
|
||||
### Setup
|
||||
|
||||
Run the command that will spin up all the required services and files.
|
||||
|
||||
```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
|
||||
|
||||
## Build
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
pnpm run build
|
||||
```
|
||||
|
||||
## Docker
|
||||
|
||||
To build the docker image
|
||||
```bash
|
||||
npm run docker:build
|
||||
pnpm run docker:build
|
||||
```
|
||||
|
||||
To push the docker image
|
||||
```bash
|
||||
npm run docker:push
|
||||
pnpm run docker:push
|
||||
```
|
||||
|
||||
## Password Reset
|
||||
|
||||
@@ -65,7 +65,7 @@ export const Login2FA = ({ authId }: Props) => {
|
||||
duration: 2000,
|
||||
});
|
||||
|
||||
push("/dashboard");
|
||||
push("/dashboard/projects");
|
||||
})
|
||||
.catch(() => {
|
||||
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",
|
||||
"build-server": "tsx esbuild.config.ts",
|
||||
"build-next": "next build",
|
||||
"setup": "tsx -r dotenv/config setup.ts && sleep 5 && pnpm run migration:run",
|
||||
"reset-password": "node dist/reset-password.mjs",
|
||||
"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:run": "tsx -r dotenv/config migration.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:truncate": "tsx -r dotenv/config ./server/db/reset.ts",
|
||||
"db:studio": "drizzle-kit studio",
|
||||
"lint": "biome lint",
|
||||
"db:seed": "dotenv tsx ./server/db/seed.ts",
|
||||
@@ -127,6 +129,7 @@
|
||||
"initVersion": "7.25.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": "18.x"
|
||||
}
|
||||
"node": "^18.18.0",
|
||||
"pnpm": "^8.15.4"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,7 +242,7 @@ export async function getServerSideProps(
|
||||
return {
|
||||
redirect: {
|
||||
permanent: false,
|
||||
destination: "/dashboard",
|
||||
destination: "/dashboard/projects",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ export async function getServerSideProps(
|
||||
return {
|
||||
redirect: {
|
||||
permanent: false,
|
||||
destination: "/dashboard",
|
||||
destination: "/dashboard/projects",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -213,7 +213,7 @@ export async function getServerSideProps(
|
||||
return {
|
||||
redirect: {
|
||||
permanent: false,
|
||||
destination: "/dashboard",
|
||||
destination: "/dashboard/projects",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@ export async function getServerSideProps(
|
||||
return {
|
||||
redirect: {
|
||||
permanent: false,
|
||||
destination: "/dashboard",
|
||||
destination: "/dashboard/projects",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@ export async function getServerSideProps(
|
||||
return {
|
||||
redirect: {
|
||||
permanent: false,
|
||||
destination: "/dashboard",
|
||||
destination: "/dashboard/projects",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ export async function getServerSideProps(
|
||||
return {
|
||||
redirect: {
|
||||
permanent: false,
|
||||
destination: "/dashboard",
|
||||
destination: "/dashboard/projects",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -38,7 +38,6 @@ export async function getServerSideProps(
|
||||
},
|
||||
};
|
||||
}
|
||||
console.log(user);
|
||||
if (user.rol === "user") {
|
||||
return {
|
||||
redirect: {
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
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 DYNAMIC_TRAEFIK_PATH = `${BASE_PATH}/traefik/dynamic`;
|
||||
export const LOGS_PATH = `${BASE_PATH}/logs`;
|
||||
|
||||
@@ -10,9 +10,10 @@ const db = drizzle(pg);
|
||||
|
||||
const clearDb = async (): Promise<void> => {
|
||||
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);
|
||||
console.log(tables);
|
||||
await pg.end();
|
||||
} catch (error) {
|
||||
console.error("Error to clean database", error);
|
||||
} finally {
|
||||
|
||||
@@ -34,31 +34,32 @@ void app.prepare().then(async () => {
|
||||
handle(req, res);
|
||||
});
|
||||
|
||||
setupDirectories();
|
||||
createDefaultMiddlewares();
|
||||
await initializeNetwork();
|
||||
await initializeSwarm();
|
||||
createDefaultTraefikConfig();
|
||||
createDefaultServerTraefikConfig();
|
||||
await initializeTraefik();
|
||||
await initializeRedis();
|
||||
await initializePostgres();
|
||||
|
||||
// WEBSOCKET
|
||||
setupDeploymentLogsWebSocketServer(server);
|
||||
setupDockerContainerLogsWebSocketServer(server);
|
||||
setupDockerContainerTerminalWebSocketServer(server);
|
||||
setupTerminalWebSocketServer(server);
|
||||
setupDockerStatsMonitoringSocketServer(server);
|
||||
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
// Cron Jobs
|
||||
setupDirectories();
|
||||
createDefaultMiddlewares();
|
||||
await initializeSwarm();
|
||||
await initializeNetwork();
|
||||
createDefaultTraefikConfig();
|
||||
createDefaultServerTraefikConfig();
|
||||
await initializeTraefik();
|
||||
await initializeRedis();
|
||||
await initializePostgres();
|
||||
initCronJobs();
|
||||
welcomeServer();
|
||||
|
||||
// Timeout to wait for the database to be ready
|
||||
await new Promise((resolve) => setTimeout(resolve, 7000));
|
||||
await migration();
|
||||
}
|
||||
server.listen(PORT);
|
||||
console.log("Server Started:", PORT);
|
||||
deploymentWorker.run();
|
||||
} catch (e) {
|
||||
console.error("Main Server Error", e);
|
||||
|
||||
@@ -56,7 +56,6 @@ export const initializePostgres = async () => {
|
||||
|
||||
console.log("Postgres Started ✅");
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
await docker.createService(settings);
|
||||
console.log("Postgres Not Found: Starting ✅");
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ export const dockerSwarmInitialized = async () => {
|
||||
|
||||
return true;
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -133,7 +133,7 @@ export const createDefaultTraefikConfig = () => {
|
||||
},
|
||||
}),
|
||||
file: {
|
||||
directory: DYNAMIC_TRAEFIK_PATH,
|
||||
directory: "/etc/dokploy/traefik/dynamic",
|
||||
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",
|
||||
"env.js"
|
||||
, "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