Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/manuelmauro/zero2prod
https://github.com/manuelmauro/zero2prod
Last synced: 7 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/manuelmauro/zero2prod
- Owner: manuelmauro
- Created: 2024-01-28T17:52:36.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-03-14T21:53:41.000Z (9 months ago)
- Last Synced: 2024-10-30T06:24:57.818Z (about 2 months ago)
- Language: Rust
- Size: 195 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Rust Backend Stack
## Setup
### Installing Rust and Cargo
Install Rust as described [here](https://doc.rust-lang.org/book/ch01-01-installation.html).
### Installing `sqlx-cli`
SQLx is an async, pure Rust SQL crate featuring compile-time checked queries without a DSL.
SQLx-CLI is SQLx's associated command-line utility for managing databases, migrations, and enabling "offline" mode with sqlx::query!() and friends.
It is published on the Cargo crates registry as `sqlx-cli` and can be installed like so:```shell
cargo install sqlx-cli --features postgres
```### Running Postgres
The following script will start the latest version of Postgres using [Docker], create the database and run the migrations.
```shell
./scripts/init_db.sh
```### Preparing SQLx data
There are 3 steps to building with "offline mode":
- Enable the SQLx's Cargo feature offline
- E.g. in your Cargo.toml, sqlx = { features = [ "offline", ... ] }
- Save query metadata for offline usage
- `cargo sqlx prepare`
- Build### Starting the Application
With everything else set up, all you need to do at this point is:
```shell
cargo run
```If successful, the API server is now listening at port 8080.
#### Hot Reload
Use [`cargo-watch`](https://crates.io/crates/cargo-watch) for hot reloading the server.
```bash
cargo watch -x run
```### Preparing Tailwind CSS
#### Install NodeJS using Volta
Follow the documentation [here](https://volta.sh/)
```bash
curl https://get.volta.sh | bash
```#### Install dependencies
```bash
npm run install
```#### Build the project's CSS
```bash
npx tailwindcss -i ./input.css -o ./assets/output.css --watch
```## Quality Assurance
### Testing
Run unit tests with:
```bash
cargo test
```### Formatting
Format with:
```bash
cargo fmt --check
```### Linting
Lint with:
```bash
cargo clippy -- -D warnings
```### Code Coverage
Check code coverage:
```bash
cargo tarpaulin --verbose --workspace
```## Deployment
### Dependencies
This application relies on Digital Ocean's [App Platform] for its CD pipeline.
Install Digital Ocean's CLI [doctl] to interact with platform.### First Deployment
To deploy a new instance of the application on Digital Ocean run:
```bash
doctl apps create --spec spec.yaml
```then migrate the production database with:
```bash
DATABASE_URL= sqlx migrate run
```## License
Licensed under MIT license. Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, shall be licensed as above, without any additional terms or conditions.
[Docker]: https://www.docker.com/
[App Platform]: https://docs.digitalocean.com/products/app-platform/
[doctl]: https://docs.digitalocean.com/reference/doctl/how-to/install/