diff --git a/.gitignore b/.gitignore index 19a2876..c439482 100644 --- a/.gitignore +++ b/.gitignore @@ -174,4 +174,5 @@ dist # Finder (MacOS) folder config .DS_Store -app/* \ No newline at end of file +app/* +.data \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index b6fc907..fdcba46 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,13 +4,9 @@ WORKDIR /app/prasi RUN apt-get update RUN apt-get install unzip -COPY pkgs/docker-prep.ts . -RUN bun docker-prep.ts -WORKDIR /app/prasi/_tmp_docker +COPY dockerzip . +RUN unzip dockerzip RUN bun install -COPY _tmp_docker/node_modules . -WORKDIR /app/prasi -RUN rm -rf _tmp_docker COPY . . EXPOSE 3000/tcp diff --git a/dockerzip b/dockerzip new file mode 100644 index 0000000..cb371f9 Binary files /dev/null and b/dockerzip differ diff --git a/pkgs/docker-prep.ts b/pkgs/docker-prep.ts index 325c541..58a7f4e 100644 --- a/pkgs/docker-prep.ts +++ b/pkgs/docker-prep.ts @@ -1,5 +1,12 @@ +import { $ } from "execa"; import fs from "fs"; -import { copyAsync, dirAsync, removeAsync } from "fs-jetpack"; +import { + copyAsync, + dirAsync, + existsAsync, + removeAsync, + renameAsync, +} from "fs-jetpack"; import path from "path"; const dir = { @@ -30,13 +37,18 @@ const dir = { }, }; -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, - }); +if (!(await existsAsync(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")); + + await $({ cwd: dir.path("_tmp_docker") })`zip -r ../docker .`; + await $`mv docker.zip dockerzip`; + await removeAsync(dir.path("_tmp_docker")); } -await copyAsync(dir.path("bun.lockb"), dir.path("_tmp_docker", "bun.lockb")); diff --git a/pkgs/index.ts b/pkgs/index.ts index 3558ccc..e4225e8 100644 --- a/pkgs/index.ts +++ b/pkgs/index.ts @@ -12,6 +12,8 @@ import { dirAsync, existsAsync } from "fs-jetpack"; import { dir } from "utils/dir"; import { $ } from "execa"; +import "./docker-prep"; + g.mode = process.argv.includes("dev") ? "dev" : "prod"; g.datadir = g.mode === "prod" ? "../data" : ".data";