2022-03-14 11:09:16 +00:00
# Zero To Production In Rust
2020-08-23 10:34:29 +00:00
2022-09-23 10:58:14 +00:00
< div align = "center" > < a href = "https://zero2prod.com" target = "_blank" > < img src = "https://www.zero2prod.com/assets/img/zero2prod.png" width = "75%" / > < / a > < / div >
2020-09-27 16:13:25 +00:00
2020-10-14 07:59:08 +00:00
[Zero To Production In Rust ](https://zero2prod.com ) is an opinionated introduction to backend development using Rust.
2020-09-27 16:13:25 +00:00
2022-03-14 11:09:16 +00:00
This repository serves as supplementary material for [the book ](https://zero2prod.com/ ): it hosts several snapshots of the codebase for our email newsletter project as it evolves throughout the book.
2020-08-23 10:34:29 +00:00
2021-03-13 15:08:33 +00:00
## Chapter snapshots
2022-03-14 11:09:16 +00:00
The [`main` ](https://github.com/LukeMathWalker/zero-to-production ) branch shows the project at the end of the book.
2021-03-13 15:08:33 +00:00
2021-03-13 15:08:54 +00:00
You can browse the project at the end of previous chapters by switching to their dedicated branches:
2021-03-13 15:08:33 +00:00
- [Chapter 3, Part 0 ](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-03-part0 )
- [Chapter 3, Part 1 ](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-03-part1 )
- [Chapter 4 ](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-04 )
2022-03-14 11:09:16 +00:00
- [Chapter 5 ](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-05 )
- [Chapter 6, Part 0 ](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-06-part0 )
2021-03-13 15:08:33 +00:00
- [Chapter 6, Part 1 ](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-06-part1 )
- [Chapter 7, Part 0 ](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-07-part0 )
- [Chapter 7, Part 1 ](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-07-part1 )
- [Chapter 7, Part 2 ](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-07-part2 )
2022-03-14 11:09:16 +00:00
- [Chapter 8 ](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-08 )
2021-08-01 18:21:57 +00:00
- [Chapter 9 ](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-09 )
2022-03-14 11:09:16 +00:00
- [Chapter 10, Part 0 ](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-10-part0 )
- [Chapter 10, Part 1 ](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-10-part1 )
- [Chapter 10, Part 2 ](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-10-part2 )
- [Chapter 10, Part 3 ](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-10-part3 )
- [Chapter 11 ](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-11 )
2020-12-05 17:19:11 +00:00
2022-03-14 11:09:16 +00:00
## Pre-requisites
2020-12-05 17:19:11 +00:00
You'll need to install:
- [Rust ](https://www.rust-lang.org/tools/install )
- [Docker ](https://docs.docker.com/get-docker/ )
2022-03-14 11:09:16 +00:00
There are also some OS-specific requirements.
### Windows
```bash
cargo install -f cargo-binutils
rustup component add llvm-tools-preview
```
2022-05-26 11:56:46 +00:00
```
2022-10-01 13:40:13 +00:00
cargo install --version="~0.6" sqlx-cli --no-default-features --features rustls,postgres
2022-05-26 11:56:46 +00:00
```
2022-03-14 11:09:16 +00:00
### Linux
```bash
# Ubuntu
2022-05-26 11:56:46 +00:00
sudo apt-get install lld clang libssl-dev postgresql-client
2022-03-14 11:09:16 +00:00
# Arch
2022-05-26 11:56:46 +00:00
sudo pacman -S lld clang postgresql
```
```
2022-10-01 13:40:13 +00:00
cargo install --version="~0.6" sqlx-cli --no-default-features --features rustls,postgres
2022-03-14 11:09:16 +00:00
```
### MacOS
```bash
brew install michaeleisel/zld/zld
```
2022-05-26 11:56:46 +00:00
```
2022-10-01 13:40:13 +00:00
cargo install --version="~0.6" sqlx-cli --no-default-features --features rustls,postgres
2022-05-26 11:56:46 +00:00
```
2022-03-14 11:09:16 +00:00
## How to build
2020-12-05 17:19:11 +00:00
Launch a (migrated) Postgres database via Docker:
2020-08-23 10:34:29 +00:00
```bash
2020-12-05 17:19:11 +00:00
./scripts/init_db.sh
2020-08-23 10:34:29 +00:00
```
2020-12-05 17:19:11 +00:00
2022-03-14 11:09:16 +00:00
Launch a Redis instance via Docker:
2020-12-05 17:19:11 +00:00
2022-03-14 11:09:16 +00:00
```bash
./scripts/init_redis.sh
```
Launch `cargo` :
2020-12-05 17:19:11 +00:00
```bash
cargo build
```
2022-07-05 17:51:16 +00:00
You can now try with opening a browser on http://127.0.0.1:8000/login after
having launch the web server with `cargo run` .
There is a default `admin` account with password
`everythinghastostartsomewhere` . The available entrypoints are listed in
[src/startup.rs ](https://github.com/LukeMathWalker/zero-to-production/blob/6bd30650cb8670a146819a342ccefd3d73ed5085/src/startup.rs#L92 )
2021-01-10 16:30:20 +00:00
## How to test
2020-12-05 17:19:11 +00:00
2022-03-14 11:09:16 +00:00
Launch a (migrated) Postgres database via Docker:
2020-12-05 17:19:11 +00:00
2020-08-23 10:34:29 +00:00
```bash
2022-03-14 11:09:16 +00:00
./scripts/init_db.sh
2020-08-23 10:56:30 +00:00
```
2021-06-06 13:11:19 +00:00
2022-03-14 11:09:16 +00:00
Launch a Redis instance via Docker:
2021-06-06 13:11:19 +00:00
2022-03-14 11:09:16 +00:00
```bash
./scripts/init_redis.sh
```
2021-06-06 13:11:19 +00:00
2022-03-14 11:09:16 +00:00
Launch `cargo` :
2021-06-06 13:11:19 +00:00
2022-03-14 11:09:16 +00:00
```bash
cargo test
```