Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
58 lines (47 loc) · 1.62 KB
/
Copy pathDockerfile
File metadata and controls
58 lines (47 loc) · 1.62 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
FROM node:24.22.1-alpine AS ci
ENV NODE_ENV=test
ENV BLUEBIRD_DEBUG=0
ENV HUSKY_SKIP_INSTALL=true
ARG CI=true
RUN mkdir /app
WORKDIR /app
# Install dependencies before copying the full source code to take advantage of Docker layer caching
COPY package*.json ./
COPY .npmrc ./
# Needed for postinstall (build:models) during npm ci
COPY src/build-spec.ts ./src/build-spec.ts
COPY src/openapi ./src/openapi
# @linode/dex-client-grpc is hosted on GitHub Packages, which requires auth even for public pkg.
RUN --mount=type=secret,id=NPM_TOKEN \
cp .npmrc .npmrc.orig && \
echo "//npm.pkg.github.com/:_authToken=$(cat /run/secrets/NPM_TOKEN)" >> .npmrc && \
npm ci && \
mv .npmrc.orig .npmrc
COPY . .* ./
RUN npm run build
RUN npm run lint
RUN npm run test
# --------------- Cleanup
FROM ci AS clean
# below command removes the packages specified in devDependencies and set NODE_ENV to production
RUN npm prune --production
# --------------- Production stage
FROM node:24.22.1-alpine AS prod
ENV NODE_ENV=production
ENV NODE_PATH='dist'
# Install dependencies
RUN apk --no-cache add python3 git jq openssh tini
# Install app
RUN mkdir /app
WORKDIR /app
COPY --from=clean /app/node_modules node_modules
COPY --from=ci /app/dist dist
COPY package.json .
# Add nouser to /etc/passwd for ssh connection
RUN echo 'nouser:x:999:999::/home/nouser:/bin/sh' >> /etc/passwd
USER node
EXPOSE 8080
# tini is used as PID 1 to reap zombie child processes (e.g. git-remote-http)
# that Node.js would otherwise leave unreaped, causing PID exhaustion over time
ENTRYPOINT ["/sbin/tini", "--"]
CMD ["node", "--max-http-header-size", "16384", "dist/src/app.js"]