FROM oven/bun AS build

RUN apt-get update && apt-get install -y postgresql-client

WORKDIR /app

# Cache packages installation
COPY package.json package.json
COPY bun.lock bun.lock
COPY tsconfig.json tsconfig.json
# Copy the current directory contents into the container at /app
COPY ./src ./src
COPY ./prisma ./prisma

# Set environment variable
ENV NODE_ENV=development
ENV PORT=3000
ENV JWT_SECRET=4242XX424208
ENV TOKEN_EXP=86400
# dev db
ENV DATABASE_URL=postgresql://africa-recrut-dev-user:africa-recrut-dev-pwd@81.17.99.41:30000/africa-recrut-dev-db


# Install dependancies
RUN bun install

# Prisma generate client
RUN bunx prisma generate


RUN bun build \
    --compile \
    --minify-whitespace \
    --minify-syntax \
    --target bun \
    --outfile ./dist/server \
    src/index.ts

CMD ["./dist/server"]

# Make port $PORT available to the world outside this container
EXPOSE ${PORT}