You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This document lists the contribution guidelines for all of Shuttle's repositories.
4
+
For a guide on how to run the Shuttle Core stack (this repo), see [DEVELOPING.md](./DEVELOPING.md).
2
5
3
6
## Tenets
4
7
@@ -13,288 +16,21 @@ We will strive to adhere to the following tenets:
13
16
14
17
## Raise an Issue
15
18
16
-
Raising [issues](https://github.com/shuttle-hq/shuttle/issues) is encouraged.
19
+
Raising issues is encouraged. Please find the appropriate repository in the [repository list](./README.md).
17
20
18
21
## Docs
19
22
20
23
If you found an error in our docs, or you simply want to make them better, contributions to our [docs](https://github.com/shuttle-hq/shuttle-docs)
21
24
are always appreciated!
22
25
23
-
## Running Locally
24
-
25
-
You can use Docker and docker-compose to test Shuttle locally during development. See the [Docker install](https://docs.docker.com/get-docker/)
26
-
and [docker-compose install](https://docs.docker.com/compose/install/) instructions if you do not have them installed already.
27
-
28
-
> Note for Windows: The current [Makefile](https://github.com/shuttle-hq/shuttle/blob/main/Makefile) does not work on Windows systems by itself - if you want to build the local environment on Windows you could use [Windows Subsystem for Linux](https://learn.microsoft.com/en-us/windows/wsl/install). Additional Windows considerations are listed at the bottom of this page.
29
-
> Note for Linux: When building on Linux systems, if the error unknown flag: --build-arg is received, install the docker-buildx package using the package management tool for your particular system.
> Note: We need the git tags for the local development workflow, but they may not be included when you clone the repository.
39
-
To make sure you have them, run `git fetch upstream --tags`, where upstream is the name of the Shuttle remote repository.
40
-
41
-
You should now be ready to setup a local environment to test code changes to core `shuttle` packages as follows:
42
-
43
-
From the root of the Shuttle repo, build the required images with:
44
-
45
-
```bash
46
-
USE_PANAMAX=disable make images
47
-
```
48
-
49
-
> Note: The stack uses [panamax](https://github.com/panamax-rs/panamax) by default to mirror crates.io content. We do this in order to avoid overloading upstream mirrors and hitting rate limits. After syncing the cache, expect to see the panamax volume take about 100GiB of space. This may not be desirable for local testing. To avoid using panamax, run `USE_PANAMAX=disable make images` instead.
50
-
51
-
The images get built with [cargo-chef](https://github.com/LukeMathWalker/cargo-chef) and therefore support incremental builds (most of the time). So they will be much faster to re-build after an incremental change in your code - should you wish to deploy it locally straight away.
52
-
53
-
You can now start a local deployment of Shuttle and the required containers with:
54
-
55
-
```bash
56
-
USE_PANAMAX=disable make up
57
-
```
58
-
59
-
> Note: `make up` does not start [panamax](https://github.com/panamax-rs/panamax) by default, if you do need to start panamax for local development, run this command with `make COMPOSE_PROFILES=panamax up`.
60
-
61
-
> Note: `make up` can also be run with `SHUTTLE_DETACH=disable`, which means docker-compose will not be run with `--detach`. This is often desirable for local testing.
62
-
63
-
> Note: `make up` can also be run with `HONEYCOMB_API_KEY=<api_key>` if you have a honeycomb.io account and want to test the instrumentation of the services. This is mostly used only by the internal team.
64
-
65
-
> Note: Other useful commands can be found within the [Makefile](https://github.com/shuttle-hq/shuttle/blob/main/Makefile).
66
-
67
-
The API is now accessible on `localhost:8000` (for app proxies) and `localhost:8001` (for the control plane). When running `cargo run --bin cargo-shuttle` (in a debug build), the CLI will point itself to `localhost` for its API calls.
68
-
69
-
In order to test local changes to the library crates, you may want to add the below to a `.cargo/config.toml` file. (See [Overriding Dependencies](https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html) for more)
The [shuttle examples](https://github.com/shuttle-hq/shuttle-examples) are linked to the main repo as a [git submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules), to initialize it run the following commands:
120
-
121
-
```bash
122
-
git submodule init
123
-
git submodule update
124
-
```
125
-
126
-
Then `cd` into any example:
127
-
128
-
```bash
129
-
cd examples/rocket/hello-world/
130
-
```
131
-
132
-
Create a new project, this will prompt your local instance of the gateway to
133
-
start a deployer container:
134
-
135
-
```bash
136
-
# the --manifest-path is used to locate the root of the Shuttle workspace
137
-
cargo run --manifest-path ../../../Cargo.toml --bin cargo-shuttle -- project start
138
-
```
139
-
140
-
Deploy the example:
141
-
142
-
```bash
143
-
cargo run --manifest-path ../../../Cargo.toml --bin cargo-shuttle -- deploy
144
-
```
145
-
146
-
Test if the deployment is working:
147
-
148
-
```bash
149
-
# the Host header should match the Host from the deploy output
# append `--follow` to this command for a live feed of logs
157
-
cargo run --manifest-path ../../../Cargo.toml --bin cargo-shuttle -- logs
158
-
```
159
-
160
-
### Testing deployer only
161
-
162
-
The steps outlined above starts all the services used by Shuttle locally (ie. both `gateway` and `deployer`). However, sometimes you will want to quickly test changes to `deployer` only. To do this replace `make up` with the following:
163
-
164
-
```bash
165
-
# if you didn't do this already, make the images
166
-
USE_PANAMAX=disable make images
167
-
168
-
# then generate the local docker-compose file
169
-
make docker-compose.rendered.yml
170
-
171
-
# then run it
172
-
docker compose -f docker-compose.rendered.yml up provisioner
173
-
```
174
-
175
-
This starts the provisioner and the auth service, while preventing `gateway` from starting up.
176
-
Next up we need to insert an admin user into the `auth` state using the ID of the `auth`
The `<project_name>` needs to match the name of the project that will be deployed to this deployer. This is the `Cargo.toml` or `Shuttle.toml` name for the project.
204
-
205
-
Now that your local deployer is running, you can run commands against using the cargo-shuttle CLI.
206
-
To do that you should navigate into an example, it needs to have the same project name as the
207
-
one you submitted when starting the deployer above. Then you can use the CLI like you normally
208
-
would:
209
-
210
-
```bash
211
-
# the manifest path is the path to the root Shuttle manifest from the example directory
212
-
cargo run --bin cargo-shuttle --manifest-path="../../../Cargo.toml" -- deploy
213
-
```
214
-
215
-
### Using Podman instead of Docker
216
-
217
-
If you want to use Podman instead of Docker, you can configure the build process with environment variables.
218
-
219
-
Use Podman for building container images by setting `DOCKER_BUILD`.
220
-
221
-
```sh
222
-
export DOCKER_BUILD=podman build --network host
223
-
```
224
-
225
-
The Shuttle containers expect access to a Docker-compatible API over a socket. Expose a rootless Podman socket either
226
-
227
-
-[with systemd](https://github.com/containers/podman/tree/main/contrib/systemd), if your system supports it,
228
-
229
-
```sh
230
-
systemctl start --user podman.service
231
-
```
232
-
233
-
- or by [running the server directly](https://docs.podman.io/en/latest/markdown/podman-system-service.1.html).
234
-
235
-
```sh
236
-
podman system service --time=0 unix://$XDG_RUNTIME_DIR/podman.sock
237
-
```
238
-
239
-
Then set`DOCKER_SOCK` to the *absolute path* of the socket (no protocol prefix).
240
-
241
-
```sh
242
-
export DOCKER_SOCK=$(podman system info -f "{{.Host.RemoteSocket.Path}}")
243
-
```
244
-
245
-
Finally, configure Docker Compose. You can either
246
-
247
-
- configure Docker Compose to use the Podman socket by setting `DOCKER_HOST` (including the `unix://` protocol prefix),
248
-
249
-
```sh
250
-
export DOCKER_HOST=unix://$(podman system info -f "{{.Host.RemoteSocket.Path}}")
251
-
```
252
-
253
-
- or install [Podman Compose](https://github.com/containers/podman-compose) and use it by setting `DOCKER_COMPOSE`.
254
-
255
-
```sh
256
-
export DOCKER_COMPOSE=podman-compose
257
-
```
258
-
259
-
If you are using `nftables`, even with `iptables-nft`, it may be necessary to install and configure the [nftables CNI plugins](https://github.com/greenpau/cni-plugins)
260
-
261
-
## Running Tests
262
-
263
-
Shuttle has reasonable test coverage - and we are working on improving this
264
-
every day. We encourage PRs to come with tests. If you're not sure about
265
-
what a test should look like, feel free to [get in touch](https://discord.gg/shuttle).
266
-
267
-
To run the unit tests for a specific crate, from the root of the repository run:
268
-
269
-
```bash
270
-
# replace <crate-name> with the name of the crate to test, e.g. `shuttle-common`
271
-
cargo test --package <crate-name> --all-features --lib -- --nocapture
272
-
```
273
-
274
-
To run the integration tests for a specific crate (if it has any), from the root of the repository run:
275
-
276
-
```bash
277
-
# replace <crate-name> with the name of the crate to test, e.g. `cargo-shuttle`
278
-
cargo test --package <crate-name> --all-features --test '*' -- --nocapture
279
-
```
280
-
281
-
To run the end-to-end tests, from the root of the repository run:
282
-
283
-
```bash
284
-
USE_PANAMAX=disable make test
285
-
```
286
-
287
-
> Note: Running all the end-to-end tests may take a long time, so it is recommended to run individual tests shipped as part of each crate in the workspace first.
288
-
289
26
## Committing
290
27
291
28
We use the [Angular Commit Guidelines](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#commit). We expect all commits to conform to these guidelines.
292
29
293
-
Before committing:
30
+
Before committing in Rust repositories:
294
31
295
-
- Make sure your commits don't trigger any warnings from Clippy by running: `cargo clippy --tests --all-targets`. If you have a good reason to contradict Clippy, insert an `#[allow(clippy::<lint>)]` macro, so that it won't complain.
32
+
- Make sure your commits don't trigger any warnings from Clippy by running: `cargo clippy --tests --all-targets --all-features`. If you have a good reason to contradict Clippy, insert an `#[allow(clippy::<lint>)]` macro, so that it won't complain.
296
33
- Make sure your code is correctly formatted: `cargo fmt --all --check`.
297
-
- If you've made changes to examples, make sure the above commands are ran there as well.
298
34
299
35
## Opening a Pull Request
300
36
@@ -314,97 +50,3 @@ We will always strive to review pull requests as soon as we can, but during cert
314
50
review every pull request in a timely manner. This does not mean we are not excited about the contribution or that
315
51
there is anything wrong with it, we are grateful for every contribution and the time spent on them. If you feel that
316
52
your PR has gone under the radar for too long feel free to ping us and we'll try to get back to you with an update.
317
-
318
-
## Project Layout
319
-
320
-
The folders in this repository relate to each other as follow:
cargo-shuttle --->|"features = ['builder']"| service
348
-
deployer -->|"features = ['builder']"| service
349
-
cargo-shuttle --> common
350
-
service --> codegen
351
-
proto ---> common
352
-
provisioner --> proto
353
-
e2e -.->|starts up| gateway
354
-
e2e -.->|starts up| auth
355
-
e2e -.->|calls| cargo-shuttle
356
-
user -->|"features = ['codegen']"| service
357
-
```
358
-
359
-
### Binaries
360
-
361
-
- `cargo-shuttle` is the CLI used by users to initialize, deploy and manage their projects and services on Shuttle.
362
-
- `gateway` starts and manages instances of `deployer`. It proxies commands from the user sent via the CLI on port 8001 and traffic on port 8000 to the correct instance of `deployer`.
363
-
- `auth` is an authentication service that creates and manages users. In addition to that, requests to the `gateway` that contain an api-key or cookie will be proxied to the `auth` service where it will be converted to a JWT for authorization between internal services (like a `deployer` requesting a database from
364
-
`provisioner`).
365
-
- `deployer` is a service that runs in its own docker container, one per user project. It manages a project's deployments and state.
366
-
- `provisioner` is a service used for requesting databases and other resources, using a gRPC API.
367
-
- `admin` is a simple CLI used for admin tasks like reviving and stopping projects, as well as requesting
368
-
and renewing SSL certificates through the acme client in the `gateway`.
369
-
370
-
### Libraries
371
-
372
-
- `common` contains shared models and functions used by the other libraries and binaries.
373
-
- `codegen` contains our proc-macro code which gets exposed to user services from `runtime`.
374
-
The redirect through `runtime` is to make it available under the prettier name of `shuttle_runtime::main`.
375
-
- `runtime` contains the `alpha` runtime, which embeds a gRPC server and a `Loader` in a service with the `shuttle_runtime::main` macro.
376
-
The gRPC server receives commands from `deployer` like `start` and `stop`.
377
-
The `Loader` sets up a tracing subscriber and provisions resources for the users service.
378
-
The `runtime` crate also contains the `shuttle-next` binary, which is a standalone runtime binary that is started by the `deployer` or the `cargo-shuttle` CLI, responsible for loading and starting `shuttle-next` services.
379
-
- `service` is where our special `Service` trait is defined.
380
-
Anything implementing this `Service` can be loaded by the `deployer` and the local runner in `cargo-shuttle`.
381
-
The `service` library also defines the `ResourceBuilder` and `Factory` trais which are used in our codegen to provision resources.
382
-
The `service` library also contains the utilities we use for compiling users crates with `cargo`.
383
-
- `proto` contains the gRPC server and client definitions to allow `deployer` to communicate with `provisioner`, and to allow the `deployer` and `cargo-shuttle` cli to communicate with the `alpha` and `shuttle-next` runtimes.
384
-
- `resources` contains various implementations of `ResourceBuilder`, which are consumed in the `codegen` to provision resources.
385
-
- `services` contains implementations of `Service` for common Rust web frameworks. Anything implementing `Service` can be deployed by shuttle.
386
-
- `e2e` just contains tests which starts up the `deployer` in a container and then deploys services to it using `cargo-shuttle`.
387
-
388
-
Lastly, the `user service` is not a folder in this repository, but is the user service that will be deployed by `deployer`.
389
-
390
-
## Windows Considerations
391
-
392
-
Currently, if you try to use 'make images' on Windows, you may find that the shell files cannot be read by Bash/WSL. This is due to the fact that Windows may have pulled the files in CRLF format rather than LF[^1], which causes problems with Bash as to run the commands, Linux needs the file in LF format.
393
-
394
-
Thankfully, we can fix this problem by simply using the `git config core.autocrlf` command to change how Git handles line endings. It takes a single argument:
395
-
396
-
```bash
397
-
git config --global core.autocrlf input
398
-
```
399
-
400
-
This should allow you to run `make images` and other Make commands with no issues.
401
-
402
-
If you need to change it back for whatever reason, you can just change the last argument from 'input' to 'true' like so:
403
-
404
-
```bash
405
-
git config --global core.autocrlf true
406
-
```
407
-
408
-
After you run this command, you should be able to checkout projects that are maintained using CRLF (Windows) again.
0 commit comments