From 72c3ae5dbef960808a9820906af7f5852537427e Mon Sep 17 00:00:00 2001 From: Camerin Figueroa Date: Fri, 3 May 2024 00:41:26 +0000 Subject: [PATCH 1/3] Modified request-mirror to accept environment variables from docker which would override the .env vars --- src/lib.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ad04a98..c4ffa3a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,9 +23,17 @@ use schema::{ /// ``` pub fn establish_connection() -> PgConnection { - dotenv().ok(); + let key: &str = "DATABASE_URL"; + let database_url: String; + match env::var(key) { + Ok(val) => database_url = val, + Err(e) => { + dotenv().ok(); - let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set"); + database_url = env::var(key).expect("DATABASE_URL must be set"); + } + } + PgConnection::establish(&database_url) .unwrap_or_else(|_| panic!("Error connecting to {}", database_url)) } From 06503392851455cab7e1350367a27b0521c44082 Mon Sep 17 00:00:00 2001 From: Camerin Figueroa Date: Fri, 3 May 2024 00:46:49 +0000 Subject: [PATCH 2/3] Updated Docker compose and docker image to pass DATABASE_URL as environment var to Request Mirror --- .gitignore | 2 +- Dockerfile | 2 +- docker-compose.yml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 80dba80..2f5cb03 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ /target -.env.local \ No newline at end of file +export.sh \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index d3064ae..a8dfbcd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,4 +13,4 @@ COPY .env.docker /.env ENV ROCKET_ADDRESS=0.0.0.0 ENV ROCKET_ENV=production EXPOSE 8000 -ENTRYPOINT diesel migration run --migration-dir /migrations && request-mirror \ No newline at end of file +ENTRYPOINT diesel migration run --database-url $DATABASE_URL --migration-dir /migrations && request-mirror \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index c564ed6..c934e54 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,7 @@ services: image: postgres environment: - POSTGRES_USER=postgres - - POSTGRES_PASSWORD=password + - POSTGRES_PASSWORD=Password123 - POSTGRES_DB=request_mirror_db volumes: - db-data:/var/lib/postgresql/data @@ -21,7 +21,7 @@ services: ports: - 80:8000 environment: - - DATABASE_URL=postgres://postgres:password@postgres/request_mirror_db + - DATABASE_URL=postgres://postgres:Password123@postgres/request_mirror_db depends_on: postgres: condition: service_healthy From d81b07957cdbceb5e0af11ed930fa6a6a88bf93e Mon Sep 17 00:00:00 2001 From: Camerin Figueroa Date: Thu, 2 May 2024 22:20:26 -0400 Subject: [PATCH 3/3] Updated docker-compose.yml to use published docker image --- docker-compose.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index c934e54..11a9829 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: "3.8" - services: postgres: image: postgres @@ -14,10 +12,7 @@ services: healthcheck: test: ["CMD-SHELL", "pg_isready -U postgres -d request_mirror_db | grep 'accepting connections'"] request-mirror: - #image: request-mirror - build: &request_mirror_build - context: . - dockerfile: ./Dockerfile + image: raspberrypi99/request-mirror:latest ports: - 80:8000 environment: