monkeytype icon indicating copy to clipboard operation
monkeytype copied to clipboard

chore: allow docker compose to start the backend server (plbstl)

Open plbstl opened this issue 1 year ago • 5 comments

Description

The Backend section of the Advanced Contribution Guide isn't entirely true. You cannot use docker compose up to start the backend server. The command only starts redis and mongodb services, while having to manually run one of the dev scripts to start the backend server.

This change makes sure that docker compose up in the backend folder also starts the server, making contributions to this project a bit more seamless.

I had to use a separate volume for the node_modules in the backend because of mismatch between where the bcrypt module is built (my PC - MacOS) and where it is being run (Docker - Linux). It creates an error that prevents the server from booting up.

services:
  #...
  api-server:
    #...
    volumes:
      #...
      - /monkeytype/backend/node_modules
    entrypoint: 'bash -c "cd /monkeytype/backend && npm install && npm run dev"'

Only the backend dependencies are installed and built in the Docker container. The script can be a bit more complicated to skip unnecessary npm installs, but this is also okay.

Checks

  • [x] Check if any open issues are related to this PR; if so, be sure to tag them below.
  • [x] Make sure the PR title follows the Conventional Commits standard. (https://www.conventionalcommits.org for more info)
  • [x] Make sure to include your GitHub username inside parentheses at the end of the PR title

plbstl avatar Feb 02 '24 17:02 plbstl

My one issue with this PR is that I personally use Docker to only host the databases, and then run the servers in node myself. Maybe we can have one file for just databases and one for databses and node server?

Miodec avatar Feb 05 '24 12:02 Miodec

Maybe we can have one file for just databases and one for databases and node server?

Yes, that can work. Maybe use the COMPOSE_FILE env var to determine the file to use

plbstl avatar Feb 06 '24 21:02 plbstl

We can't just use multiple files?

Miodec avatar Feb 09 '24 17:02 Miodec

Yes, we're using multiple files. The env var is not necessary but a nice to have. Now thinking about it, it may not even be needed

plbstl avatar Feb 15 '24 18:02 plbstl

Yes, we're using multiple files. The env var is not necessary but a nice to have. Now thinking about it, it may not even be needed

I mean multiple files for composing backend:

  • one that only runs the databasees
  • one that runs both databases and the api server

Miodec avatar Feb 15 '24 20:02 Miodec

This PR is stale. Please trigger a re-run of the PR check action.

github-actions[bot] avatar Feb 22 '24 20:02 github-actions[bot]

Maybe we can have one file for just databases and one for databases and node server?

Yes, that can work. Maybe use the COMPOSE_FILE env var to determine the file to use

Let me elaborate on what I meant by this.

There will be two docker-compose files in the backend. When someone wants to contribute and they run docker compose up, the env var will instruct docker on which file to use. So, there is a default file being used.

Yes, we're using multiple files. The env var is not necessary but a nice to have. Now thinking about it, it may not even be needed

We know by default, docker compose checks for docker-compose.yaml. So the default file that is supposed to be set in the COMPOSE_FILE env var can be named docker-compose.yaml, and the other one named something more specific which will be run with docker-compose -f <filename> up

plbstl avatar Feb 24 '24 16:02 plbstl

Maybe we can have one file for just databases and one for databases and node server?

Yes, that can work. Maybe use the COMPOSE_FILE env var to determine the file to use

Let me elaborate on what I meant by this.

There will be two docker-compose files in the backend. When someone wants to contribute and they run docker compose up, the env var will instruct docker on which file to use. So, there is a default file being used.

Yes, we're using multiple files. The env var is not necessary but a nice to have. Now thinking about it, it may not even be needed

We know by default, docker compose checks for docker-compose.yaml. So the default file that is supposed to be set in the COMPOSE_FILE env var can be named docker-compose.yaml, and the other one named something more specific which will be run with docker-compose -f <filename> up

In that case, i would move the compose files to a backend/docker and rename them to db-and-server and db-only. Then add npm run docker and npm run docker-db scripts.

Miodec avatar Feb 25 '24 10:02 Miodec