62 lines
1.8 KiB
Docker
62 lines
1.8 KiB
Docker
# Multi-stage build: Backend + Frontend
|
|
FROM alpine:latest AS version
|
|
COPY VERSION.txt /tmp/version.txt
|
|
|
|
FROM oven/bun:1.1-alpine AS backend-builder
|
|
COPY --from=version /tmp/version.txt /tmp/version.txt
|
|
|
|
WORKDIR /app/backend
|
|
COPY backend/package*.json ./
|
|
RUN bun install
|
|
COPY backend/prisma ./prisma
|
|
RUN bunx prisma generate
|
|
COPY backend/src ./src
|
|
COPY backend/package.json ./
|
|
RUN sed -i "s/{{VERSION}}/$(cat /tmp/version.txt)/g" src/index.ts && sed -i "s/{{VERSION}}/$(cat /tmp/version.txt)/g" package.json && bun build src/index.ts --outdir ./dist --target bun
|
|
|
|
FROM node:20-alpine AS frontend-builder
|
|
ARG VITE_GIT_URL=https://git.kropa.tech/lotherk/deardiary
|
|
ARG VITE_WEBSITE_URL=https://deardiary.lother.io
|
|
COPY --from=backend-builder /tmp/version.txt /tmp/version.txt
|
|
|
|
WORKDIR /app/frontend
|
|
COPY frontend/package*.json ./
|
|
RUN npm install
|
|
COPY frontend ./
|
|
ENV VITE_GIT_URL=$VITE_GIT_URL
|
|
ENV VITE_WEBSITE_URL=$VITE_WEBSITE_URL
|
|
RUN sed -i "s/{{VERSION}}/$(cat /tmp/version.txt)/g" package.json && npm run build
|
|
|
|
FROM oven/bun:1.1-alpine AS runner
|
|
|
|
WORKDIR /app
|
|
|
|
ENV NODE_ENV=production
|
|
|
|
RUN addgroup --system --gid 1001 nodejs || true
|
|
|
|
# Install nginx for serving frontend
|
|
RUN apk add --no-cache nginx
|
|
|
|
# Copy backend
|
|
COPY --from=backend-builder /app/backend/dist ./dist
|
|
COPY --from=backend-builder /app/backend/node_modules ./node_modules
|
|
COPY backend/package.json .
|
|
COPY backend/prisma ./prisma
|
|
|
|
# Copy frontend build
|
|
COPY --from=frontend-builder /app/frontend/dist ./public
|
|
|
|
# Copy docs from www/ for the app container
|
|
COPY www/docs ./public/docs
|
|
|
|
# Setup nginx
|
|
COPY nginx.conf /etc/nginx/http.d/default.conf
|
|
|
|
RUN mkdir -p /data /run /app/nginx_tmp /var/lib/nginx/logs && chmod 777 /var/lib/nginx/logs /var/lib/nginx/tmp && chown -R bun:nodejs /data /app
|
|
|
|
# Start everything as root
|
|
COPY start.sh /start.sh
|
|
RUN chmod +x /start.sh
|
|
CMD ["/start.sh"]
|