From a89c1293d1a44e42ca4ee1fa946b6642aff03459 Mon Sep 17 00:00:00 2001 From: Nyamort <67233336+Nyamort@users.noreply.github.com> Date: Thu, 13 Mar 2025 22:30:17 +0000 Subject: [PATCH 1/4] feat: add docker file --- Dockerfile | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..9d5cd47a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM oven/bun:slim + +WORKDIR /app + +COPY package*.json ./ + +RUN bun install + +COPY src ./src +COPY tsconfig.json ./ + +EXPOSE 4141 + +ENV NODE_ENV=production + +CMD ["bun", "run", "start"] \ No newline at end of file From 49731443427d4a0d15e6e8de56ff24f19707ec96 Mon Sep 17 00:00:00 2001 From: Nyamort <67233336+Nyamort@users.noreply.github.com> Date: Thu, 13 Mar 2025 22:39:47 +0000 Subject: [PATCH 2/4] docs: Update README with docker setup --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index f2ead0c7..9964f31d 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,20 @@ To install dependencies, run: bun install ``` +## Using with docker + +Build image + +```sh +docker build -t copilot-api . +``` + +Run the container + +```sh +docker run -p 4141:4141 copilot-api +``` + ## Using with npx You can run the project directly using npx: From 03d90066fa0bad1c44766be26ceb80ddd76e2fe3 Mon Sep 17 00:00:00 2001 From: Nyamort <67233336+Nyamort@users.noreply.github.com> Date: Fri, 14 Mar 2025 22:03:36 +0000 Subject: [PATCH 3/4] feat: Refactor Dockerfile for multi-stage builds and update package.json prepare script --- Dockerfile | 27 +++++++++++++++++---------- package.json | 2 +- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9d5cd47a..bb819b5e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,23 @@ -FROM oven/bun:slim +FROM oven/bun:1.2.5 AS base +WORKDIR /usr/src/app -WORKDIR /app +FROM base AS install +COPY package.json bun.lock ./ +RUN bun install --frozen-lockfile --production -COPY package*.json ./ -RUN bun install - -COPY src ./src -COPY tsconfig.json ./ - -EXPOSE 4141 +FROM base AS prerelease +COPY --from=install /usr/src/app/node_modules node_modules +COPY . . ENV NODE_ENV=production +RUN bun test +RUN bun run build + +FROM base AS release +COPY --from=install /usr/src/app/node_modules node_modules +COPY --from=prerelease /usr/src/app/dist/ . -CMD ["bun", "run", "start"] \ No newline at end of file +USER bun +EXPOSE 4141/tcp +ENTRYPOINT [ "bun", "main.js"] \ No newline at end of file diff --git a/package.json b/package.json index 502fdd6f..33c84ef0 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "knip": "knip-bun", "lint": "eslint .", "prepack": "bun run build", - "prepare": "simple-git-hooks", + "prepare": "NODE_ENV=production || simple-git-hooks", "release": "bumpp && bun publish --access public", "start": "NODE_ENV=production bun run ./src/main.ts" }, From 0935ed1dbc55421ba4ca8678dfed7a0b7e6e88ce Mon Sep 17 00:00:00 2001 From: Erick Christian Date: Sat, 15 Mar 2025 16:58:37 +0700 Subject: [PATCH 4/4] build: Refactor Dockerfile for multi-stage build and smaller image size --- Dockerfile | 31 ++++++++++++++----------------- package.json | 2 +- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index bb819b5e..92c7a452 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,20 @@ -FROM oven/bun:1.2.5 AS base -WORKDIR /usr/src/app +FROM oven/bun:alpine AS builder +WORKDIR /app -FROM base AS install -COPY package.json bun.lock ./ -RUN bun install --frozen-lockfile --production +COPY ./package.json ./bun.lock ./ +RUN bun install --frozen-lockfile - -FROM base AS prerelease -COPY --from=install /usr/src/app/node_modules node_modules COPY . . - -ENV NODE_ENV=production -RUN bun test RUN bun run build -FROM base AS release -COPY --from=install /usr/src/app/node_modules node_modules -COPY --from=prerelease /usr/src/app/dist/ . +FROM oven/bun:alpine AS runner +WORKDIR /app + +COPY ./package.json ./bun.lock ./ +RUN bun install --frozen-lockfile --production --ignore-scripts --no-cache + +COPY --from=builder /app/dist ./dist + +EXPOSE 4141 -USER bun -EXPOSE 4141/tcp -ENTRYPOINT [ "bun", "main.js"] \ No newline at end of file +CMD ["bun", "run", "dist/main.js"] \ No newline at end of file diff --git a/package.json b/package.json index 33c84ef0..502fdd6f 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "knip": "knip-bun", "lint": "eslint .", "prepack": "bun run build", - "prepare": "NODE_ENV=production || simple-git-hooks", + "prepare": "simple-git-hooks", "release": "bumpp && bun publish --access public", "start": "NODE_ENV=production bun run ./src/main.ts" },