From 6408ab2459610cdd71d100351e6ec285cb814629 Mon Sep 17 00:00:00 2001 From: Rushil Perera Date: Sun, 2 Jun 2024 07:06:36 -0400 Subject: [PATCH] build: add Dockerfile (#1) Summary: Test Plan: --- Dockerfile | 40 ++++++++++++++++++++++++++++++++++++++++ package.json | 4 +++- 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2809651 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,40 @@ +# use the official Bun image +# see all versions at https://hub.docker.com/r/oven/bun/tags +FROM oven/bun:1 as base +WORKDIR /usr/app + +# install dependencies into temp directory +# this will cache them and speed up future builds +FROM base AS install +RUN mkdir -p /tmp/dev +COPY package.json bun.lockb /tmp/dev/ +RUN cd /tmp/dev && bun install --frozen-lockfile + +# install with --production (exclude devDependencies) +RUN mkdir -p /tmp/prod +COPY package.json bun.lockb /tmp/prod/ +RUN cd /tmp/prod && bun install --frozen-lockfile --production + +# copy node_modules from temp directory +# then copy all (non-ignored) project files into the image +FROM base AS prerelease +COPY --from=install /tmp/dev/node_modules node_modules +COPY . . + +# [optional] tests & build +ENV NODE_ENV=production +RUN bun test +RUN bun build --compile src/index.ts --outfile=aniplay + +# copy production dependencies and source code into final image +FROM base AS release +COPY --from=install /tmp/prod/node_modules node_modules +COPY --from=prerelease /usr/app/src ./src +COPY --from=prerelease /usr/app/package.json . +COPY --from=prerelease /usr/app/tsconfig.json . +COPY --from=prerelease /usr/app/drizzle.config.ts . + +# run the app +USER bun +EXPOSE 3000 +ENTRYPOINT [ "bun", "run", "prod:server" ] \ No newline at end of file diff --git a/package.json b/package.json index 00528e9..7f80de3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,8 @@ { "scripts": { - "dev": "wrangler dev src/index.ts --port 8080", + "dev:cloudflare": "wrangler dev src/index.ts --port 8080", + "dev:server": "bun run --watch src/index.ts", + "prod:server": "bun run src/index.ts", "deploy": "wrangler deploy --minify src/index.ts" }, "dependencies": {