This commit is contained in:
Rizky 2024-01-25 11:16:34 +07:00
parent 58b1d02de3
commit 8d4dec8db1
2 changed files with 52 additions and 3 deletions

View File

@ -3,8 +3,15 @@ WORKDIR /app/prasi
RUN apt-get update
RUN apt-get install unzip
COPY package.json bun.lockb .
COPY pkgs/docker-prep.ts .
RUN bun docker-prep.ts
COPY _tmp_docker .
WORKDIR /app/prasi/_tmp_docker
RUN bun install
COPY _tmp_docker/node_modules .
WORKDIR /app/prasi
RUN rm -rf _tmp_docker
COPY . .
EXPOSE 3000/tcp

42
pkgs/docker-prep.ts Normal file
View File

@ -0,0 +1,42 @@
import fs from "fs";
import { copyAsync, dirAsync, removeAsync } from "fs-jetpack";
import path from "path";
const dir = {
path(...allpath: any[]) {
return path.join(process.cwd(), ...allpath);
},
read(dirPath: string, baseDir?: string[]): Record<string, string> {
const result: Record<string, string> = {};
const contents = fs.readdirSync(dirPath);
for (const item of contents) {
const itemPath = path.join(dirPath, item);
const stats = fs.statSync(itemPath);
if (stats.isFile()) {
// const content = fs.readFileSync(itemPath, "utf-8");
result[[...(baseDir || []), item].join("/")] = "";
} else if (stats.isDirectory()) {
if (item !== "node_modules" && item !== ".git") {
const subdirResult = dir.read(itemPath, [...(baseDir || []), item]);
Object.assign(result, subdirResult);
}
}
}
return result;
},
};
await removeAsync(dir.path("_tmp_docker"));
for (const file of Object.keys(dir.read(dir.path``))) {
if (file.endsWith("package.json")) {
await dirAsync(dir.path("_tmp_docker", path.dirname(file)));
await copyAsync(dir.path(file), dir.path("_tmp_docker", file), {
overwrite: true,
});
}
}
await copyAsync(dir.path("bun.lockb"), dir.path("_tmp_docker", "bun.lockb"));