# Use Bun base image
FROM oven/bun:1 AS base
WORKDIR /app

# Install dependencies (including dev for build)
FROM base AS install
RUN mkdir -p /temp/dev
COPY package.json bun.lock* bunfig.toml /temp/dev/
# Install all dependencies (needed for build:css)
RUN cd /temp/dev && bun install --frozen-lockfile --ignore-scripts

# Copy application code
FROM base AS release
COPY --from=install /temp/dev/node_modules node_modules
COPY . .

# Build CSS
RUN bun run build:css

# Initialize a default backlog project
RUN bun src/cli.ts init "Backlog Server" || true

# Expose port
EXPOSE 6420

# Set environment
ENV NODE_ENV=production
ENV PORT=6420

# Run the web server
CMD ["bun", "src/cli.ts", "browser", "--port", "6420"]
