Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions chef-service/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# compiled output
/dist
/node_modules
/build

# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# temp directory
.temp
.tmp

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
40 changes: 40 additions & 0 deletions chef-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Stage 1: Build the application
FROM node:22 AS builder

# Declare build-time arguments
ARG DATABASE_URL
ARG NATS_URL

# Set environment variables in the Docker image
ENV DATABASE_URL=$DATABASE_URL
ENV NATS_URL=$NATS_URL

Comment on lines +1 to +11
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider security improvements and version stability

Several improvements can enhance security and stability:

  1. Pin the Node.js version to a specific minor version (e.g., node:20.11-slim) for better predictability
  2. Use --platform flag for multi-architecture support
  3. Avoid setting sensitive environment variables during build stage

Apply this diff:

-FROM node:22 AS builder
+FROM --platform=$BUILDPLATFORM node:20.11-slim AS builder

# Declare build-time arguments
ARG DATABASE_URL
ARG NATS_URL

-# Set environment variables in the Docker image
-ENV DATABASE_URL=$DATABASE_URL
-ENV NATS_URL=$NATS_URL
+# Build arguments should not be persisted as ENV in builder stage
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Stage 1: Build the application
FROM node:22 AS builder
# Declare build-time arguments
ARG DATABASE_URL
ARG NATS_URL
# Set environment variables in the Docker image
ENV DATABASE_URL=$DATABASE_URL
ENV NATS_URL=$NATS_URL
# Stage 1: Build the application
FROM --platform=$BUILDPLATFORM node:20.11-slim AS builder
# Declare build-time arguments
ARG DATABASE_URL
ARG NATS_URL
# Build arguments should not be persisted as ENV in builder stage

WORKDIR /app

COPY package*.json ./
RUN npm install

COPY . .
RUN npm run build
Comment on lines +12 to +18
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Optimize build process and improve reliability

Several improvements can enhance build efficiency and reliability:

  1. Use npm ci instead of npm install for reproducible builds
  2. Leverage build cache for node_modules
  3. Ensure proper .dockerignore is in place

Apply this diff:

WORKDIR /app

COPY package*.json ./
-RUN npm install
+RUN npm ci

+# Copy only necessary source files
-COPY . .
+COPY src/ ./src/
+COPY tsconfig*.json ./
+
+# Build the application
RUN npm run build

Also, create a .dockerignore file with the following contents:

node_modules
npm-debug.log
dist
.git
.env
*.md

Committable suggestion skipped: line range outside the PR's diff.


# Stage 2: Run the application
FROM node:22

# Declare build-time arguments
ARG DATABASE_URL
ARG NATS_URL

# Set environment variables in the Docker image
ENV DATABASE_URL=$DATABASE_URL
ENV NATS_URL=nats://nats-streaming:4222

Comment on lines +20 to +30
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Address security concerns and configuration flexibility

Several critical improvements needed:

  1. Use non-root user for security
  2. Consider using environment variables for all configuration
  3. Use same version improvements as builder stage

Apply this diff:

-FROM node:22
+FROM --platform=$BUILDPLATFORM node:20.11-slim

# Declare build-time arguments
ARG DATABASE_URL
ARG NATS_URL

+# Create non-root user
+RUN groupadd -r nodejs && useradd -r -g nodejs nodejs

# Set environment variables in the Docker image
ENV DATABASE_URL=$DATABASE_URL
-ENV NATS_URL=nats://nats-streaming:4222
+ENV NATS_URL=${NATS_URL:-nats://nats-streaming:4222}

WORKDIR /app
+# Change ownership of working directory
+RUN chown nodejs:nodejs /app
+
+# Switch to non-root user
+USER nodejs
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Stage 2: Run the application
FROM node:22
# Declare build-time arguments
ARG DATABASE_URL
ARG NATS_URL
# Set environment variables in the Docker image
ENV DATABASE_URL=$DATABASE_URL
ENV NATS_URL=nats://nats-streaming:4222
# Stage 2: Run the application
FROM --platform=$BUILDPLATFORM node:20.11-slim
# Declare build-time arguments
ARG DATABASE_URL
ARG NATS_URL
# Create non-root user
RUN groupadd -r nodejs && useradd -r -g nodejs nodejs
# Set environment variables in the Docker image
ENV DATABASE_URL=$DATABASE_URL
ENV NATS_URL=${NATS_URL:-nats://nats-streaming:4222}
WORKDIR /app
# Change ownership of working directory
RUN chown nodejs:nodejs /app
# Switch to non-root user
USER nodejs

WORKDIR /app

COPY package*.json ./
RUN npm install --only=production

COPY --from=builder /app/dist ./dist

EXPOSE 3000

CMD ["node", "dist/main"]
28 changes: 21 additions & 7 deletions chef-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,42 +29,56 @@
## Project setup

```bash
$ pnpm install
$ npm install
```

## Compile and run the project

```bash
# development
$ pnpm run start
$ npm run start

# watch mode
$ pnpm run start:dev
$ npm run start:dev

# production mode
$ pnpm run start:prod
$ npm run start:prod
```

## Run tests

```bash
# unit tests
$ pnpm run test
$ npm run test

# e2e tests
$ pnpm run test:e2e
$ npm run test:e2e

# test coverage
$ pnpm run test:cov
$ npm run test:cov
```

## Deployment

When you're ready to deploy your NestJS application to production, there are some key steps you can take to ensure it runs as efficiently as possible. Check out the [deployment documentation](https://docs.nestjs.com/deployment) for more information.

If you are looking for a cloud-based platform to deploy your NestJS application, check out [Mau](https://mau.nestjs.com), our official platform for deploying NestJS applications on AWS. Mau makes deployment straightforward and fast, requiring just a few simple steps:

```bash
$ npm install -g mau
$ mau deploy
```

With Mau, you can deploy your application in just a few clicks, allowing you to focus on building features rather than managing infrastructure.

Comment on lines +61 to +73
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add Docker deployment instructions

While the Mau deployment instructions are valuable, considering the PR's focus on Docker containerization, it would be beneficial to add Docker-specific deployment instructions.

Consider adding a section like this:

## Deployment

+ ### Docker Deployment
+ 
+ To run the service using Docker:
+ 
+ ```bash
+ # Build the Docker image
+ $ docker build -t chef-service .
+ 
+ # Run the container
+ $ docker run -p 3000:3000 chef-service
+ ```
+ 
### Cloud Deployment

When you're ready to deploy your NestJS application to production...
🧰 Tools
🪛 Markdownlint

68-68: null
Dollar signs used before commands without showing output

(MD014, commands-show-output)


69-69: null
Dollar signs used before commands without showing output

(MD014, commands-show-output)

## Resources

Check out a few resources that may come in handy when working with NestJS:

- Visit the [NestJS Documentation](https://docs.nestjs.com) to learn more about the framework.
- For questions and support, please visit our [Discord channel](https://discord.gg/G7Qnnhy).
- To dive deeper and get more hands-on experience, check out our official video [courses](https://courses.nestjs.com/).
- Deploy your application to AWS with the help of [NestJS Mau](https://mau.nestjs.com) in just a few clicks.
- Visualize your application graph and interact with the NestJS application in real-time using [NestJS Devtools](https://devtools.nestjs.com).
- Need help with your project (part-time to full-time)? Check out our official [enterprise support](https://enterprise.nestjs.com).
- To stay in the loop and get updates, follow us on [X](https://x.com/nestframework) and [LinkedIn](https://linkedin.com/company/nestjs).
Expand Down
Loading