-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
55 lines (43 loc) · 1.62 KB
/
Dockerfile
File metadata and controls
55 lines (43 loc) · 1.62 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
# Build stage
FROM node:20-alpine AS builder
ARG NEXT_PUBLIC_AMPLITUDE_API_KEY=__NEXT_PUBLIC_AMPLITUDE_API_KEY__
WORKDIR /app
RUN apk add --no-cache git bash curl build-base
# Install Rust toolchain — the @sparkjsdev/spark git dep's "prepare" script
# compiles WASM from Rust source (npm always runs prepare for git deps,
# --ignore-scripts does NOT skip it).
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
&& . /root/.cargo/env \
&& rustup target add wasm32-unknown-unknown
ENV PATH="/root/.cargo/bin:${PATH}"
# Create a dummy git repo at /root so that "lefthook install" (part of
# spark's prepare script) finds a .git dir when walking up from npm's
# temp dir at /root/.npm/_cacache/tmp/... (npm extracts a tarball, not
# a real git clone, so there's no .git in the temp dir itself).
RUN git init /root
COPY package*.json ./
RUN npm ci
COPY . .
ENV NEXT_PUBLIC_AMPLITUDE_API_KEY=$NEXT_PUBLIC_AMPLITUDE_API_KEY
RUN npm run build
# Production stage
FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
# Create non-root user
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Copy necessary files from builder
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
# Set correct permissions
RUN chown -R nextjs:nodejs /app
RUN chmod 755 /usr/local/bin/docker-entrypoint.sh
USER nextjs
EXPOSE 3000
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
CMD ["node", "server.js"]