-
-
Notifications
You must be signed in to change notification settings - Fork 710
Expand file tree
/
Copy pathdockerfile
More file actions
120 lines (95 loc) · 4.43 KB
/
dockerfile
File metadata and controls
120 lines (95 loc) · 4.43 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Build Stage
FROM oven/bun:1.2.8 AS builder
# Add Build Arguments
ARG USE_MIRROR=false
WORKDIR /app
# Set Sharp environment variables to speed up ARM installation
ENV SHARP_IGNORE_GLOBAL_LIBVIPS=1
ENV npm_config_sharp_binary_host="https://npmmirror.com/mirrors/sharp"
ENV npm_config_sharp_libvips_binary_host="https://npmmirror.com/mirrors/sharp-libvips"
# Set Prisma environment variables to optimize installation
ENV PRISMA_ENGINES_MIRROR="https://registry.npmmirror.com/-/binary/prisma"
ENV PRISMA_SKIP_POSTINSTALL_GENERATE=true
# Copy Project Files
COPY . .
# Configure Mirror Based on USE_MIRROR Parameter
RUN if [ "$USE_MIRROR" = "true" ]; then \
echo "Using Taobao Mirror to Install Dependencies" && \
echo '{ "install": { "registry": "https://registry.npmmirror.com" } }' > .bunfig.json; \
else \
echo "Using Default Mirror to Install Dependencies"; \
fi
# Pre-install Sharp for ARM architecture
RUN if [ "$(uname -m)" = "aarch64" ] || [ "$(uname -m)" = "arm64" ]; then \
echo "Detected ARM architecture, installing sharp platform-specific dependencies..." && \
mkdir -p /tmp/sharp-cache && \
export SHARP_CACHE_DIRECTORY=/tmp/sharp-cache && \
bun install --platform=linux --arch=arm64 sharp@0.34.1 --no-save --unsafe-perm || \
bun install --force @img/sharp-linux-arm64 --no-save; \
fi
# Install Dependencies and Build App
RUN bun install --unsafe-perm
RUN bunx prisma generate
RUN bun run build:web
RUN bun run build:seed
RUN printf '#!/bin/sh\necho "Current Environment: $NODE_ENV"\nnpx prisma migrate deploy\nnode server/seed.js\nnode server/index.js\n' > start.sh && \
chmod +x start.sh
FROM node:20-alpine as init-downloader
WORKDIR /app
RUN wget -qO /app/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.5/dumb-init_1.2.5_$(uname -m) && \
chmod +x /app/dumb-init && \
rm -rf /var/cache/apk/*
# Runtime Stage - Using Alpine as required
FROM node:20-alpine AS runner
# Add Build Arguments
ARG USE_MIRROR=false
WORKDIR /app
# Environment Variables
ENV NODE_ENV=production
# If there is a proxy or load balancer behind HTTPS, you may need to disable secure cookies
ENV DISABLE_SECURE_COOKIE=false
# Set Trust Proxy
ENV TRUST_PROXY=1
# Set Sharp environment variables
ENV SHARP_IGNORE_GLOBAL_LIBVIPS=1
ENV npm_config_sharp_binary_host="https://npmmirror.com/mirrors/sharp"
ENV npm_config_sharp_libvips_binary_host="https://npmmirror.com/mirrors/sharp-libvips"
RUN apk add --no-cache openssl vips-dev python3 py3-setuptools make g++ gcc libc-dev linux-headers && \
if [ "$USE_MIRROR" = "true" ]; then \
echo "Using Taobao Mirror to Install Dependencies" && \
npm config set registry https://registry.npmmirror.com; \
else \
echo "Using Default Mirror to Install Dependencies"; \
fi
# Copy Build Artifacts and Necessary Files
COPY --from=builder /app/dist ./server
COPY --from=builder /app/server/lute.min.js ./server/lute.min.js
COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/node_modules/.prisma/client ./node_modules/.prisma/client
COPY --from=builder /app/start.sh ./
COPY --from=init-downloader /app/dumb-init /usr/local/bin/dumb-init
RUN chmod +x ./start.sh && \
ls -la start.sh
RUN if [ "$(uname -m)" = "aarch64" ] || [ "$(uname -m)" = "arm64" ]; then \
echo "Detected ARM architecture, installing sharp platform-specific dependencies..." && \
mkdir -p /tmp/sharp-cache && \
export SHARP_CACHE_DIRECTORY=/tmp/sharp-cache && \
npm install --platform=linux --arch=arm64 sharp@0.34.1 --no-save --unsafe-perm || \
npm install --force @img/sharp-linux-arm64 --no-save; \
fi
# Install dependencies with --ignore-scripts to skip native compilation
RUN echo "Installing additional dependencies..." && \
npm install @node-rs/crc32 lightningcss sharp@0.34.1 prisma@5.21.1 && \
npm install -g prisma@5.21.1 && \
npm install sqlite3@5.1.7 && \
npm install llamaindex @langchain/community@0.3.40 && \
npm install @libsql/client @libsql/core && \
npx prisma generate && \
# find / -type d -name "onnxruntime-*" -exec rm -rf {} + 2>/dev/null || true && \
# npm cache clean --force && \
rm -rf /tmp/* && \
apk del python3 py3-setuptools make g++ gcc libc-dev linux-headers && \
rm -rf /var/cache/apk/* /root/.npm /root/.cache
# Expose Port (Adjust According to Actual Application)
EXPOSE 1111
CMD ["/usr/local/bin/dumb-init", "--", "/bin/sh", "-c", "./start.sh"]