mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor(docker-build): replace docker build with the command
This commit is contained in:
@@ -1,9 +1,8 @@
|
|||||||
import type { WriteStream } from "node:fs";
|
import type { WriteStream } from "node:fs";
|
||||||
import { docker } from "@/server/constants";
|
import { prepareEnvironmentVariables } from "@/server/utils/docker/utils";
|
||||||
import { prepareBuildArgs } from "@/server/utils/docker/utils";
|
|
||||||
import * as tar from "tar-fs";
|
|
||||||
import type { ApplicationNested } from ".";
|
import type { ApplicationNested } from ".";
|
||||||
import { getBuildAppDirectory } from "../filesystem/directory";
|
import { getBuildAppDirectory } from "../filesystem/directory";
|
||||||
|
import { spawnAsync } from "../process/spawnAsync";
|
||||||
import { createEnvFile } from "./utils";
|
import { createEnvFile } from "./utils";
|
||||||
|
|
||||||
export const buildCustomDocker = async (
|
export const buildCustomDocker = async (
|
||||||
@@ -14,29 +13,30 @@ export const buildCustomDocker = async (
|
|||||||
const dockerFilePath = getBuildAppDirectory(application);
|
const dockerFilePath = getBuildAppDirectory(application);
|
||||||
try {
|
try {
|
||||||
const image = `${appName}`;
|
const image = `${appName}`;
|
||||||
|
|
||||||
const contextPath =
|
const contextPath =
|
||||||
dockerFilePath.substring(0, dockerFilePath.lastIndexOf("/") + 1) || ".";
|
dockerFilePath.substring(0, dockerFilePath.lastIndexOf("/") + 1) || ".";
|
||||||
const tarStream = tar.pack(contextPath);
|
const args = prepareEnvironmentVariables(buildArgs);
|
||||||
|
|
||||||
|
const commandArgs = ["build", "-t", image, "-f", dockerFilePath, "."];
|
||||||
|
|
||||||
|
for (const arg of args) {
|
||||||
|
commandArgs.push("--build-arg", arg);
|
||||||
|
}
|
||||||
|
|
||||||
createEnvFile(dockerFilePath, env);
|
createEnvFile(dockerFilePath, env);
|
||||||
|
await spawnAsync(
|
||||||
const stream = await docker.buildImage(tarStream, {
|
"docker",
|
||||||
t: image,
|
commandArgs,
|
||||||
buildargs: prepareBuildArgs(buildArgs),
|
(data) => {
|
||||||
dockerfile: dockerFilePath.substring(dockerFilePath.lastIndexOf("/") + 1),
|
if (writeStream.writable) {
|
||||||
});
|
writeStream.write(data);
|
||||||
|
}
|
||||||
await new Promise((resolve, reject) => {
|
},
|
||||||
docker.modem.followProgress(
|
{
|
||||||
stream,
|
cwd: contextPath,
|
||||||
(err, res) => (err ? reject(err) : resolve(res)),
|
},
|
||||||
(event) => {
|
);
|
||||||
if (event.stream) {
|
|
||||||
writeStream.write(event.stream);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user