|
| 1 | +# https://bun.sh/guides/ecosystem/docker |
| 2 | +# docker build -t sqlitcloud-gateway . |
| 3 | +# docker run -p 8090:8090 -p 4000:4000 --name sqlitecloud-gateway sqlitecloud-gateway |
| 4 | + |
| 5 | +# use the official Bun image |
| 6 | +# see all versions at https://hub.docker.com/r/oven/bun/tags |
| 7 | +FROM oven/bun:1 as base |
| 8 | +WORKDIR /usr/src/app |
| 9 | + |
| 10 | +# install dependencies into temp directory |
| 11 | +# this will cache them and speed up future builds |
| 12 | +FROM base AS install |
| 13 | +RUN mkdir -p /temp/dev |
| 14 | +COPY package.json bun.lockb /temp/dev/ |
| 15 | +RUN cd /temp/dev && bun install --frozen-lockfile |
| 16 | + |
| 17 | +# install with --production (exclude devDependencies) |
| 18 | +RUN mkdir -p /temp/prod |
| 19 | +COPY package.json bun.lockb /temp/prod/ |
| 20 | +RUN cd /temp/prod && bun install --frozen-lockfile --production |
| 21 | + |
| 22 | +# copy node_modules from temp directory |
| 23 | +# then copy all (non-ignored) project files into the image |
| 24 | +FROM base AS prerelease |
| 25 | +COPY --from=install /temp/dev/node_modules node_modules |
| 26 | +COPY . . |
| 27 | + |
| 28 | +# [optional] tests & build |
| 29 | +ENV NODE_ENV=production |
| 30 | +#RUN bun test |
| 31 | +#RUN bun run build |
| 32 | +RUN bun build ./src/gateway/gateway.ts --compile --outfile ./sqlitecloud-gateway.out |
| 33 | + |
| 34 | +# copy production dependencies and source code into final image |
| 35 | +FROM base AS release |
| 36 | +COPY --from=install /temp/prod/node_modules node_modules |
| 37 | +COPY --from=prerelease /usr/src/app/src ./src |
| 38 | +COPY --from=prerelease /usr/src/app/public ./public |
| 39 | +COPY --from=prerelease /usr/src/app/package.json . |
| 40 | +COPY --from=prerelease /usr/src/app/sqlitecloud-gateway.out . |
| 41 | + |
| 42 | +# run the app |
| 43 | +USER bun |
| 44 | + |
| 45 | +EXPOSE 4000/tcp |
| 46 | +EXPOSE 8090/tcp |
| 47 | + |
| 48 | +#ENTRYPOINT [ "bun", "run", "./src/gateway/gateway.ts" ] |
| 49 | +ENTRYPOINT [ "./sqlitecloud-gateway.out" ] |
0 commit comments