middlewarehq / middleware

✨ Open-source dev productivity platform for engineering teams ✨
https://middlewarehq.com
Apache License 2.0
395 stars 33 forks source link

Add pre-requisite checks for the CLI tool #338

Open adnanhashmi09 opened 1 month ago

adnanhashmi09 commented 1 month ago

Description:

Before running the docker-compose watch command to set up the development environment, we should add some pre-requisite checks to ensure that the necessary components are available and the required files exist. This will help catch potential issues early and provide a better user experience.

Pre-requisite Checks:

Implementation Steps:

  1. Identify the required ports for the development environment and add a check to ensure they are not already in use.
  2. Add a check to verify if the Docker daemon is running on the system.
  3. Add a check to ensure that the docker-compose.yml file exists in the project directory.
  4. Add a check to ensure that the Dockerfile.dev exists in the project directory.
  5. Display appropriate error messages or prompts if any of the pre-requisite checks fail.
  6. Proceed with the docker-compose watch command only if all pre-requisite checks pass.

Additional Considerations:

sidtohan commented 1 week ago

So regarding this issue, I'd like to confirm a few things:

  1. For the ports, I believe these are the only ones that are used (found in the dockerfile). Please let me know if I'm missing anything: image
  2. For checking if docker daemon is running, should we do it before we call the docker compose down command in dev.sh script itself? Because otherwise, we would get the error "Cannot connect to the Docker daemon at unix:///home/solo/.docker/desktop/docker.sock. Is the docker daemon running?", and then the script would proceed to run the yarn start command in the cli folder. I think that if we add the daemon check in the app.tsx file then this message would still appear and potentially be confusing.
adnanhashmi09 commented 1 week ago

For the ports, I believe these are the only ones that are used (found in the dockerfile). Please let me know if I'm missing anything: image

Well, these ports can be changed using the environment variables. The ports specified in the Dockerfile are the default values in case the ports are not specified in the environment variables. You would have to get the ports from the environment for each of the above service, ie, DB_PORT, REDIS_PORT, PORT, ANALYTICS_SERVER_PORT and SYNC_SERVER_PORT, and then check if these ports are available to be used.

For checking if docker daemon is running, should we do it before we call the docker compose down command in dev.sh script itself? Because otherwise, we would get the error "Cannot connect to the Docker daemon at unix:///home/solo/.docker/desktop/docker.sock. Is the docker daemon running?", and then the script would proceed to run the yarn start command in the cli folder. I think that if we add the daemon check in the app.tsx file then this message would still appear and potentially be confusing.

Oh! You are actually right about that. Good thinking! How about we move that to the cli itself, instead of running it inside the bash file. So what I mean is, we first do the pre-requisite checks that I have specified in the issue description and then do docker compose down in the cli. And then the cli proceeds to function the way it does. So we remove docker compose down from the bash script. Thank you @sidtohan for pointing this out.

Also, do remember you would have to make appropriate changes in the UI as well. When the pre-requisite checks are running display a spinner and when they are successful update those spinners to a check-mark or a cross. Something like below: image image

(PS: Please don't use the above screenshots as a design reference for the UI. That is just an example illustration)

sidtohan commented 1 week ago

Thanks for the help @adnanhashmi09 . I think I have more clarity on this now. Could I please be assigned this issue?

adnanhashmi09 commented 1 week ago

Sure :)