Skip to content

Commit dcdebad

Browse files
authored
Merge 6f1dc71 into 9907f1e
2 parents 9907f1e + 6f1dc71 commit dcdebad

File tree

9 files changed

+29
-32
lines changed

9 files changed

+29
-32
lines changed

Cargo.lock

+1-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ axum = "0.6.20"
99
tower-http = { version = "0.4.0", features = ["cors","trace"] }
1010
tracing-subscriber = "0.3.17"
1111
chrono = { version = "0.4.23", features = ["serde"] }
12-
dotenv = "0.15.0"
1312
mongodb = { version = "2.3.1", features = ["bson-chrono-0_4"] }
1413
serde = { version = "1.0.152", features = ["derive"] }
1514
sqlx = {version="0.7.1", features = ["runtime-async-std-native-tls", "postgres", "uuid", "chrono"]}
@@ -24,6 +23,7 @@ tracing = "0.1.37"
2423
futures = { version = "0.3.25", default-features = false, features = ["async-await"] }
2524
hyper = {version="0.14.27", features = ["full"] }
2625
autometrics = { version = "0.6.0", features = ["prometheus-exporter"] }
26+
dotenvy = "0.15.7"
2727

2828
[dev-dependencies]
2929
mime = "0.3"

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,3 @@ curl -X DELETE http://localhost:8000/api/mongo/<id> -s | jq
8080

8181
- error handling using `thiserror`
8282
- implement tracing using opentelemetry
83-
- modify dependency loading with dotenv file rather than env vars

dev.env

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ME_CONFIG_MONGODB_ADMINUSERNAME=username
2+
ME_CONFIG_MONGODB_ADMINPASSWORD=password
3+
ME_CONFIG_MONGODB_SERVER=localhost
4+
MONGO_INITDB_DATABASE=rust_mongodb
5+
MONGODB_NOTE_COLLECTION=notes
6+
POSTGRES_USER=postgres
7+
POSTGRES_PASSWORD=postgres
8+
POSTGRES_DB=postgres
9+
POSTGRES_URL=postgres

docker-compose.yaml

+2-11
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,16 @@ services:
44
rust:
55
build:
66
context: .
7-
# dockerfile: Dockerfile
87
depends_on:
98
- mongodb
109
- liquibase
11-
# image: sample-python-container:latest
1210
ports:
1311
- 8000:8000
1412
restart: unless-stopped
1513
environment:
1614
- ENV=dev
17-
- ME_CONFIG_MONGODB_ADMINUSERNAME=username
18-
- ME_CONFIG_MONGODB_ADMINPASSWORD=password
19-
- ME_CONFIG_MONGODB_SERVER=mongodb
20-
- MONGO_INITDB_DATABASE=rust_mongodb
21-
- MONGODB_NOTE_COLLECTION=notes
22-
- POSTGRES_USER=postgres
23-
- POSTGRES_PASSWORD=postgres
24-
- POSTGRES_DB=postgres
25-
- POSTGRES_URL=postgres
15+
volumes:
16+
- ./dev.env:/.env
2617
liquibase:
2718
depends_on:
2819
- postgres

local.env

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ME_CONFIG_MONGODB_ADMINUSERNAME=username
2+
ME_CONFIG_MONGODB_ADMINPASSWORD=password
3+
ME_CONFIG_MONGODB_SERVER=localhost
4+
MONGO_INITDB_DATABASE=rust_mongodb
5+
MONGODB_NOTE_COLLECTION=notes
6+
POSTGRES_USER=postgres
7+
POSTGRES_PASSWORD=postgres
8+
POSTGRES_DB=postgres
9+
POSTGRES_URL=localhost

local.sh

-11
This file was deleted.

src/main.rs

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ mod schema;
1010
pub use self::error::{Error, Result};
1111

1212
use autometrics::prometheus_exporter;
13+
use dotenvy::dotenv;
1314
use mongo::MONGO;
1415
use pg::PG;
1516
use route::create_router;
@@ -23,6 +24,8 @@ async fn main() {
2324
if std::env::var_os("RUST_LOG").is_none() {
2425
std::env::set_var("RUST_LOG", "app=info,tower_http=trace");
2526
}
27+
dotenv().expect(".env file not found");
28+
2629
let pg = PG::init().await.unwrap();
2730
let mongo = MONGO::init().await.unwrap();
2831

@@ -78,6 +81,7 @@ mod tests {
7881
}
7982

8083
async fn api_call(method: Method, uri: &str, body: Body) -> (StatusCode, serde_json::Value) {
84+
dotenv().expect(".env file not found");
8185
let app = init().await;
8286
let response = app
8387
.oneshot(

test.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
source local.sh
2+
cp local.env .env
33
docker compose -f docker-compose-local.yaml up --force-recreate -V -d
44

55
sleep 5
@@ -8,4 +8,6 @@ cargo sqlx prepare --database-url "postgresql://postgres:postgres@localhost:5432
88

99
cargo test
1010

11+
rm .env
12+
1113
docker compose -f docker-compose-local.yaml down

0 commit comments

Comments
 (0)