Skip to content

Commit e3a209c

Browse files
committed
chore(containers): clarify Dockerfile comments and npm scripts usage in README
1 parent 62c81cf commit e3a209c

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

Dockerfile

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
# - Stage 1: Builder -----------------------------------------------------------
2-
1+
# ------------------------------------------------------------------------------
2+
# Stage 1: Builder
33
# This stage builds the application and its dependencies.
4+
# ------------------------------------------------------------------------------
45
FROM node:jod-alpine AS builder
56

67
WORKDIR /app
@@ -24,9 +25,10 @@ RUN npm run build && \
2425
npm run swagger:docs && \
2526
npm prune --omit=dev
2627

27-
# - Stage 2: Runtime -----------------------------------------------------------
28-
28+
# ------------------------------------------------------------------------------
29+
# Stage 2: Runtime
2930
# This stage creates the final, minimal image to run the application.
31+
# ------------------------------------------------------------------------------
3032
FROM node:jod-alpine AS runtime
3133

3234
WORKDIR /app
@@ -37,23 +39,21 @@ LABEL org.opencontainers.image.description="Proof of Concept for a RESTful API m
3739
LABEL org.opencontainers.image.licenses="MIT"
3840
LABEL org.opencontainers.image.source="https://github.com/nanotaboada/ts-node-samples-express-restful"
3941

40-
# Install the SQLite runtime libraries, add a non-root user for security
41-
# hardening, and set the ownership of the /app directory to this user.
42-
RUN apk add --no-cache sqlite-libs && \
43-
adduser -D -g "" express && \
44-
chown -R express:express /app
42+
# Copy README and assets (read-only): often displayed in container registries such as Docker Hub or GHCR
43+
COPY --chown=root:root --chmod=644 README.md ./
44+
COPY --chown=root:root --chmod=755 assets/ ./assets/
4545

46-
# Copy transpiled JavaScript, pruned node_modules, SQLite database and Swagger JSON.
47-
COPY --from=builder --chown=express:express /app/dist ./dist
48-
COPY --from=builder --chown=express:express /app/node_modules ./dist/node_modules
49-
COPY --from=builder --chown=express:express /app/src/data/players-sqlite3.db ./dist/data/players-sqlite3.db
50-
COPY --from=builder --chown=express:express /app/dist/swagger.json ./dist/swagger.json
46+
# Install SQLite runtime libraries and create a system-like user (express) for running the app.
47+
RUN apk add --no-cache sqlite-libs && \
48+
adduser -D -g "" express
5149

52-
# Copy README and assets to the root of the app.
53-
# This is often displayed in registries like GitHub Container Registry.
54-
COPY README.md ./
55-
COPY assets/ ./assets/
50+
# Copy transpiled JavaScript, pruned node_modules, SQLite database and Swagger JSON, owned by express
51+
COPY --from=builder --chown=express:express --chmod=755 /app/dist ./dist
52+
COPY --from=builder --chown=express:express --chmod=755 /app/node_modules ./dist/node_modules
53+
COPY --from=builder --chown=express:express --chmod=644 /app/dist/swagger.json ./dist/swagger.json
54+
COPY --from=builder --chown=express:express --chmod=664 /app/src/data/players-sqlite3.db ./dist/data/players-sqlite3.db
5655

56+
# Drop privileges: run as express
5757
USER express
5858

5959
EXPOSE 9000

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ This project includes a multi-stage `Dockerfile` for local development and produ
6666
### Build the image
6767

6868
```bash
69-
docker build -t ts-node-samples-express-restful .
69+
npm run docker:build
7070
```
7171

7272
### Run the container
7373

7474
```bash
75-
docker run -p 9000:9000 ts-node-samples-express-restful:latest
75+
npm run docker:run
7676
```
7777

7878
## Credits

0 commit comments

Comments
 (0)