AryanAngiras31 commited on
Commit
86e87f9
·
1 Parent(s): 683a8cb

Change dockerfile and add dynamic port configuration for main.rs

Browse files
Files changed (2) hide show
  1. Dockerfile +5 -6
  2. src/main.rs +5 -3
Dockerfile CHANGED
@@ -1,5 +1,5 @@
1
  # Stage 1: Build the Rust binary
2
- FROM rust:1.75 AS builder
3
 
4
  WORKDIR /app
5
 
@@ -7,10 +7,9 @@ WORKDIR /app
7
  RUN apt-get update && apt-get install -y cmake clang libssl-dev pkg-config
8
 
9
  # Copy your source code
10
- COPY backend/Cargo.toml backend/Cargo.toml
11
- COPY backend/src backend/src
12
- # (If you have a Cargo.lock, copy it too)
13
- # COPY backend/Cargo.lock backend/Cargo.lock
14
 
15
  WORKDIR /app/backend
16
 
@@ -18,7 +17,7 @@ WORKDIR /app/backend
18
  RUN cargo build --release
19
 
20
  # Stage 2: Create the lightweight runtime image
21
- FROM debian:bookworm-slim
22
 
23
  WORKDIR /app
24
 
 
1
  # Stage 1: Build the Rust binary
2
+ FROM rust:latest AS builder
3
 
4
  WORKDIR /app
5
 
 
7
  RUN apt-get update && apt-get install -y cmake clang libssl-dev pkg-config
8
 
9
  # Copy your source code
10
+ COPY ./Cargo.toml backend/Cargo.toml
11
+ COPY ./src backend/src
12
+ COPY ./Cargo.lock backend/Cargo.lock
 
13
 
14
  WORKDIR /app/backend
15
 
 
17
  RUN cargo build --release
18
 
19
  # Stage 2: Create the lightweight runtime image
20
+ FROM ubuntu:24.04
21
 
22
  WORKDIR /app
23
 
src/main.rs CHANGED
@@ -314,7 +314,10 @@ async fn main() -> std::io::Result<()> {
314
  }
315
  };
316
 
317
- println!("Started Verity Rust API on 0.0.0.0:8080...");
 
 
 
318
 
319
  // 5. Start the HTTP Server
320
  HttpServer::new(move || {
@@ -331,8 +334,7 @@ async fn main() -> std::io::Result<()> {
331
  .app_data(app_state.clone())
332
  .service(verify_claim)
333
  })
334
- .workers(2) // Limit to 2 workers for development
335
- .bind(("0.0.0.0", 8080))?
336
  .run()
337
  .await
338
  }
 
314
  }
315
  };
316
 
317
+ // Dynamically get port
318
+ let port = std::env::var("PORT").unwrap_or_else(|_| "7860".to_string());
319
+ let bind_address = format!("0.0.0.0:{}", port);
320
+ println!("Started Verity Rust API on {}...", bind_address);
321
 
322
  // 5. Start the HTTP Server
323
  HttpServer::new(move || {
 
334
  .app_data(app_state.clone())
335
  .service(verify_claim)
336
  })
337
+ .bind(&bind_address)?
 
338
  .run()
339
  .await
340
  }