Skip to content

Commit

Permalink
fix: ROCKET_ENV became ROCKET_PROFILE. production became release. apt…
Browse files Browse the repository at this point in the history
…-get became sudo apt-get. removed the atomic bool and concurrend ci deploy group. added rocket::Config::default()
  • Loading branch information
Tguntenaar committed Nov 8, 2024
1 parent 31000c5 commit 800975e
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
DATABASE_URL=
CONTRACT=devhub.near
ROCKET_DATABASES={devhub_cache_api_rs={url="postgres://devhub_cache_api_rs:password@localhost/devhub_cache_api_rs"}}
ROCKET_ENV=development
ROCKET_PROFILE=debug
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
components: clippy

- name: Install dependencies
run: apt-get update -y && apt-get install -y \
run: sudo apt-get update -y && sudo apt-get install -y \
libssl-dev \
ca-certificates \
libudev-dev \
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/fly-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ jobs:
deploy:
name: Deploy Devhub
runs-on: ubuntu-latest
concurrency: deploy-group # optional: ensure only one action runs at a time
steps:
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
Expand All @@ -24,7 +23,6 @@ jobs:
deploy-infra:
name: Deploy Infra
runs-on: ubuntu-latest
concurrency: deploy-group # optional: ensure only one action runs at a time
steps:
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
Expand All @@ -35,7 +33,6 @@ jobs:
deploy-events:
name: Deploy Events
runs-on: ubuntu-latest
concurrency: deploy-group # optional: ensure only one action runs at a time
steps:
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
Expand Down
11 changes: 7 additions & 4 deletions Rocket.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
[production]
[default]
address = "0.0.0.0"

[release]
address = "0.0.0.0"
port = 8080
workers = 2
workers = 1
log_level = "normal"


[development]
[debug]
address = "127.0.0.1"
port = 8080
workers = 2
workers = 1
log_level = "normal"
22 changes: 11 additions & 11 deletions fly.events.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ primary_region = 'ams'
[build]

[env]
CONTRACT = 'events-committee.near'
ROCKET_ENV = 'production'
CONTRACT = 'events-committee.near'
ROCKET_PROFILE = 'release'

[http_service]
internal_port = 8080
force_https = true
auto_stop_machines = 'stop'
auto_start_machines = true
min_machines_running = 0
processes = ['app']
internal_port = 8080
force_https = true
auto_stop_machines = 'stop'
auto_start_machines = true
min_machines_running = 0
processes = ['app']

[[vm]]
memory = '1gb'
cpu_kind = 'shared'
cpus = 1
memory = '1gb'
cpu_kind = 'shared'
cpus = 1
22 changes: 11 additions & 11 deletions fly.infra.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ primary_region = 'ams'
[build]

[env]
CONTRACT = 'infrastructure-committee.near'
ROCKET_ENV = 'production'
CONTRACT = 'infrastructure-committee.near'
ROCKET_PROFILE = 'release'

[http_service]
internal_port = 8080
force_https = true
auto_stop_machines = 'stop'
auto_start_machines = true
min_machines_running = 0
processes = ['app']
internal_port = 8080
force_https = true
auto_stop_machines = 'stop'
auto_start_machines = true
min_machines_running = 0
processes = ['app']

[[vm]]
memory = '1gb'
cpu_kind = 'shared'
cpus = 1
memory = '1gb'
cpu_kind = 'shared'
cpus = 1
2 changes: 1 addition & 1 deletion fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ cpu_kind = 'shared'
cpus = 1

[env]
ROCKET_ENV = "production"
ROCKET_PROFILE = "release"
CONTRACT = "devhub.near"
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ This repository leverages PostgreSQL as a caching layer to reduce DevHub's RPC c
## Develop

```sh
ROCKET_ENV=development cargo run
cargo run
```

or

```sh
ROCKET_ENV=development cargo watch -q -c -w src/ -x 'run '
cargo watch -q -c -w src/ -x 'run '
```

### SQLx Postgres
Expand Down
14 changes: 3 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pub fn timestamp_to_date_string(timestamp: i64) -> String {
use crate::entrypoints::ApiDoc;
use rocket::{catch, catchers, get, launch, routes};
use rocket_cors::AllowedOrigins;
use std::sync::Arc;
use types::Contract;
use utoipa::OpenApi;
use utoipa_swagger_ui::SwaggerUi;
Expand Down Expand Up @@ -66,7 +65,6 @@ pub struct Env {
#[launch]
fn rocket() -> _ {
dotenvy::dotenv().ok();
let atomic_bool = Arc::new(std::sync::atomic::AtomicBool::new(true));

let env: Env = envy::from_env::<Env>().expect("Failed to load environment variables");

Expand All @@ -89,21 +87,15 @@ fn rocket() -> _ {
.to_cors()
.expect("Failed to create cors config");

let figment = rocket::Config::figment().merge(("databases.my_db.url", env.database_url));
let figment = rocket::Config::figment()
.merge(rocket::Config::default())
.merge(("databases.my_db.url", env.database_url));

rocket::custom(figment)
.attach(cors)
.attach(db::stage())
.mount("/", routes![robots, index])
.attach(entrypoints::stage(env.contract))
.attach(rocket::fairing::AdHoc::on_shutdown(
"Stop loading users from Near and Github metadata",
|_| {
Box::pin(async move {
atomic_bool.store(false, std::sync::atomic::Ordering::Relaxed);
})
},
))
.mount(
"/",
SwaggerUi::new("/swagger-ui/<_..>").url("/api-docs/openapi.json", ApiDoc::openapi()),
Expand Down

0 comments on commit 800975e

Please sign in to comment.