Skip to content

Commit

Permalink
Merge pull request #3 from johnbcodes/feature/rocket-instead
Browse files Browse the repository at this point in the history
Rocket instead
  • Loading branch information
johnbcodes authored Feb 8, 2024
2 parents 77a9643 + e7b4fe8 commit b926d7a
Show file tree
Hide file tree
Showing 28 changed files with 3,285 additions and 2,453 deletions.
1,337 changes: 759 additions & 578 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 3 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,17 @@ lto = true

[dependencies]
anyhow = "1.0"
axum = "0.7"
currency_rs = { git = "https://github.com/johnbcodes/currency_rs", branch = "feature/db-diesel2-sqlite", version = "1.1", features = [ "db-diesel2-sqlite" ] }
diesel = { version = "2.1", features = ["r2d2", "sqlite", "time"] }
diesel = { version = "2.1", features = ["sqlite", "time"] }
diesel_migrations = "2.1"
dotenvy = "0.15"
hotwire-turbo = "0.1"
hotwire-turbo-axum = "0.1"
itertools = "0.12"
libsqlite3-sys = { version = "0.27", features = ["bundled"] }
markup = "0.15"
mime_guess = "2"
once_cell = "1"
regex = "1"
rocket = "0.5"
rocket_sync_db_pools = { version = "0.1", features = ["diesel_sqlite_pool"]}
rust-embed = { version = "8", features = ["interpolate-folder-path"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
time = { version = "0.3", features = ["formatting", "macros", "parsing", "serde"] }
tokio = { version = "1", features = ["full"] }
tower-http = { version = "0.5", features = ["full"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
ulid = "1.1"
validator = { version = "0.16", features = ["derive"] }
10 changes: 6 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ RUN USER=root cargo new --bin app
WORKDIR /app

# copy over infrequently changing files
COPY package.json package-lock.json Cargo.lock Cargo.toml ./
# copy your source tree, ordered again by infrequent to frequently changed files
COPY tailwind.config.js ./
COPY build.rs ./
COPY Rocket.toml ./
COPY package.json package-lock.json Cargo.lock Cargo.toml ./
# copy your source tree, ordered again by infrequent to frequently changed files
COPY ./migrations ./migrations
COPY ./ui ./ui
COPY ./src ./src
Expand All @@ -38,7 +39,7 @@ RUN --mount=type=cache,target=/usr/local/cargo/registry \
## Deploy locally
FROM debug as dev

ENV DATABASE_URL=sqlite://data/demo.db
ENV ROCKET_PROFILE=docker

EXPOSE 8080

Expand All @@ -65,9 +66,10 @@ WORKDIR /

RUN mkdir data

COPY --from=release /app/Rocket.toml .
COPY --from=release /usr/local/cargo/bin/demo .

ENV DATABASE_URL=sqlite://data/demo.db
ENV ROCKET_PROFILE=docker

EXPOSE 8080

Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

> Rust implementation of the quote editor from [Turbo Rails Tutorial](https://www.hotrails.dev/turbo-rails).
### TODO
* Group queries in run block where possible

### Motivation and caveats

The main motivation is learning to develop web applications with Rust and JavaScript combined. It now includes
the following stack:

* [htmx](https://htmx.org/)
* [hyperscript](https://hyperscript.org/)
* [Axum](https://github.com/tokio-rs/axum)
* [Rocket](https://rocket.rs/)
* [Diesel](https://diesel.rs/)
* [markup.rs](https://github.com/utkarshkukreti/markup.rs)
* Custom Rust / NPM build integration
Expand All @@ -18,6 +21,7 @@ the following stack:
In the past it included these technologies:

* [Hotwire Turbo](https://turbo.hotwired.dev/)
* [Axum](https://github.com/tokio-rs/axum)
* [Rusqlite](https://github.com/rusqlite/rusqlite)

Some features of the tutorial were intentionally left out and possibly will be worked on in the future:
Expand All @@ -29,11 +33,9 @@ Additionally, there were some other features and integral parts of Rails that ha

* The look and feel deviates from [demo](https://www.hotrails.dev/quotes) because the author has made some UI enhancements that are not in the tutorial
* Viewports less than tablet sizing
* Proper validation error messages ("to_sentence" on ValidationErrors struct for flash message)
* Only add border color to fields with errors
* Labels for input fields
* Delete confirmation
* Probably a few others
* ...probably a few others

## Getting Started

Expand Down Expand Up @@ -62,7 +64,7 @@ Additionally, there were some other features and integral parts of Rails that ha

* Create volume with `docker volume create db-data`
* Build with `docker build -t rust-quote-editor .`
* Run with `docker run -itd -e "DATABASE_URL=sqlite:///data/demo.db" -p 8080:8080 -v db-data:/data rust-quote-editor`
* Run with `docker run -itd -p 8080:8080 -v db-data:/data rust-quote-editor`

#### Docker Compose

Expand All @@ -78,12 +80,11 @@ Additionally, there were some other features and integral parts of Rails that ha
* Update `primary_region` property in `fly.toml`
* `fly volumes create <VOLUME-NAME> -s 1 -r <REGION>`
* Update `mounts.source` property in `fly.toml` with <VOLUME-NAME>
* `fly secrets set DATABASE_URL=/data/demo.db`
* `docker build -t registry.fly.io/<GLOBALLY-UNIQUE-APP-NAME>:<VERSION-NUMBER> --target deploy .`
* `fly deploy --image registry.fly.io/<GLOBALLY-UNIQUE-APP-NAME>:<VERSION-NUMBER>`

## Automated deployment of new versions with GitHub [action](.github/workflows/deploy.yml)
* [Set up](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions) your `FLY_API_TOKEN` secret in your repository
* [Set up](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions) your `FLY_API_TOKEN` [secret](https://fly.io/docs/reference/deploy-tokens/) in your repository
* Tag release with a tag name starting with 'v'
* Example: `git tag -a v2 -m "My new release!" && git push --tags`

Expand Down
13 changes: 13 additions & 0 deletions Rocket.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[default]
log_level = "debug"

[default.databases.demo]
url = "data/demo.db"
timeout = 10

[docker]
address = "0.0.0.0"

[docker.databases.demo]
url = "/data/demo.db"
timeout = 10
4 changes: 1 addition & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ services:
web.app:
build:
target: dev
environment:
- DATABASE_URL=/data/demo.db
ports:
- "8080:8080"
- "8000:8000"
volumes:
- db-data:/data

Expand Down
6 changes: 3 additions & 3 deletions fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ kill_timeout = 5
PORT = "8080"

[mounts]
source = "jbc_ah_data"
source = "jbc_qe_data"
destination = "/data"

[[services]]
internal_port = 8080
internal_port = 8000
protocol = "tcp"

[services.concurrency]
Expand All @@ -31,6 +31,6 @@ port = 443
[[services.tcp_checks]]
grace_period = "1s"
interval = "15s"
port = "8080"
port = "8000"
restart_limit = 6
timeout = "2s"
Loading

0 comments on commit b926d7a

Please sign in to comment.