Skip to content

Commit

Permalink
fix: app to run even without sentry, replaced configs with configs ex…
Browse files Browse the repository at this point in the history
…amples, added RUN_MODE in dockerfiles
  • Loading branch information
yellowHatpro committed Sep 6, 2024
1 parent a597dbc commit 45df1f9
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 10 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ retry_interval = 120 # 2 min
allow_remove_row_after = 600 # 10 min

[sentry]
url = "https://[email protected].sentry.io/4507836627222528"
url = "your sentry DSN here"

[database]
pg_host = "localhost" # If running as a docker container, change this to musicbrainz-docker-db-1
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions docker/Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ RUN --mount=type=cache,target=/usr/local/cargo/registry \
cargo build --target x86_64-unknown-linux-gnu && \
cp ./target/x86_64-unknown-linux-gnu/debug/mb-ia /app/mb-ia

ENV RUN_MODE=development

# Set the working directory to /app and run the binary
CMD ["/app/mb-ia"]
3 changes: 3 additions & 0 deletions docker/Dockerfile.prod
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ WORKDIR /app
COPY --from=builder /mb-ia ./app

COPY --from=builder /app/config /app/config

ENV RUN_MODE=production

CMD ["/app/app"]

1 change: 1 addition & 0 deletions docs/INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
> - Make sure musicbrainz db and the required database tables are present.
> - Follow https://github.com/metabrainz/musicbrainz-docker to install the required containers and db dumps.
> - Rename the `.env.example` to `.env`, to set the `RUN_MODE` to `development`.
> - Rename `config/default.example.toml` to `config/default.toml`, `config/development.example.toml` to `config/development.toml` and `config/production.example.toml` to `config/production.toml`.
> - Ensure [yq](https://github.com/mikefarah/yq) is installed, for using configs in the sql scripts.
> - After ensuring musicbrainz_db is running on port 5432, Run the script `init_db.sh` in scripts dir.
> - In `config/development.toml` file, make sure to create a sentry rust project, enter your sentry project [DSN](https://docs.sentry.io/platforms/rust/#configure) (Data Source Name) in the `url` key's value. Make sure to not forget this step, else the program will panic.
Expand Down
27 changes: 18 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,23 @@ mod configuration;
mod metrics;

fn main() {
let settings = Settings::new().expect("Sentry Config not set");
let _guard = sentry::init((
settings.sentry.url,
sentry::ClientOptions {
release: sentry::release_name!(),
..Default::default()
},
));
let settings = Settings::new().expect("Failed to load settings");

let _guard = if !settings.sentry.url.trim().is_empty() {
println!("Initializing Sentry with DSN...");
Some(sentry::init((
settings.sentry.url.as_str(),
sentry::ClientOptions {
release: sentry::release_name!(),
..Default::default()
},
)))
} else {
println!("Sentry DSN is not provided, skipping Sentry initialization.");
None
};

// Initialize the Tokio runtime
tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
Expand All @@ -37,7 +46,7 @@ fn main() {
.max_connections(5)
.connect(&db_url)
.await
.unwrap();
.expect("Failed to connect to the database");

cli::start(&pool).await;
});
Expand Down

0 comments on commit 45df1f9

Please sign in to comment.