FROM oven/bun:alpine AS builder

WORKDIR /app

RUN apk add git

COPY package.json ./
RUN bun install
COPY . .

RUN mkdir -p /data \
  && touch /data/portal-btc.db \
  && chown -R bun:bun /app /data

RUN bun run build

FROM oven/bun:alpine

WORKDIR /app

COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/bun.lock ./bun.lock

COPY --from=builder /app/build .

VOLUME /data

USER bun

EXPOSE 3000

CMD ["bun", "index.js"]
