apihub icon indicating copy to clipboard operation
apihub copied to clipboard

[enhancement]: Enhance Developer Experience with Docker Compose

Open yntpdotme opened this issue 1 year ago • 1 comments

Description:

Current setup poses challenges and hampers developer productivity

  1. Currently, our Docker Compose configuration uses bind mounting for the backend service, which requires

    • managing the node_modules separately
    • rebuilding the image whenever a new dependency is added to the project.
  2. Additionally, the MongoDB service logs clutter the terminal, making it difficult to focus on relevant information and causing unnecessary distraction.

Proposed Changes:

  1. Implement Docker Compose watch feature to automatically sync and rebuild, eliminating the need for bind mounting and manual management of node_modules.

  2. Optimize MongoDB service by adding --quiet and --logpath /dev/null options to reduce log clutter.

Use Case

After running docker compose up --build:

  • Press w to Enable Watch

    Screenshot 2024-05-02 at 11 27 50

  • Syncing backend service after changes in code

    Screenshot 2024-05-02 at 12 28 47

  • Rebuilding backend service after changes in dependencies

    Screenshot 2024-05-02 at 11 31 16

Additional Information

  • By implementing these changes, we aim to streamline the development workflow, improve developer productivity, and reduce the overhead of managing dependencies and logs.

  • This enhancement aligns with our goal of providing a seamless development experience for contributors.

Additional context or Information

  • Initial Configuration:

    docker-compose.yaml
    version: '3.8'
    
    services:
      backend:
        image: freeapi-server
        build: .
        ports:
          - 8080:8080
        volumes:
          - ./:/usr/src/freeapi
          - /usr/src/freeapi/node_modules
        env_file:
          - ./.env
        depends_on:
          - mongodb
      mongodb:
        image: mongo
        container_name: mongodb
        volumes:
          - data:/data/db
        ports:
          - 27017:27017
    
    volumes:
      data:
    
  • Proposed Configuration:

    docker-compose.yaml
    version: '3.8'
    
    services:
      backend:
        image: freeapi-server
        build: .
        ports:
          - 8080:8080
        env_file:
          - ./.env
        depends_on:
          - mongodb
        develop:
          watch:
            - action: sync
              path: .
              target: /usr/src/freeapi
              ignore:
                - node_modules/
            - action: rebuild
              path: ./package.json
    
      mongodb:
        image: mongo
        container_name: mongodb
        command: ['--quiet', '--logpath', '/dev/null']
        volumes:
          - data:/data/db
        ports:
          - 27017:27017
    
    volumes:
      data:
    

Suggested Tools

  • Docker Compose Watch

    Docker Compose documentation for file watching feature.

  • Hands on

    Practical demo on implementing Docker Compose improvements.

Labels:

  • enhancement
  • docker
  • developer-experience

yntpdotme avatar May 02 '24 07:05 yntpdotme

@KadlagAkash Looks good. You can proceed with opening a PR for the same. Thank you

wajeshubham avatar May 05 '24 09:05 wajeshubham