forked from thirdweb-dev/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
133 lines (87 loc) · 3.15 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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
FROM node:18.15.0-alpine AS base
# Install tini
RUN apk add --no-cache tini
# Set the working directory
WORKDIR /app
# Use tini as entrypoint to handle killing processes
ENTRYPOINT ["/sbin/tini", "--"]
# Install build dependencies
RUN apk --no-cache --virtual build-dependencies add g++ make py3-pip openssl
# Copy package.json and yarn.lock files
COPY package*.json yarn*.lock ./
# Copy the entire project directory
COPY . .
RUN npm install -g nodemon
# Install dependencies for both development and production
RUN yarn install --frozen-lockfile --network-timeout 1000000
WORKDIR /app/https
RUN openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 \
-subj "/C=US/ST=State/L=City/O=Organization/OU=Unit/CN=localhost" \
-passout pass:thirdweb-engine
RUN chmod 600 key.pem cert.pem
WORKDIR /app
# Clean up build dependencies
RUN apk del build-dependencies
##############################
##############################
FROM base AS local_server
EXPOSE 3005
ENV NODE_ENV="local"
CMD [ "sh", "-c","yarn prisma:setup:dev && yarn dev:server" ]
##############################
##############################
FROM base AS local_worker
ENV NODE_ENV="local"
CMD [ "sh", "-c", "yarn prisma:setup:dev && yarn dev:worker" ]
##############################
##############################
# Production Node Modules stage
FROM node:18.15.0-alpine AS prod-dependencies
# Install build dependencies
RUN apk add --no-cache g++ make py3-pip openssl
WORKDIR /app
# Copy package.json and yarn.lock files
COPY package*.json yarn*.lock ./
# Copy the entire project directory
COPY . .
COPY --from=base /app/node_modules ./node_modules
# Build the project
RUN yarn build
RUN yarn copy-files
RUN rm -rf node_modules
# Install production dependencies only
RUN yarn install --production=true --frozen-lockfile --network-timeout 1000000
# Generate SSL certificates
WORKDIR /app/dist/https
RUN openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 \
-subj "/C=US/ST=State/L=City/O=Organization/OU=Unit/CN=localhost" \
-passout pass:thirdweb-engine
RUN chmod 600 key.pem cert.pem
# Clean up build dependencies
RUN apk del g++ make py3-pip openssl
##############################
##############################
# Production stage
FROM node:18.15.0-alpine AS prod
# Setting ENV variables for image information
ARG ENGINE_VERSION
ENV ENGINE_VERSION=${ENGINE_VERSION}
# Install tini
RUN apk add --no-cache tini
# Set the working directory
WORKDIR /app
ENV NODE_ENV="production"
EXPOSE 3005
# Copy package.json and yarn.lock files
COPY package*.json yarn*.lock ./
# Replace the schema path in the package.json file
RUN sed -i 's_"schema": "./src/prisma/schema.prisma"_"schema": "./dist/prisma/schema.prisma"_g' package.json
# Copy only production dependencies from the prod-dependencies stage
COPY --from=prod-dependencies /app/node_modules ./node_modules
COPY --from=prod-dependencies /app/dist ./dist
COPY --from=prod-dependencies /app/dist/https ./dist/https
# Add the node_modules/.bin directory to the PATH
ENV PATH /app/node_modules/.bin:$PATH
# Use tini as entrypoint to handle killing processes
ENTRYPOINT ["/sbin/tini", "--"]
CMD [ "yarn", "start"]