-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
93 lines (66 loc) · 2.77 KB
/
Dockerfile
File metadata and controls
93 lines (66 loc) · 2.77 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
# Based on https://raw.githubusercontent.com/BretFisher/node-docker-good-defaults/main/Dockerfile
# and https://raw.githubusercontent.com/BretFisher/nodejs-rocks-in-docker/main/dockerfiles/3.Dockerfile
###############################################################################
# base stage
FROM node:22-alpine AS base
# Install the latest bash (for script-running), openssl (for HTTPS), and some other tools (for debugging)
RUN apk upgrade && apk add bash openssl curl postgresql17-client nano
# RUN apt update -y && apt install -y openssl curl postgresql-client nano
# Default NODE_ENV to development (the safest); later stages will override this if needed
ENV NODE_ENV=development
# Default to port 3000 for Node
ARG PORT=3000
ENV PORT=$PORT
EXPOSE $PORT
# Use the built-in node user so that we're not running as root
# https://github.com/nodejs/docker-node/blob/master/docs/BestPractices.md#non-root-user
USER node
# WORKDIR now sets correct permissions if you set USER first
# We'll use /app for all our stuff
WORKDIR /app
# Pull in package.json in prep for dependency installation
COPY --chown=node:node package.json package-lock.json* ./
# Install only the production dependencies (we'll install dev deps in the dev stage)
# RUN npm ci --prefer-offline --no-audit --no-fund && npm cache clean --force
RUN --mount=type=cache,target=~/.npm npm ci --no-audit --no-fund
# Make sure we can run commands from node_modules/.bin
ENV PATH=/app/node_modules/.bin:$PATH
###############################################################################
# dev stage
FROM base AS dev
# overwrite NODE_ENV to development
ENV NODE_ENV=development
# Expose port 24678 for HMR
EXPOSE 24678
# Expose ports 9229 and 9230 (tests) for debug
EXPOSE 9229 9230
# Install all the dev deps (you can't do just that, so we have to install everything)
RUN --mount=type=cache,target=~/.npm npm install
# Copy the code in
COPY --chown=node:node . .
# Regenerate db models
RUN npm run compile:db
# Check every 30s to ensure /api/ping returns HTTP 200
HEALTHCHECK --interval=30s CMD node ./scripts/healthchecks/trackbear.js
# Start the server (this also runs migrations)
CMD [ "./entrypoint.sh" ]
###############################################################################
# prod stage
FROM base AS prod
# overwrite NODE_ENV to production
ENV NODE_ENV=production
# Copy the code in
COPY --chown=node:node . .
# Regenerate db models
ARG PRISMA_GENERATE_DATABASE_URL
RUN npm run compile:db
# Compile the API
RUN npm run compile:api
# Compile the help docs
RUN npm run compile:help
# Compile the front-end
RUN npm run compile:client
# Check every 30s to ensure /api/ping returns HTTP 200
HEALTHCHECK --interval=30s CMD node ./scripts/healthchecks/trackbear.js
# Start the server (this also runs migrations)
CMD [ "./entrypoint.sh" ]