Skip to content

Commit d2df363

Browse files
committed
Added the Dockerfile for the User Service.
1 parent b7ab44e commit d2df363

File tree

3 files changed

+84
-42
lines changed

3 files changed

+84
-42
lines changed
Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,34 @@
1-
# deps & build artifacts
2-
node_modules
3-
npm-debug.log
4-
yarn.lock
5-
pnpm-lock.yaml
6-
dist
7-
build
8-
.cache
9-
*.log
1+
# Include any files or directories that you don't want to be copied to your
2+
# container here (e.g., local build artifacts, temporary files, etc.).
3+
#
4+
# For more help, visit the .dockerignore file reference guide at
5+
# https://docs.docker.com/go/build-context-dockerignore/
106

11-
# env/secrets (never bake into the image)
12-
.env
13-
.env.*
14-
.DS_Store
15-
.git
7+
**/.classpath
8+
**/.dockerignore
9+
**/.env
10+
**/.git
11+
**/.gitignore
12+
**/.project
13+
**/.settings
14+
**/.toolstarget
15+
**/.vs
16+
**/.vscode
17+
**/.next
18+
**/.cache
19+
**/*.*proj.user
20+
**/*.dbmdl
21+
**/*.jfm
22+
**/charts
23+
**/docker-compose*
24+
**/compose.y*ml
25+
**/Dockerfile*
26+
**/node_modules
27+
**/npm-debug.log
28+
**/obj
29+
**/secrets.dev.yaml
30+
**/values.dev.yaml
31+
**/build
32+
**/dist
33+
LICENSE
34+
README.md
Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,38 @@
1-
# ---------- Base builder (installs deps) ----------
2-
FROM node:20-alpine AS deps
3-
WORKDIR /app
1+
# syntax=docker/dockerfile:1
42

5-
# If you have a package-lock.json, keep npm. If you use yarn/pnpm, adjust.
6-
COPY package*.json ./
7-
RUN npm ci --omit=dev
3+
# Comments are provided throughout this file to help you get started.
4+
# If you need more help, visit the Dockerfile reference guide at
5+
# https://docs.docker.com/go/dockerfile-reference/
86

9-
# ---------- Runtime image ----------
10-
FROM node:20-alpine AS runner
11-
ENV NODE_ENV=production
12-
WORKDIR /app
7+
# Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7
138

14-
# Copy node_modules from deps stage
15-
COPY --from=deps /app/node_modules ./node_modules
9+
ARG NODE_VERSION=22.21.0
10+
11+
FROM node:${NODE_VERSION}-alpine
12+
13+
# Use production node environment by default.
14+
ENV NODE_ENV production
1615

17-
# Copy app source
18-
COPY . .
1916

20-
# Security: run as non-root user
21-
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
22-
USER appuser
17+
WORKDIR /usr/src/app
2318

24-
# Healthcheck (optional but nice). If you have a /health route, use it.
25-
# Replace /health with your actual health endpoint.
26-
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
27-
CMD wget -qO- http://localhost:3001/health || exit 1
19+
# Download dependencies as a separate step to take advantage of Docker's caching.
20+
# Leverage a cache mount to /root/.npm to speed up subsequent builds.
21+
# Leverage a bind mounts to package.json and package-lock.json to avoid having to copy them into
22+
# into this layer.
23+
RUN --mount=type=bind,source=package.json,target=package.json \
24+
--mount=type=bind,source=package-lock.json,target=package-lock.json \
25+
--mount=type=cache,target=/root/.npm \
26+
npm ci --omit=dev
27+
28+
# Run the application as a non-root user.
29+
USER node
30+
31+
# Copy the rest of the source files into the image.
32+
COPY . .
2833

29-
# Expose the app port (matches your .env PORT)
34+
# Expose the port that the application listens on.
3035
EXPOSE 3001
3136

32-
# Start command. Change if your service uses a different entry (e.g. dist/index.js).
33-
# Common cases:
34-
# - "node src/server.js"
35-
# - "node index.js"
36-
# - "npm start" (if start script is set properly)
37-
CMD ["npm", "start"]
37+
# Run the application.
38+
CMD npm start
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
### Building and running your application
2+
3+
When you're ready, start your application by running:
4+
`docker compose up --build`.
5+
6+
Your application will be available at http://localhost:3001.
7+
8+
### Deploying your application to the cloud
9+
10+
First, build your image, e.g.: `docker build -t myapp .`.
11+
If your cloud uses a different CPU architecture than your development
12+
machine (e.g., you are on a Mac M1 and your cloud provider is amd64),
13+
you'll want to build the image for that platform, e.g.:
14+
`docker build --platform=linux/amd64 -t myapp .`.
15+
16+
Then, push it to your registry, e.g. `docker push myregistry.com/myapp`.
17+
18+
Consult Docker's [getting started](https://docs.docker.com/go/get-started-sharing/)
19+
docs for more detail on building and pushing.
20+
21+
### References
22+
* [Docker's Node.js guide](https://docs.docker.com/language/nodejs/)

0 commit comments

Comments
 (0)