/
Dockerfile
52 lines (39 loc) · 1.58 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
FROM node:18 as build
WORKDIR /usr/src/app
COPY package.json nx.json yarn.lock ./
COPY assets/services/assets-api ./assets/services/assets-api
COPY platform/packages ./platform/packages
# Install dependencies using the Yarn cache from the previous build, if one exists.
RUN --mount=type=cache,target=/yarn YARN_CACHE_FOLDER=/yarn yarn install --frozen-lockfile
# Build the Assets API and all its local dependencies.
RUN npm run build assets-api
# Remove the dev dependencies.
RUN --mount=type=cache,target=/yarn YARN_CACHE_FOLDER=/yarn yarn install --frozen-lockfile --production
# Remove all source files and keep only the build output.
RUN for DIR in packages services; do \
find ./platform/$DIR -maxdepth 2 -mindepth 2 ! \
\( -name "package.json" \
-or -name "dist" \
-or -name "build" \
-or -name "node_modules" \) \
| xargs rm -rf \
; done
RUN for DIR in packages services; do \
find ./assets/$DIR -maxdepth 2 -mindepth 2 ! \
\( -name "package.json" \
-or -name "dist" \
-or -name "build" \
-or -name "node_modules" \) \
| xargs rm -rf \
; done
FROM node:18-alpine3.14 as run
WORKDIR /usr/src/app
RUN chown node -R .
USER node
EXPOSE 3000
ENV PORT 3000
ENV NODE_ENV production
COPY --from=build --chown=node:node /usr/src/app/node_modules ./node_modules
COPY --from=build --chown=node:node /usr/src/app/assets/services/assets-api ./assets/services/assets-api
COPY --from=build --chown=node:node /usr/src/app/platform/packages ./platform/packages
CMD [ "node", "assets/services/metadata-api/dist/main"]