Using Watch Mode for Automatic Rebuilds

Scenario: A developer working on the genai-stack project wants to enable automatic rebuilds whenever they make changes to the codebase. They can achieve this by using watch mode when building the stack.

Codebase Files and Directories:

  • embedding_model/
  • front-end/
  • public/
  • vite.svg
  • src/
  • assets/
  • lib/
  • App.svelte
  • app.css
  • main.js
  • vite-env.d.ts
  • index.html
  • jsconfig.json
  • package-lock.json
  • package.json
  • postcss.config.js
  • svelte.config.js
  • tailwind.config.js
  • vite.config.js
  • images/
  • datamodel.png
  • CONTRIBUTING.md
  • LICENSE
  • api.Dockerfile
  • api.py
  • bot.Dockerfile
  • bot.py
  • chains.py
  • docker-compose.yml
  • env.example
  • front-end.Dockerfile
  • install_ollama.sh
  • loader.Dockerfile
  • loader.py
  • pdf_bot.Dockerfile
  • pdf_bot.py
  • pull_model.Dockerfile
  • readme.md
  • requirements.txt
  • running_on_wsl.md
  • utils.py

Documentation:

To enable watch mode for automatic rebuilds in the genai-stack project, follow these steps:

  1. Open the terminal and navigate to the root directory of the project (genai-stack).

  2. Build the stack using Docker Compose with the --build-arg WATCH_MODE=true flag:

docker-compose up --build --build-arg WATCH_MODE=true

This flag enables watch mode for all services in the docker-compose.yml file.

  1. Now, whenever you make changes to any file in the project, the corresponding service will be automatically rebuilt.

Tests:

To verify that watch mode is working correctly, make a change to one of the files (e.g., update the text in App.svelte), save the file, and observe the output in the terminal. You should see a message indicating that the service is being rebuilt.

Additionally, you can check the running containers by using the following command:

docker ps

You should see the container for the affected service being restarted.

References:

Videos: