Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ export const ShowEnvironment = ({ id, type }: Props) => {
const [isEnvVisible, setIsEnvVisible] = useState(true);

const mutationMap = {
postgres: () => api.postgres.update.useMutation(),
redis: () => api.redis.update.useMutation(),
mysql: () => api.mysql.update.useMutation(),
mariadb: () => api.mariadb.update.useMutation(),
mongo: () => api.mongo.update.useMutation(),
compose: () => api.compose.update.useMutation(),
postgres: () => api.postgres.saveEnvironment.useMutation(),
redis: () => api.redis.saveEnvironment.useMutation(),
mysql: () => api.mysql.saveEnvironment.useMutation(),
mariadb: () => api.mariadb.saveEnvironment.useMutation(),
mongo: () => api.mongo.saveEnvironment.useMutation(),
compose: () => api.compose.saveEnvironment.useMutation(),
};
const { mutateAsync, isPending } = mutationMap[type]
? mutationMap[type]()
: api.mongo.update.useMutation();
: api.mongo.saveEnvironment.useMutation();

const form = useForm<EnvironmentSchema>({
defaultValues: {
Expand All @@ -86,15 +86,18 @@ export const ShowEnvironment = ({ id, type }: Props) => {
}, [data, form]);

const onSubmit = async (formData: EnvironmentSchema) => {
mutateAsync({
mongoId: id || "",
postgresId: id || "",
redisId: id || "",
mysqlId: id || "",
mariadbId: id || "",
composeId: id || "",
env: formData.environment,
})
const payloadMap = {
postgres: { postgresId: id, env: formData.environment },
redis: { redisId: id, env: formData.environment },
mysql: { mysqlId: id, env: formData.environment },
mariadb: { mariadbId: id, env: formData.environment },
mongo: { mongoId: id, env: formData.environment },
compose: { composeId: id, env: formData.environment },
} as const;

(mutateAsync as (input: (typeof payloadMap)[typeof type]) => Promise<unknown>)(
payloadMap[type],
)
.then(async () => {
toast.success("Environments Added");
await refetch();
Expand Down
27 changes: 26 additions & 1 deletion apps/dokploy/server/api/routers/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import {
apiFindCompose,
apiRandomizeCompose,
apiRedeployCompose,
apiSaveEnvironmentVariablesCompose,
apiUpdateCompose,
compose as composeTable,
environments,
Expand Down Expand Up @@ -189,6 +190,30 @@ export const composeRouter = createTRPCRouter({
});
return updated;
}),
saveEnvironment: protectedProcedure
.input(apiSaveEnvironmentVariablesCompose)
.mutation(async ({ input, ctx }) => {
await checkServicePermissionAndAccess(ctx, input.composeId, {
envVars: ["write"],
});
const service = await updateCompose(input.composeId, {
env: input.env,
});

if (!service) {
throw new TRPCError({
code: "BAD_REQUEST",
message: "Error adding environment variables",
});
}

await audit(ctx, {
action: "update",
resourceType: "compose",
resourceId: input.composeId,
});
return true;
}),
delete: protectedProcedure
.input(apiDeleteCompose)
.mutation(async ({ input, ctx }) => {
Expand Down Expand Up @@ -278,7 +303,7 @@ export const composeRouter = createTRPCRouter({
.input(apiFetchServices)
.query(async ({ input, ctx }) => {
await checkServicePermissionAndAccess(ctx, input.composeId, {
service: ["create"],
service: ["read"],
});
return await loadServices(input.composeId, input.type);
}),
Expand Down
9 changes: 8 additions & 1 deletion packages/server/src/db/schema/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,14 @@ export const apiUpdateCompose = createSchema
composeFile: z.string().optional(),
command: z.string().optional(),
})
.omit({ serverId: true });
.omit({ serverId: true, env: true });

export const apiSaveEnvironmentVariablesCompose = createSchema
.pick({
composeId: true,
env: true,
})
.required();

export const apiRandomizeCompose = createSchema
.pick({
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/db/schema/mariadb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export const apiUpdateMariaDB = createSchema
mariadbId: z.string().min(1),
dockerImage: z.string().optional(),
})
.omit({ serverId: true });
.omit({ serverId: true, env: true });

export const apiRebuildMariadb = createSchema
.pick({
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/db/schema/mongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export const apiUpdateMongo = createSchema
mongoId: z.string().min(1),
dockerImage: z.string().optional(),
})
.omit({ serverId: true });
.omit({ serverId: true, env: true });

export const apiResetMongo = createSchema
.pick({
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/db/schema/mysql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export const apiUpdateMySql = createSchema
mysqlId: z.string().min(1),
dockerImage: z.string().optional(),
})
.omit({ serverId: true });
.omit({ serverId: true, env: true });

export const apiRebuildMysql = createSchema
.pick({
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/db/schema/postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export const apiUpdatePostgres = createSchema
postgresId: z.string().min(1),
dockerImage: z.string().optional(),
})
.omit({ serverId: true });
.omit({ serverId: true, env: true });

export const apiRebuildPostgres = createSchema
.pick({
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/db/schema/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export const apiUpdateRedis = createSchema
redisId: z.string().min(1),
dockerImage: z.string().optional(),
})
.omit({ serverId: true });
.omit({ serverId: true, env: true });

export const apiRebuildRedis = createSchema
.pick({
Expand Down