diff --git a/Dockerfile b/Dockerfile index 8883be1..40fdc0f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,9 +3,16 @@ 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 . . +COPY _tmp_docker/node_modules . +WORKDIR /app/prasi +RUN rm -rf _tmp_docker +COPY . . EXPOSE 3000/tcp -CMD [ "bun", "run", "prod" ] \ No newline at end of file +CMD [ "bun", "run", "prod" ] diff --git a/pkgs/docker-prep.ts b/pkgs/docker-prep.ts new file mode 100644 index 0000000..325c541 --- /dev/null +++ b/pkgs/docker-prep.ts @@ -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 { + const result: Record = {}; + + 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"));