diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..60f958b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +.DS_Store +node_modules +dist +Dockerfile* +docker-compose* +.dockerignore +.git +.gitignore +README.md +LICENSE +.vscode +.env.* diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2d8fa4f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,35 @@ +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 . . + +# build +ENV NODE_ENV=production +#RUN bun test +RUN bun run build-remote + +# 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/dist ./dist +COPY --from=prerelease /usr/src/app/package.json . + +USER bun +EXPOSE 4321 +ENTRYPOINT ["bun", "run", "./dist/server/entry.mjs"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..cffe336 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,9 @@ +services: + personal-site: + build: . + ports: + - 4321:4321 + restart: no + logging: + options: + max-size: 1g