-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
60 lines (52 loc) · 2.37 KB
/
Dockerfile
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
############################ INSTALL STAGE ##################################
# FROM oven/bun:alpine AS base
FROM imbios/bun-node:1.1-20.12.2-alpine AS install-dependecies-stage
#Use this options when running on aws t2.micro/nano or anything with vCPU=1 and RAM<=2GBs
#it will take longer but it wont freeze
ENV NODE_OPTIONS --max-old-space-size=512
ENV NODE_OPTIONS --max_semi_space_size=128
WORKDIR /app/website
COPY package.json .
COPY bun.lockb .
RUN bun install
########################### BUILD STAGE ##################################
FROM install-dependecies-stage AS build-compile-stage
#Use this options when running on aws t2.micro/nano or anything with vCPU=1 and RAM<=2GBs
#it will take longer but it wont freeze
ENV NODE_OPTIONS --max-old-space-size=512
ENV NODE_OPTIONS --max_semi_space_size=128
WORKDIR /app/website
COPY . .
COPY --from=install-dependecies-stage /app/website/node_modules ./node_modules
RUN \
if [ -f bun.lockb ]; then bun run build; \
elif [ -f yarn.lock ]; then yarn run build; \
elif [ -f package-lock.json ]; then yarn run build; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
elif [ -f package.json ]; then yarn run build; \
else echo "Lockfile not found." && exit 1; \
fi
############################### PRODUCTION STAGE #################################
FROM node:21.7.1-alpine AS production-stage
WORKDIR /app/website
#Use this options when running on aws t2.micro/nano or anything with vCPU=1 and RAM<=2GBs
#it will take longer but it wont freeze
ENV NODE_OPTIONS --max-old-space-size=512
ENV NODE_OPTIONS --max_semi_space_size=128
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED 1
#Change your timezone
#ENV TZ="America/New_York"
RUN addgroup --system --gid 1002 nodejs
RUN adduser --system --uid 1002 nextjs
#ADD YOUR ENV HERE
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=build-compile-stage --chown=nextjs:nodejs /app/website/.next/standalone ./
COPY --from=build-compile-stage --chown=nextjs:nodejs /app/website/public /app/website/public
COPY --from=build-compile-stage --chown=nextjs:nodejs /app/website/.next/static /app/website/.next/static
USER nextjs
EXPOSE 8000
ENV PORT 8000
CMD HOSTNAME="0.0.0.0" node server.js
##########################################################################