|
| 1 | +--- |
| 2 | +title: Developing with Catalyst |
| 3 | +icon: gear |
| 4 | +--- |
| 5 | + |
| 6 | +Developing Catalyst is currently supported on macOS and Linux. |
| 7 | + |
| 8 | +### Dependencies |
| 9 | + |
| 10 | +You'll need the following things installed locally: |
| 11 | + |
| 12 | +- Docker (or Podman 4.6.0+, which works even better) |
| 13 | +- Buildah (for `docker buildx`, included with Podman and Docker for Mac) |
| 14 | +- Go v1.20+ |
| 15 | +- Node.js v18+ (Studio development only) |
| 16 | +- Make |
| 17 | +- git |
| 18 | +- llvm (`brew install llvm` for compiling MistServer and go-livepeer on MacOS |
| 19 | + only) |
| 20 | + |
| 21 | +You'll first need to clone the Catalyst repo if you haven't already. |
| 22 | + |
| 23 | +```shell |
| 24 | +git clone https://github.com/livepeer/catalyst.git |
| 25 | +cd catalyst |
| 26 | +``` |
| 27 | + |
| 28 | +Then you'll need to download/build all the binaries that you'll need. |
| 29 | + |
| 30 | +```shell |
| 31 | +make # downloads all the external binaries & builds the local ones |
| 32 | +make box # builds the livepeer/in-a-box Docker image |
| 33 | +``` |
| 34 | + |
| 35 | +## Development |
| 36 | + |
| 37 | +Now you're ready to boot up your development environment! |
| 38 | + |
| 39 | +```shell |
| 40 | +make box-dev |
| 41 | +``` |
| 42 | + |
| 43 | +Lots and lots of logs will print out while all the dependencies finish booting |
| 44 | +up. After that, you'll now have a fully-functioning full-stack Livepeer Studio + |
| 45 | +Catalyst environment running locally! You can access it like so: |
| 46 | + |
| 47 | +- URL: [http://localhost:8888](http://localhost:8888) |
| 48 | + |
| 49 | +- Password: `livepeer` |
| 50 | + |
| 51 | +### Customizing the Environment |
| 52 | + |
| 53 | +If you need to add additional parameters to things running inside the box, you |
| 54 | +can create a `.env` file that contains key-value pairs: |
| 55 | + |
| 56 | +```shell |
| 57 | +echo "CATALYST_API_CDN_REDIRECT_PREFIX=https://externalcdn.livepeer.com/mist/" >> .env |
| 58 | +echo "CATALYST_API_CDN_REDIRECT_PLAYBACK_IDS=222222222222" >> .env |
| 59 | +``` |
| 60 | + |
| 61 | +Note that this mechanism is limited to adding new configuration; existing |
| 62 | +configuration cannot be modified this way. If you need to modify existing |
| 63 | +configuration you can manually change the file in `config/full-stack.json`. A |
| 64 | +more robust configuration management system is under development. |
| 65 | + |
| 66 | +### Making changes |
| 67 | + |
| 68 | +TLDR: Use a command like this and the Makefile will take care of it for you: |
| 69 | + |
| 70 | +```shell |
| 71 | +make livepeer-catalyst-api |
| 72 | +``` |
| 73 | + |
| 74 | +The general Livepeer in a Box development cycle works like this: |
| 75 | + |
| 76 | +1. Make changes to code on your local filesystem |
| 77 | +2. Build a Linux binary from that code |
| 78 | +3. Move that Linux binary into the `bin` directory of `catalyst`, which is |
| 79 | + mounted by `make box-dev` |
| 80 | +4. Kill the old version of your binary and allow MistController to bring it back |
| 81 | + up. |
| 82 | + |
| 83 | +Thankfully, this entire process has been automated. All you need to do is have |
| 84 | +the project you're working on cloned in a directory adjacent to `catalyst`. For |
| 85 | +example, if you're hacking on `task-runner`, you might have |
| 86 | + |
| 87 | +``` |
| 88 | +/home/user/code/catalyst |
| 89 | +/home/user/code/task-runner |
| 90 | +``` |
| 91 | + |
| 92 | +The catalyst Makefile is aware of the common paths for all of the other projects |
| 93 | +that go into the full stack. All that's necessary to build a new binary, package |
| 94 | +it in the container, and trigger a restart is a single command: |
| 95 | + |
| 96 | +```shell |
| 97 | +make livepeer-task-runner |
| 98 | +``` |
| 99 | + |
| 100 | +Note that the names of all subprojects are prefixed with `livepeer`, just like |
| 101 | +the resulting binaries within the Catalyst container. This yields the following |
| 102 | +commands: |
| 103 | + |
| 104 | +| Project | Command | |
| 105 | +| --------------------------- | --------------------------------- | |
| 106 | +| [catalyst-api] | `make livepeer-catalyst-api` | |
| 107 | +| [catalyst-uploader] | `make livepeer-catalyst-uploader` | |
| 108 | +| [task-runner] | `make livepeer-task-runner` | |
| 109 | +| [analyzer] | `make livepeer-analyzer` | |
| 110 | +| [Studio Node.js API Server] | `make livepeer-api` | |
| 111 | +| [MistServer] | `make mistserver` | |
| 112 | + |
| 113 | +[catalyst-api]: https://github.com/livepeer/catalyst-api |
| 114 | +[catalyst-uploader]: https://github.com/livepeer/catalyst-uploader |
| 115 | +[task-runner]: https://github.com/livepeer/catalyst-uploader |
| 116 | +[analyzer]: https://github.com/livepeer/livepeer-data |
| 117 | +[Studio Node.js API Server]: https://github.com/livepeer/studio |
| 118 | +[MistServer]: https://github.com/livepeer/mistserver |
| 119 | + |
| 120 | +### Connecting the Frontend |
| 121 | + |
| 122 | +Livepeer in a Box comes with a [pkg](https://github.com/vercel/pkg)-bundled |
| 123 | +version of the Livepeer Studio API server and frontend, but does not include a |
| 124 | +full development environment for that frontend. If you are making changes to the |
| 125 | +frontend, you can boot it up as you usually would: |
| 126 | + |
| 127 | +``` |
| 128 | +cd studio/packages/www |
| 129 | +yarn run dev |
| 130 | +``` |
| 131 | + |
| 132 | +To connect it to the box; there's a hidden `localStorage` variable you can use |
| 133 | +to override the API server URL. Open your browser console and type in the |
| 134 | +following: |
| 135 | + |
| 136 | +```javascript |
| 137 | +localStorage.setItem("LP_API_SERVER_OVERRIDE", "http://localhost:8888"); |
| 138 | +``` |
| 139 | + |
| 140 | +Reload the page and your frontend should be connecting to the box as an API |
| 141 | +server. |
| 142 | + |
| 143 | +Additional note: in the interest of build speed, `make livepeer-api` does not |
| 144 | +package the frontend within the `livepeer-api` binary that it builds, so if you |
| 145 | +experience your frontend suddenly 404ing after you run `make livepeer-api` you |
| 146 | +will have to use the above instructions to boot up the frontend on your host. |
| 147 | + |
| 148 | +You can also build the full API server with a bundled frontend using |
| 149 | +`make livepeer-api-pkg`, but be aware this frequently takes 3-4 minutes to |
| 150 | +complete. |
| 151 | + |
| 152 | +### Notes |
| 153 | + |
| 154 | +- Your CockroachDB (Postgres) database and your Minio (S3) object store will be |
| 155 | + saved in the `data` subdirectory of your Catalyst installation. If you want to |
| 156 | + start from scratch again with the `[email protected]` database snapshot, shut |
| 157 | + down your box and `rm -rf data`. |
| 158 | +- You can press `Ctrl+C` to trigger a graceful shutdown of the container. If |
| 159 | + you're impatient, following it up with a `Ctrl+\` can uncleanly shut things |
| 160 | + down a bit more cleanly. |
| 161 | +- Sometimes the rate of logs produced by Catalyst somehow overwhelms Make and |
| 162 | + log output simply stops. You'll know if you get in this state because you'll |
| 163 | + press Ctrl+C and control will return immediately to your terminal instead of |
| 164 | + shutting down the Docker image. You can start everything back up with |
| 165 | + `docker rm -f catalyst` and `make box-dev`. |
| 166 | + |
| 167 | +## Changelog |
| 168 | + |
| 169 | +### 2023-08-12 |
| 170 | + |
| 171 | +- Changed the hardcoded streams in the database snapshots to have |
| 172 | + easy-to-remember stream keys like `2222-2222-2222-2222` |
| 173 | +- Changed the built-in streams to use the H264ConstrainedHigh profile so there |
| 174 | + are no B-Frames in the output |
| 175 | +- Moved all references from `127.0.0.1` to `localhost`; this is needed for |
| 176 | + WebRTC/Coturn to work properly |
| 177 | +- Removed outdated references to `GOOS=linux` and `KILL=true`; these are the |
| 178 | + defaults now |
0 commit comments