-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.api.backup
75 lines (56 loc) · 1.98 KB
/
Dockerfile.api.backup
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
74
75
# This dockerfile use node image as base and build application with npm which takes long time.
# Set bun image version
ARG BUN_VERSION=1.1.8
# Use node 20 buster as base image
FROM node:20-buster AS base
# Install bash and turbo for base, then clean up
RUN apt-get update && \
apt-get install -y --no-install-recommends bash curl && \
npm install -g turbo@latest && \
apt-get clean && rm -rf /var/lib/apt/lists/*
# Install Bun for base
RUN curl -fsSL https://bun.sh/install | bash && \
mv /root/.bun/bin/bun /usr/local/bin/ && \
rm -rf /root/.bun
# Ensure Bun environment
ENV PATH="/usr/local/bin:$PATH"
# Check Bun installation
RUN bun -v
# Set working directory for base
WORKDIR /app
# Builder stage to compile the application
FROM base AS builder
COPY . .
# Prune and prepare the application
RUN turbo prune api --docker
# Installer stage to set up environment
FROM base AS installer
COPY --from=builder /app/.gitignore ./.gitignore
COPY --from=builder /app/out/json/ .
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/out/package-lock.json ./package-lock.json
# Install dependencies without audit to speed up the process
# RUN npm ci --production --no-audit --no-fund --verbose
RUN bun install
# Copy build artifacts
COPY --from=builder /app/out/full/ .
COPY --from=builder /app/turbo.json ./turbo.json
RUN pwd && ls -lat /app
# FROM bun image AS runner stage to run the application
FROM oven/bun:${BUN_VERSION}-alpine AS runner
# Install bash and curl (if required)
RUN apk update && \
apk add --no-cache bash curl && \
rm -rf /var/cache/apk/*
# Set working directory
WORKDIR /app
# Set up non-root user
RUN addgroup --system honojs && \
adduser --system --ingroup honojs honojs --uid 1001
USER honojs
# Copy application from the installer stage
COPY --from=installer /app/node_modules ./node_modules
COPY --from=installer /app/apps ./apps
COPY --from=installer /app/packages ./packages
RUN pwd && ls -lath /app
CMD ["bun", "run", "./apps/api/src/main.ts"]