mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
Update schedule management with shell type support and version upgrades
- Updated the `drizzle-zod` package to version 0.7.1 across the project for enhanced schema validation. - Introduced a new `shellType` column in the `schedule` schema to specify the shell used for executing commands, defaulting to 'bash'. - Enhanced the `HandleSchedules` component to include the new `shellType` field, allowing users to select the shell type when creating or updating schedules. - Updated the `runCommand` utility to utilize the selected shell type when executing commands, improving flexibility in command execution. - Refactored the API to accommodate the new `shellType` in schedule creation and updates, ensuring proper handling of the new field.
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
import { relations } from "drizzle-orm";
|
||||
import { boolean, pgTable, text } from "drizzle-orm/pg-core";
|
||||
import { createInsertSchema } from "drizzle-zod";
|
||||
import { boolean, pgEnum, pgTable, text } from "drizzle-orm/pg-core";
|
||||
import { createInsertSchema, createUpdateSchema } from "drizzle-zod";
|
||||
import { nanoid } from "nanoid";
|
||||
import { z } from "zod";
|
||||
import { applications } from "./application";
|
||||
import { deployments } from "./deployment";
|
||||
import { generateAppName } from "./utils";
|
||||
|
||||
export const shellTypes = pgEnum("shellType", ["bash", "sh"]);
|
||||
|
||||
export const schedules = pgTable("schedule", {
|
||||
scheduleId: text("scheduleId")
|
||||
.notNull()
|
||||
@@ -17,6 +19,7 @@ export const schedules = pgTable("schedule", {
|
||||
appName: text("appName")
|
||||
.notNull()
|
||||
.$defaultFn(() => generateAppName("schedule")),
|
||||
shellType: shellTypes("shellType").notNull().default("bash"),
|
||||
command: text("command").notNull(),
|
||||
applicationId: text("applicationId")
|
||||
.notNull()
|
||||
@@ -45,3 +48,7 @@ export const createScheduleSchema = createInsertSchema(schedules, {
|
||||
command: z.string().min(1),
|
||||
applicationId: z.string().min(1),
|
||||
});
|
||||
|
||||
export const updateScheduleSchema = createUpdateSchema(schedules).extend({
|
||||
scheduleId: z.string().min(1),
|
||||
});
|
||||
|
||||
@@ -19,7 +19,8 @@ export const scheduleJob = (schedule: Schedule) => {
|
||||
};
|
||||
|
||||
export const runCommand = async (scheduleId: string) => {
|
||||
const { application, command } = await findScheduleById(scheduleId);
|
||||
const { application, command, shellType } =
|
||||
await findScheduleById(scheduleId);
|
||||
|
||||
const isServer = !!application.serverId;
|
||||
|
||||
@@ -42,7 +43,8 @@ export const runCommand = async (scheduleId: string) => {
|
||||
application.serverId,
|
||||
`
|
||||
set -e
|
||||
docker exec ${containerId} sh -c "${command}" || {
|
||||
echo "Running command: docker exec ${containerId} ${shellType} -c \"${command}\"" >> ${deployment.logPath};
|
||||
docker exec ${containerId} ${shellType} -c "${command}" || {
|
||||
echo "❌ Command failed" >> ${deployment.logPath};
|
||||
exit 1;
|
||||
}
|
||||
@@ -56,10 +58,12 @@ export const runCommand = async (scheduleId: string) => {
|
||||
const writeStream = createWriteStream(deployment.logPath, { flags: "a" });
|
||||
|
||||
try {
|
||||
writeStream.write(`${command}\n`);
|
||||
writeStream.write(
|
||||
`docker exec ${containerId} ${shellType} -c "${command}"\n`,
|
||||
);
|
||||
await spawnAsync(
|
||||
"docker",
|
||||
["exec", containerId, "sh", "-c", command],
|
||||
["exec", containerId, shellType, "-c", command],
|
||||
(data) => {
|
||||
if (writeStream.writable) {
|
||||
writeStream.write(data);
|
||||
|
||||
Reference in New Issue
Block a user