Snazzie
BABetter Auth
•Created by Snazzie on 4/28/2025 in #help
Reduce docker image size
Any improvements to reduce the image size? surely it shouldnt be larger than 2-300MB.
its bloated requiring bun, python, and js. due to needing to run prisma client, and do prisma migrate at runtime
hono + better auth + prisma
684MB
FROM oven/bun:1 AS build
RUN apt-get update && apt-get install -y python3 build-essential
RUN apt-get install -y \
libssl-dev \
openssl
WORKDIR /app
COPY package.json package.json
COPY bun.lockb bun.lockb
RUN bun install
COPY ./src ./src
COPY ./prisma ./prisma
COPY ./start.sh .
ENV NODE_ENV=production
ENV DATABASE_URL=file:../database.db
RUN bunx prisma generate
RUN bunx prisma migrate deploy
RUN bun build \
--compile \
--minify-whitespace \
--minify-syntax \
--target bun \
--outfile server \
./src/index.ts
FROM oven/bun:1-slim AS final
RUN apt-get update -y && apt-get install -y \
libssl-dev \
openssl
WORKDIR /app
COPY --from=build /app/server ./server
COPY --from=build /app/prisma ./prisma
COPY --from=build /app/start.sh ./start.sh
COPY --from=build /app/src/generated/prismaclient ./src/generated/prismaclient
ENV NODE_ENV=production
ENV PORT=5123
ENV DATABASE_URL=file:../database.db
RUN bun add [email protected]
WORKDIR /app
CMD ["/start.sh"]
EXPOSE 5123
FROM oven/bun:1 AS build
RUN apt-get update && apt-get install -y python3 build-essential
RUN apt-get install -y \
libssl-dev \
openssl
WORKDIR /app
COPY package.json package.json
COPY bun.lockb bun.lockb
RUN bun install
COPY ./src ./src
COPY ./prisma ./prisma
COPY ./start.sh .
ENV NODE_ENV=production
ENV DATABASE_URL=file:../database.db
RUN bunx prisma generate
RUN bunx prisma migrate deploy
RUN bun build \
--compile \
--minify-whitespace \
--minify-syntax \
--target bun \
--outfile server \
./src/index.ts
FROM oven/bun:1-slim AS final
RUN apt-get update -y && apt-get install -y \
libssl-dev \
openssl
WORKDIR /app
COPY --from=build /app/server ./server
COPY --from=build /app/prisma ./prisma
COPY --from=build /app/start.sh ./start.sh
COPY --from=build /app/src/generated/prismaclient ./src/generated/prismaclient
ENV NODE_ENV=production
ENV PORT=5123
ENV DATABASE_URL=file:../database.db
RUN bun add [email protected]
WORKDIR /app
CMD ["/start.sh"]
EXPOSE 5123
startup.sh
echo "Running migrations..."
bun prisma migrate deploy
# Start the server
echo "Starting server..."
./server
echo "Running migrations..."
bun prisma migrate deploy
# Start the server
echo "Starting server..."
./server
2 replies