MCPcopy Index your code
hub / github.com/Dokploy/dokploy / generateApplyPatchesCommand

Function generateApplyPatchesCommand

packages/server/src/services/patch.ts:136–176  ·  view source on GitHub ↗
({
	id,
	type,
	serverId,
}: ApplyPatchesOptions)

Source from the content-addressed store, hash-verified

134}
135
136export const generateApplyPatchesCommand = async ({
137 id,
138 type,
139 serverId,
140}: ApplyPatchesOptions) => {
141 const entity =
142 type === "application"
143 ? await findApplicationById(id)
144 : await findComposeById(id);
145 const { COMPOSE_PATH, APPLICATIONS_PATH } = paths(!!serverId);
146 const basePath = type === "compose" ? COMPOSE_PATH : APPLICATIONS_PATH;
147 const codePath = join(basePath, entity.appName, "code");
148
149 const resultPatches = await findPatchesByEntityId(id, type);
150 const patches = resultPatches.filter((p) => p.enabled);
151
152 if (patches.length === 0) {
153 return "";
154 }
155
156 let command = `echo "Applying ${patches.length} patch(es)...";`;
157
158 for (const p of patches) {
159 const filePath = join(codePath, p.filePath);
160
161 if (p.type === "delete") {
162 command += `
163 rm -f "${filePath}";
164 `;
165 } else {
166 command += `
167file="${filePath}"
168dir="$(dirname "$file")"
169mkdir -p "$dir"
170echo "${encodeBase64(p.content)}" | base64 -d > "$file"
171`;
172 }
173 }
174
175 return command;
176};

Callers 3

deployComposeFunction · 0.90
rebuildComposeFunction · 0.90
deployApplicationFunction · 0.90

Calls 5

findApplicationByIdFunction · 0.90
findComposeByIdFunction · 0.90
pathsFunction · 0.90
encodeBase64Function · 0.90
findPatchesByEntityIdFunction · 0.85

Tested by

no test coverage detected