-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.build
More file actions
73 lines (56 loc) · 2.05 KB
/
Copy pathDockerfile.build
File metadata and controls
73 lines (56 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Multi-stage build for Next.js applications
FROM oven/bun:alpine AS base
# Install dependencies only when needed
FROM base AS deps
# RUN apk add --no-cache libc6-compat
WORKDIR /app
# Copy package files first for better caching
COPY package.json bun.lock ./
COPY apps/admin/package.json ./apps/admin/
COPY apps/front/package.json ./apps/front/
# Install dependencies
RUN bun install --ignore-scripts
# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
ENV NODE_ENV=production
COPY --from=deps /app/package.json /app/bun.lock ./
COPY --from=deps /app/node_modules ./node_modules
COPY --from=deps /app/apps/admin/node_modules ./apps/admin/node_modules
COPY --from=deps /app/apps/front/node_modules ./apps/front/node_modules
COPY apps/admin ./apps/admin
COPY apps/front ./apps/front
RUN bun run build
RUN set -eu; \
for app in front admin; do \
mkdir -p /out/apps/$app; \
cp -a apps/$app/dist/standalone/. /out/apps/$app/; \
done
# Production image, copy all the files and run next
FROM base AS front-builder
WORKDIR /app
# Create ecosystem file
COPY ecosystem.json ./ecosystem.json
COPY --from=builder /out/ /app/
WORKDIR /app
RUN tar --exclude='.git' --exclude='.github' --exclude='.gitignore' -czf front.tar.gz .
FROM rust:1.98-alpine AS api-builder
RUN apk add --no-cache musl-dev
WORKDIR /app
# Copy dependency files first for better caching
COPY Cargo.lock Cargo.toml ./
COPY apis/api/Cargo.toml ./apis/api/
# Build dependencies only (this layer will be cached if dependencies don't change)
RUN mkdir -p apis/api/src && \
echo "fn main() {}" > apis/api/src/main.rs && \
cargo build --release && \
rm -rf apis/api/src
# Copy actual source code
COPY apis/api ./apis/api
# Build the actual application (only rebuilds if source changed)
RUN cargo build --release
RUN tar -czf api.tar.gz -C /app/target/release api
FROM alpine AS result
WORKDIR /app
COPY --from=front-builder /app/front.tar.gz ./front.tar.gz
COPY --from=api-builder /app/api.tar.gz ./api.tar.gz