Skip to content

Commit ec8c516

Browse files
authored
Merge pull request #3212 from Dokploy/feat/add-create-env-file-flag
feat(environment): add createEnvFile option to environment settings
2 parents bcd1cbe + 58be8f9 commit ec8c516

File tree

9 files changed

+7001
-3
lines changed

9 files changed

+7001
-3
lines changed

apps/dokploy/__test__/drop/drop.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const baseApp: ApplicationNested = {
2828
railpackVersion: "0.2.2",
2929
applicationId: "",
3030
previewLabels: [],
31+
createEnvFile: true,
3132
herokuVersion: "",
3233
giteaBranch: "",
3334
buildServerId: "",

apps/dokploy/__test__/traefik/traefik.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const baseApp: ApplicationNested = {
77
rollbackActive: false,
88
applicationId: "",
99
previewLabels: [],
10+
createEnvFile: true,
1011
herokuVersion: "",
1112
giteaRepository: "",
1213
giteaOwner: "",

apps/dokploy/components/dashboard/application/environment/show.tsx

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,23 @@ import { toast } from "sonner";
55
import { z } from "zod";
66
import { Button } from "@/components/ui/button";
77
import { Card } from "@/components/ui/card";
8-
import { Form } from "@/components/ui/form";
8+
import {
9+
Form,
10+
FormControl,
11+
FormDescription,
12+
FormField,
13+
FormItem,
14+
FormLabel,
15+
} from "@/components/ui/form";
916
import { Secrets } from "@/components/ui/secrets";
17+
import { Switch } from "@/components/ui/switch";
1018
import { api } from "@/utils/api";
1119

1220
const addEnvironmentSchema = z.object({
1321
env: z.string(),
1422
buildArgs: z.string(),
1523
buildSecrets: z.string(),
24+
createEnvFile: z.boolean(),
1625
});
1726

1827
type EnvironmentSchema = z.infer<typeof addEnvironmentSchema>;
@@ -39,6 +48,7 @@ export const ShowEnvironment = ({ applicationId }: Props) => {
3948
env: "",
4049
buildArgs: "",
4150
buildSecrets: "",
51+
createEnvFile: true,
4252
},
4353
resolver: zodResolver(addEnvironmentSchema),
4454
});
@@ -47,17 +57,20 @@ export const ShowEnvironment = ({ applicationId }: Props) => {
4757
const currentEnv = form.watch("env");
4858
const currentBuildArgs = form.watch("buildArgs");
4959
const currentBuildSecrets = form.watch("buildSecrets");
60+
const currentCreateEnvFile = form.watch("createEnvFile");
5061
const hasChanges =
5162
currentEnv !== (data?.env || "") ||
5263
currentBuildArgs !== (data?.buildArgs || "") ||
53-
currentBuildSecrets !== (data?.buildSecrets || "");
64+
currentBuildSecrets !== (data?.buildSecrets || "") ||
65+
currentCreateEnvFile !== (data?.createEnvFile ?? true);
5466

5567
useEffect(() => {
5668
if (data) {
5769
form.reset({
5870
env: data.env || "",
5971
buildArgs: data.buildArgs || "",
6072
buildSecrets: data.buildSecrets || "",
73+
createEnvFile: data.createEnvFile ?? true,
6174
});
6275
}
6376
}, [data, form]);
@@ -67,6 +80,7 @@ export const ShowEnvironment = ({ applicationId }: Props) => {
6780
env: formData.env,
6881
buildArgs: formData.buildArgs,
6982
buildSecrets: formData.buildSecrets,
83+
createEnvFile: formData.createEnvFile,
7084
applicationId,
7185
})
7286
.then(async () => {
@@ -83,6 +97,7 @@ export const ShowEnvironment = ({ applicationId }: Props) => {
8397
env: data?.env || "",
8498
buildArgs: data?.buildArgs || "",
8599
buildSecrets: data?.buildSecrets || "",
100+
createEnvFile: data?.createEnvFile ?? true,
86101
});
87102
};
88103

@@ -167,6 +182,30 @@ export const ShowEnvironment = ({ applicationId }: Props) => {
167182
placeholder="NPM_TOKEN=xyz"
168183
/>
169184
)}
185+
{data?.buildType === "dockerfile" && (
186+
<FormField
187+
control={form.control}
188+
name="createEnvFile"
189+
render={({ field }) => (
190+
<FormItem className="flex flex-row items-center justify-between p-3 border rounded-lg shadow-sm">
191+
<div className="space-y-0.5">
192+
<FormLabel>Create Environment File</FormLabel>
193+
<FormDescription>
194+
When enabled, an .env file will be created during the
195+
build process. Disable this if you don't want to generate
196+
an environment file.
197+
</FormDescription>
198+
</div>
199+
<FormControl>
200+
<Switch
201+
checked={field.value}
202+
onCheckedChange={field.onChange}
203+
/>
204+
</FormControl>
205+
</FormItem>
206+
)}
207+
/>
208+
)}
170209
<div className="flex flex-row justify-end gap-2">
171210
{hasChanges && (
172211
<Button type="button" variant="outline" onClick={handleCancel}>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE "application" ADD COLUMN "createEnvFile" boolean DEFAULT true NOT NULL;

0 commit comments

Comments
 (0)