MCPcopy
hub / github.com/Dokploy/dokploy / initializePostgres

Function initializePostgres

packages/server/src/setup/postgres-setup.ts:4–69  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2import { docker } from "../constants";
3import { pullImage } from "../utils/docker/utils";
4export const initializePostgres = async () => {
5 const imageName = "postgres:16";
6 const containerName = "dokploy-postgres";
7 const settings: CreateServiceOptions = {
8 Name: containerName,
9 TaskTemplate: {
10 ContainerSpec: {
11 Image: imageName,
12 Env: [
13 "POSTGRES_USER=dokploy",
14 "POSTGRES_DB=dokploy",
15 "POSTGRES_PASSWORD=amukds4wi9001583845717ad2",
16 ],
17 Mounts: [
18 {
19 Type: "volume",
20 Source: "dokploy-postgres",
21 Target: "/var/lib/postgresql/data",
22 },
23 ],
24 },
25 Networks: [{ Target: "dokploy-network" }],
26 Placement: {
27 Constraints: ["node.role==manager"],
28 },
29 },
30 Mode: {
31 Replicated: {
32 Replicas: 1,
33 },
34 },
35 ...(process.env.NODE_ENV === "development" && {
36 EndpointSpec: {
37 Ports: [
38 {
39 TargetPort: 5432,
40 PublishedPort: 5432,
41 Protocol: "tcp",
42 PublishMode: "host",
43 },
44 ],
45 },
46 }),
47 };
48 try {
49 await pullImage(imageName);
50
51 const service = docker.getService(containerName);
52 const inspect = await service.inspect();
53 await service.update({
54 version: Number.parseInt(inspect.Version.Index),
55 ...settings,
56 });
57 console.log("Postgres Started ✅");
58 } catch (_) {
59 try {
60 await docker.createService(settings);
61 } catch (error: any) {

Callers 1

setup.tsFile · 0.90

Calls 1

pullImageFunction · 0.90

Tested by

no test coverage detected