Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 69ab59a

Browse files
committed
Add dedicated env var when starting a container
1 parent 9d33392 commit 69ab59a

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

ui/src/components/NewDatabaseDialog.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,23 @@ export const NewDatabaseDialog = (props: DialogProps) => {
8383
}
8484

8585
const handleCreateDatabase = async () => {
86-
const { image } = officialDBs.find((db) => db.id === provider);
86+
const { image, defaults } = officialDBs.find((db) => db.id === provider);
87+
88+
let envs = [];
89+
const values = { password, username, database }
90+
if (defaults.envs) {
91+
for (const key in defaults.envs) {
92+
const value = defaults.envs[key];
93+
const variableName = value.replaceAll("%", "");
94+
const resolvedValue = values[variableName];
95+
envs.push("-e", `${key}=${resolvedValue}`);
96+
}
97+
}
8798

8899
setCreatingContainer(true);
89100
let containerID = "";
90101
try {
91-
const result = await ddClient.docker.cli.exec("run", ["-d", "-p", port, image]);
102+
const result = await ddClient.docker.cli.exec("run", ["-d", "-p", port, ...envs, image]);
92103
containerID = result.stdout.trim();
93104
} catch (e) {
94105
console.log(e)

ui/src/utils/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ export const officialDBs: IDatabaseProvider[] = [
2121
username: "postgres",
2222
database: "postgres",
2323
password: "mysecretpassword",
24+
envs: {
25+
POSTGRES_PASSWORD: "%password%",
26+
POSTGRES_USER: "%username%",
27+
POSTGRES_DB: "%database%",
28+
}
2429
}
2530
},
2631
{
@@ -32,6 +37,11 @@ export const officialDBs: IDatabaseProvider[] = [
3237
username: "root",
3338
database: "default",
3439
password: "mysecretpassword",
40+
envs: {
41+
MYSQL_ROOT_PASSWORD: "%password%",
42+
MYSQL_DATABASE: "%database%",
43+
MYSQL_USER: "%username%",
44+
}
3545
}
3646
},
3747
{
@@ -43,6 +53,11 @@ export const officialDBs: IDatabaseProvider[] = [
4353
username: "root",
4454
database: "default",
4555
password: "mysecretpassword",
56+
envs: {
57+
MARIADB_ROOT_PASSWORD: "%password%",
58+
MARIADB_DATABASE: "%database%",
59+
MARIADB_USER: "%username%",
60+
}
4661
}
4762
},
4863
]

ui/src/utils/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface IDatabaseProvider {
1515
username: string;
1616
password?: string;
1717
database: string;
18+
envs?: { [id: string]: string };
1819
}
1920
}
2021

0 commit comments

Comments
 (0)