|
| 1 | +--- |
| 2 | +title: Dev environment setup |
| 3 | +date: 2024-12-07 |
| 4 | +draft: false |
| 5 | +cascade: |
| 6 | + type: docs |
| 7 | +--- |
| 8 | + |
| 9 | +This page details how to setup a development environment for Yeti so you can |
| 10 | +start contributing. |
| 11 | + |
| 12 | +## Clone the yeti-docker repo |
| 13 | + |
| 14 | +Like for production deployments, the Yeti development environment is based on |
| 15 | +Docker. The `yeti-docker` repository contains all the necessary files to build |
| 16 | +the Docker images and run the containers. |
| 17 | + |
| 18 | +```bash |
| 19 | +git clone https://github.com/yeti-platform/yeti-docker |
| 20 | +cd yeti-docker |
| 21 | +``` |
| 22 | + |
| 23 | +Further instructions are available in the repo's |
| 24 | +[README](https://github.com/yeti-platform/yeti-docker/blob/main/dev/README.md). |
| 25 | + |
| 26 | +## Run the `init.sh` script |
| 27 | + |
| 28 | +```bash |
| 29 | +cd dev |
| 30 | +./init.sh |
| 31 | +``` |
| 32 | + |
| 33 | +This will clone the frontend and the backend repos to your local filesystem, and |
| 34 | +start the dev Docker containers that you need. |
| 35 | + |
| 36 | +## Spin up some terminals |
| 37 | + |
| 38 | +We recommend using a terminal multiplexer like `tmux` or `screen` to manage the |
| 39 | +multiple terminals you'll need to run the frontend and backend servers. |
| 40 | + |
| 41 | +You're going to run a couple of commands in different terminals: |
| 42 | + |
| 43 | +### API server |
| 44 | + |
| 45 | +This is the main Yeti backend server. We'll set it up to auto-reload whenever |
| 46 | +changes are made to the Python code. |
| 47 | + |
| 48 | +```bash |
| 49 | +docker compose exec api poetry run uvicorn core.web.webapp:app --reload --host 0.0.0.0 |
| 50 | +``` |
| 51 | + |
| 52 | +### Frontend server |
| 53 | + |
| 54 | +Even if you're not going to work on the frontend, you'll need to run the server |
| 55 | +to render the main Yeti web UI. |
| 56 | + |
| 57 | +```bash |
| 58 | +docker compose exec frontend npm run dev |
| 59 | +``` |
| 60 | + |
| 61 | +### Celery workers |
| 62 | + |
| 63 | +Celery is the task queue used by Yeti. If you plan to develop new feeds, |
| 64 | +analyzers, or other background tasks, you'll need to run the Celery workers. |
| 65 | + |
| 66 | +```bash |
| 67 | +docker compose exec -it api poetry run celery -A core.taskscheduler worker --loglevel=INFO --purge -B -P threads |
| 68 | +``` |
| 69 | + |
| 70 | +{{< callout type="warning" >}} **While the API server picks up changes to the |
| 71 | +code automatically, any changes to the Celery worker or task code has to be |
| 72 | +reloaded manually** {{< /callout >}} |
| 73 | + |
| 74 | +### Events tasks |
| 75 | + |
| 76 | +If you wanna work with events tasks, you need to run one or several events |
| 77 | +consumers. |
| 78 | + |
| 79 | +```bash |
| 80 | +docker compose exec -it api poetry run python -m core.events.consumers events |
| 81 | +``` |
| 82 | + |
| 83 | +{{< callout type="warning" >}} **While the API server picks up changes to the |
| 84 | +code automatically, any changes to the Celery worker or task code has to be |
| 85 | +reloaded manually** {{< /callout >}} |
| 86 | + |
| 87 | +You can adjust concurrency with `--concurrency <number_of_worker>` and enable |
| 88 | +debugging output with `--debug`. |
| 89 | + |
| 90 | +## Start hacking! |
| 91 | + |
| 92 | +The docker containers use volumes to read your local directory so you can make |
| 93 | +changes to the code locally, with your favorite editor, and see them reflected |
| 94 | +in the running containers. |
| 95 | + |
| 96 | +If you kill the containers, the code changes will still exist on your local |
| 97 | +filesystem, and re-creating them will pick up where you left off. |
0 commit comments