-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathDockerfile
More file actions
128 lines (95 loc) · 3.8 KB
/
Copy pathDockerfile
File metadata and controls
128 lines (95 loc) · 3.8 KB
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
# syntax=docker/dockerfile:1
ARG NODE_VER=22-alpine
# Copy in package files and any needed apt packages?
FROM node:${NODE_VER} AS packages
WORKDIR /oada
# Need to list out every package.json we need from monorepo for caching stuff...
COPY --link ./yarn.lock ./.yarnrc.yml /oada/
# TODO: How to COPY all package.json files with glob?
COPY ./package.json /oada/package.json
COPY ./libs/models/package.json /oada/libs/models/package.json
COPY ./libs/lib-arangodb/package.json /oada/libs/lib-arangodb/package.json
COPY ./libs/lib-config/package.json /oada/libs/lib-config/package.json
COPY ./libs/lib-kafka/package.json /oada/libs/lib-kafka/package.json
COPY ./libs/lib-prom/package.json /oada/libs/lib-prom/package.json
COPY ./libs/pino-debug/package.json /oada/libs/pino-debug/package.json
COPY ./services/auth/package.json /oada/services/auth/package.json
COPY ./services/http-handler/package.json /oada/services/http-handler/package.json
COPY ./services/permissions-handler/package.json /oada/services/permissions-handler/package.json
COPY ./services/rev-graph-update/package.json /oada/services/rev-graph-update/package.json
COPY ./services/shares/package.json /oada/services/shares/package.json
COPY ./services/startup/package.json /oada/services/startup/package.json
COPY ./services/sync-handler/package.json /oada/services/sync-handler/package.json
COPY ./services/users/package.json /oada/services/users/package.json
COPY ./services/webhooks/package.json /oada/services/webhooks/package.json
COPY ./services/well-known/package.json /oada/services/well-known/package.json
COPY ./services/write-handler/package.json /oada/services/write-handler/package.json
RUN corepack yarn workspaces focus --all --production
# Install just production deps
FROM packages AS yarn
# Copy in actual code
COPY --link . /oada/
# Run again to be safe?
RUN corepack yarn workspaces focus --all --production
# Install all deps and run build step
# Allows for workspaces to have build step (e.g., for TypeScript)
FROM packages AS dev
# Install _all_ dependencies for build
RUN corepack yarn install --immutable
# Copy in actual code
COPY --link . /oada/
# Run again to be safe?
RUN corepack yarn install --immutable
RUN corepack yarn sdks vscode vim
FROM dev AS build
# Build and then remove yarn stuff
RUN corepack yarn build --verbose && rm -rfv .yarn .pnp.*
FROM node:${NODE_VER} AS code
# Copy in service code and production dependencies
COPY --from=yarn /oada/ /oada/
# Copy in built code
COPY --from=build /oada/ /oada/
# Assemble "production" image
FROM node:$NODE_VER AS production
WORKDIR /oada
# Install needed packages
RUN apk add --no-cache \
dumb-init \
libc6-compat
# Copy in entrypoint script
COPY ./utils/entrypoint.sh /entrypoint.sh
RUN chmod u+x /entrypoint.sh
RUN chown node:node /entrypoint.sh
# Get wait-for script
ARG WAIT_FOR_VER=v2.2.3
RUN wget https://raw.githubusercontent.com/eficode/wait-for/${WAIT_FOR_VER}/wait-for -O /wait-for
RUN chmod u+x /wait-for
RUN chown node:node /wait-for
# Copy in config file?
COPY ./oada.config.mjs /oada.config.mjs
# Launch entrypoint with dumb-init
# Remap SIGTERM to SIGINT https://github.com/Yelp/dumb-init#signal-rewriting
ENTRYPOINT ["/usr/bin/dumb-init", "--rewrite", "15:2", "--", "/entrypoint.sh"]
# Run start script of package
CMD ["start"]
# Add volume for Binary data and chown to node?
RUN mkdir -p /oada/binary && chown node:node /oada/binary
#VOLUME /oada/binary
# Copy in the code
COPY --from=code /oada/ /oada/
ARG OADA_SERVICE
ENV OADA_SERVICE=${OADA_SERVICE}
ENV INSPECT=
# Have corepack download yarn
ENV COREPACK_HOME=/oada/.cache/node/corepack
RUN corepack enable
RUN corepack install
WORKDIR /oada/services/${OADA_SERVICE}
# Do not run services as root
USER node
ENV PORT=8080
FROM production AS debug
USER root
COPY --from=dev /oada/ /oada/
# Default to a production target
FROM production