From 9f8c70522465592b0f40617a1a314fac7dc1fd76 Mon Sep 17 00:00:00 2001 From: cirroskais Date: Mon, 18 Mar 2024 16:08:10 -0400 Subject: [PATCH] This is it --- .gitignore | 2 ++ Dockerfile | 21 +++------------------ package.json | 23 +++++++++++++---------- src/index.ts | 2 ++ 4 files changed, 20 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index 9b1ee42..ad22606 100644 --- a/.gitignore +++ b/.gitignore @@ -173,3 +173,5 @@ dist # Finder (MacOS) folder config .DS_Store + +build \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index f0f2387..37cc563 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,38 +1,23 @@ -# 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/src/app -# install dependencies into temp directory -# this will cache them and speed up future builds FROM base AS install RUN mkdir -p /temp/dev COPY package.json bun.lockb /temp/dev/ RUN cd /temp/dev && bun install --frozen-lockfile -# install with --production (exclude devDependencies) -RUN mkdir -p /temp/prod -COPY package.json bun.lockb /temp/prod/ -RUN cd /temp/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 /temp/dev/node_modules node_modules COPY . . -# [optional] tests & build ENV NODE_ENV=production -# RUN bun test RUN bun run build -# copy production dependencies and source code into final image FROM base AS release -COPY --from=install /temp/prod/node_modules node_modules -COPY --from=prerelease /usr/src/app/index.ts . -COPY --from=prerelease /usr/src/app/package.json . +COPY --from=prerelease /usr/src/app/build/garf-api . -# run the app USER bun EXPOSE 3000/tcp -ENTRYPOINT [ "bun", "run", "index.ts" ] +RUN ls -lah +CMD [ "garf-api" ] diff --git a/package.json b/package.json index 4bfb3e0..c7b9ee8 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,14 @@ { - "name": "garf-api", - "module": "src/index.ts", - "type": "module", - "devDependencies": { - "@types/bun": "latest" - }, - "peerDependencies": { - "typescript": "^5.0.0" - } -} \ No newline at end of file + "name": "garf-api", + "module": "src/index.ts", + "type": "module", + "scripts": { + "build": "bun build . --compile --outfile=build/garf-api" + }, + "devDependencies": { + "@types/bun": "latest" + }, + "peerDependencies": { + "typescript": "^5.0.0" + } +} diff --git a/src/index.ts b/src/index.ts index f5ae705..9505326 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,3 +9,5 @@ Bun.serve({ return new Response("garf dont know what want..."); }, }); + +console.log("Listening on 0.0.0.0:3000");