11# base node image
22FROM node:16-bullseye-slim as base
33
4- # Install openssl for Prisma
5- RUN apt-get update && apt-get install -y openssl
6-
4+ # set for base and all layer that inherit from it
75ENV NODE_ENV production
86
7+ # Install openssl for Prisma
8+ RUN apt-get update && apt-get install -y openssl sqlite3
9+
910# Install all node_modules, including dev dependencies
1011FROM base as deps
1112
12- RUN mkdir /app
13- WORKDIR /app
13+ WORKDIR /myapp
1414
15- ADD package.json package-lock.json ./
16- RUN npm install --production=false
15+ ADD package.json .npmrc ./
16+ RUN npm install --include=dev
1717
1818# Setup production node_modules
1919FROM base as production-deps
2020
21- RUN mkdir /app
22- WORKDIR /app
21+ WORKDIR /myapp
2322
24- COPY --from=deps /app /node_modules /app /node_modules
25- ADD package.json package-lock.json ./
26- RUN npm prune --production
23+ COPY --from=deps /myapp /node_modules /myapp /node_modules
24+ ADD package.json .npmrc ./
25+ RUN npm prune --omit=dev
2726
2827# Build the app
2928FROM base as build
3029
31- RUN mkdir /app
32- WORKDIR /app
30+ WORKDIR /myapp
3331
34- COPY --from=deps /app /node_modules /app /node_modules
32+ COPY --from=deps /myapp /node_modules /myapp /node_modules
3533
3634ADD prisma .
3735RUN npx prisma generate
@@ -42,16 +40,22 @@ RUN npm run build
4240# Finally, build the production image with minimal footprint
4341FROM base
4442
45- ENV NODE_ENV production
43+ ENV DATABASE_URL=file:/data/sqlite.db
44+ ENV PORT="8080"
45+ ENV NODE_ENV="production"
4646
47- RUN mkdir /app
48- WORKDIR /app
47+ # add shortcut for connecting to database CLI
48+ RUN echo "#!/bin/sh \n set -x \n sqlite3 \$ DATABASE_URL" > /usr/local/bin/database-cli && chmod +x /usr/local/bin/database-cli
4949
50- COPY --from=production-deps /app/node_modules /app/node_modules
51- COPY --from=build /app/node_modules/.prisma /app/node_modules/.prisma
52- COPY --from=build /app/build /app/build
53- COPY --from=build /app/public /app/public
54- ADD . .
50+ WORKDIR /myapp
51+
52+ COPY --from=production-deps /myapp/node_modules /myapp/node_modules
53+ COPY --from=build /myapp/node_modules/.prisma /myapp/node_modules/.prisma
54+
55+ COPY --from=build /myapp/build /myapp/build
56+ COPY --from=build /myapp/public /myapp/public
57+ COPY --from=build /myapp/package.json /myapp/package.json
58+ COPY --from=build /myapp/start.sh /myapp/start.sh
59+ COPY --from=build /myapp/prisma /myapp/prisma
5560
56- ENV PORT 8080
57- CMD ["npm" , "run" , "start" ]
61+ ENTRYPOINT [ "./start.sh" ]
0 commit comments