Spaces:
Running
Running
feat: dockerfile refactor for faster loading (#1574)
Browse files- Dockerfile +39 -35
Dockerfile
CHANGED
@@ -3,6 +3,41 @@
|
|
3 |
# you will also find guides on how best to write your Dockerfile
|
4 |
ARG INCLUDE_DB=false
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
FROM node:20 AS builder
|
7 |
|
8 |
WORKDIR /app
|
@@ -28,20 +63,19 @@ RUN git config --global --add safe.directory /app && \
|
|
28 |
FROM mongo:7 AS mongo
|
29 |
|
30 |
# image to be used if INCLUDE_DB is false
|
31 |
-
FROM
|
32 |
|
33 |
# image to be used if INCLUDE_DB is true
|
34 |
-
FROM
|
35 |
|
36 |
-
RUN apt-get update
|
37 |
-
RUN apt-get install gnupg curl -y
|
38 |
# copy mongo from the other stage
|
39 |
COPY --from=mongo /usr/bin/mongo* /usr/bin/
|
40 |
|
41 |
ENV MONGODB_URL=mongodb://localhost:27017
|
|
|
42 |
RUN mkdir -p /data/db
|
43 |
RUN chown -R 1000:1000 /data/db
|
44 |
-
|
45 |
# final image
|
46 |
FROM local_db_${INCLUDE_DB} AS final
|
47 |
|
@@ -55,38 +89,8 @@ ARG APP_BASE=
|
|
55 |
ARG PUBLIC_APP_COLOR=blue
|
56 |
ENV BODY_SIZE_LIMIT=15728640
|
57 |
|
58 |
-
# install dotenv-cli
|
59 |
-
RUN npm install -g dotenv-cli
|
60 |
-
|
61 |
-
# switch to a user that works for spaces
|
62 |
-
RUN userdel -r node
|
63 |
-
RUN useradd -m -u 1000 user
|
64 |
-
USER user
|
65 |
-
|
66 |
-
ENV HOME=/home/user \
|
67 |
-
PATH=/home/user/.local/bin:$PATH
|
68 |
-
|
69 |
-
WORKDIR /app
|
70 |
-
|
71 |
-
# add a .env.local if the user doesn't bind a volume to it
|
72 |
-
RUN touch /app/.env.local
|
73 |
-
|
74 |
-
# get the default config, the entrypoint script and the server script
|
75 |
-
COPY --chown=1000 package.json /app/package.json
|
76 |
-
COPY --chown=1000 .env /app/.env
|
77 |
-
COPY --chown=1000 entrypoint.sh /app/entrypoint.sh
|
78 |
-
COPY --chown=1000 gcp-*.json /app/
|
79 |
-
|
80 |
#import the build & dependencies
|
81 |
COPY --from=builder --chown=1000 /app/build /app/build
|
82 |
COPY --from=builder --chown=1000 /app/node_modules /app/node_modules
|
83 |
|
84 |
-
RUN npx playwright install
|
85 |
-
|
86 |
-
USER root
|
87 |
-
RUN npx playwright install-deps
|
88 |
-
USER user
|
89 |
-
|
90 |
-
RUN chmod +x /app/entrypoint.sh
|
91 |
-
|
92 |
CMD ["/bin/bash", "-c", "/app/entrypoint.sh"]
|
|
|
3 |
# you will also find guides on how best to write your Dockerfile
|
4 |
ARG INCLUDE_DB=false
|
5 |
|
6 |
+
FROM node:20-slim AS base
|
7 |
+
|
8 |
+
# install dotenv-cli
|
9 |
+
RUN npm install -g dotenv-cli
|
10 |
+
|
11 |
+
# switch to a user that works for spaces
|
12 |
+
RUN userdel -r node
|
13 |
+
RUN useradd -m -u 1000 user
|
14 |
+
USER user
|
15 |
+
|
16 |
+
ENV HOME=/home/user \
|
17 |
+
PATH=/home/user/.local/bin:$PATH
|
18 |
+
|
19 |
+
WORKDIR /app
|
20 |
+
|
21 |
+
# add a .env.local if the user doesn't bind a volume to it
|
22 |
+
RUN touch /app/.env.local
|
23 |
+
|
24 |
+
|
25 |
+
# get the default config, the entrypoint script and the server script
|
26 |
+
COPY --chown=1000 package.json /app/package.json
|
27 |
+
COPY --chown=1000 .env /app/.env
|
28 |
+
COPY --chown=1000 entrypoint.sh /app/entrypoint.sh
|
29 |
+
COPY --chown=1000 gcp-*.json /app/
|
30 |
+
|
31 |
+
RUN npx playwright install
|
32 |
+
|
33 |
+
USER root
|
34 |
+
RUN apt-get update
|
35 |
+
RUN apt-get install gnupg curl -y
|
36 |
+
RUN npx playwright install-deps
|
37 |
+
USER user
|
38 |
+
RUN chmod +x /app/entrypoint.sh
|
39 |
+
|
40 |
+
|
41 |
FROM node:20 AS builder
|
42 |
|
43 |
WORKDIR /app
|
|
|
63 |
FROM mongo:7 AS mongo
|
64 |
|
65 |
# image to be used if INCLUDE_DB is false
|
66 |
+
FROM base AS local_db_false
|
67 |
|
68 |
# image to be used if INCLUDE_DB is true
|
69 |
+
FROM base AS local_db_true
|
70 |
|
|
|
|
|
71 |
# copy mongo from the other stage
|
72 |
COPY --from=mongo /usr/bin/mongo* /usr/bin/
|
73 |
|
74 |
ENV MONGODB_URL=mongodb://localhost:27017
|
75 |
+
USER root
|
76 |
RUN mkdir -p /data/db
|
77 |
RUN chown -R 1000:1000 /data/db
|
78 |
+
USER user
|
79 |
# final image
|
80 |
FROM local_db_${INCLUDE_DB} AS final
|
81 |
|
|
|
89 |
ARG PUBLIC_APP_COLOR=blue
|
90 |
ENV BODY_SIZE_LIMIT=15728640
|
91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
#import the build & dependencies
|
93 |
COPY --from=builder --chown=1000 /app/build /app/build
|
94 |
COPY --from=builder --chown=1000 /app/node_modules /app/node_modules
|
95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
CMD ["/bin/bash", "-c", "/app/entrypoint.sh"]
|