Bun Railpack config
sturlen
FREEOP

a month ago

do you have public repo for the railpack configs? I can run bun flawlessly on railway with the auto detected railpack, but I'm having issues with building a docker image for my own servers. curious what you guys are doing differently

8 Replies

Can you show your Dockerimage?


Removing sensitive content if you need to


sturlen
FREEOP

a month ago

# Multi-stage Bun build optimized for CI
FROM oven/bun:1.3-debian AS deps
WORKDIR /app
COPY package.json bun.lock /app/
# install production dependencies only (used in final image)
RUN bun install --frozen-lockfile --production

FROM oven/bun:1.3-debian  AS builder
WORKDIR /app
# install full deps for build
COPY package.json bun.lock /app/
RUN bun install --frozen-lockfile
# copy source and build
COPY . /app
# run tests and build in this stage (CI should run tests before building image)
RUN bun test || true
RUN bun run build

FROM oven/bun:1.3-debian  AS release
WORKDIR /app
# copy only production node_modules and built assets
COPY --from=deps /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist
# copy source in case start script requires it (keeps runtime correct)
COPY --from=builder /app/src ./src
COPY --from=builder /app/package.json ./package.json

ENV NODE_ENV=production
EXPOSE 3000
USER bun
# start the app via the project start script (adjust if you prefer a static server)
CMD ["bun", "run", "start"]

Any errors during building?


sturlen
FREEOP

a month ago

it built succesfully with github actions, but failed to start when I run it


I see your CMD, I recommend you set it to RUN ["bun", "run", "dist/YOUR_MAIN_FILE.js"] as using package.json scripts can be finicky


iloveitaly
HOBBY

25 days ago

You can use railpack to build a docker image outside of railway fyi!


iloveitaly
HOBBY

25 days ago

railpack build via the CLI


Loading...