mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor(dockerfile): create .env file when using dockerfile #227
This commit is contained in:
@@ -3,12 +3,13 @@ import { docker } from "@/server/constants";
|
|||||||
import * as tar from "tar-fs";
|
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 { createEnvFile } from "./utils";
|
||||||
|
|
||||||
export const buildCustomDocker = async (
|
export const buildCustomDocker = async (
|
||||||
application: ApplicationNested,
|
application: ApplicationNested,
|
||||||
writeStream: WriteStream,
|
writeStream: WriteStream,
|
||||||
) => {
|
) => {
|
||||||
const { appName } = application;
|
const { appName, env } = application;
|
||||||
const dockerFilePath = getBuildAppDirectory(application);
|
const dockerFilePath = getBuildAppDirectory(application);
|
||||||
try {
|
try {
|
||||||
const image = `${appName}`;
|
const image = `${appName}`;
|
||||||
@@ -16,11 +17,11 @@ export const buildCustomDocker = async (
|
|||||||
dockerFilePath.substring(0, dockerFilePath.lastIndexOf("/") + 1) || ".";
|
dockerFilePath.substring(0, dockerFilePath.lastIndexOf("/") + 1) || ".";
|
||||||
const tarStream = tar.pack(contextPath);
|
const tarStream = tar.pack(contextPath);
|
||||||
|
|
||||||
|
createEnvFile(dockerFilePath, env);
|
||||||
|
|
||||||
const stream = await docker.buildImage(tarStream, {
|
const stream = await docker.buildImage(tarStream, {
|
||||||
t: image,
|
t: image,
|
||||||
dockerfile: dockerFilePath.substring(dockerFilePath.lastIndexOf("/") + 1),
|
dockerfile: dockerFilePath.substring(dockerFilePath.lastIndexOf("/") + 1),
|
||||||
// TODO: maybe use or not forcerm
|
|
||||||
// forcerm: true,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
|
|||||||
12
server/utils/builders/utils.ts
Normal file
12
server/utils/builders/utils.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
||||||
|
import { dirname, join } from "node:path";
|
||||||
|
import { prepareEnvironmentVariables } from "../docker/utils";
|
||||||
|
|
||||||
|
export const createEnvFile = (directory: string, env: string | null) => {
|
||||||
|
const envFilePath = join(dirname(directory), ".env");
|
||||||
|
if (!existsSync(dirname(envFilePath))) {
|
||||||
|
mkdirSync(dirname(envFilePath), { recursive: true });
|
||||||
|
}
|
||||||
|
const envFileContent = prepareEnvironmentVariables(env).join("\n");
|
||||||
|
writeFileSync(envFilePath, envFileContent);
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user