diff --git a/.Dockerignore b/.Dockerignore index 1112ef2..a8a3e47 100644 --- a/.Dockerignore +++ b/.Dockerignore @@ -1,5 +1,8 @@ -target +target/ .vscode -tests +tests/ .git -.gitignore \ No newline at end of file +.gitignore +.env +Dockerfile +migrations/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index e073c30..a20a22f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,21 @@ -FROM rust:1.56 +FROM rust:1.56-slim AS builder WORKDIR /app - COPY . . + ENV SQLX_OFFLINE true RUN cargo build --release +FROM debian:bullseye-slim AS runtime + +WORKDIR /app + +# Install dependancies required +RUN apt update -y && apt install -y --no-install-recommends openssl && apt autoremove -y && apt clean -y && rm -rf /var/lib/apt/lists/* + +# Copy the fully built binary and configuration to the image +COPY --from=builder /app/target/release/mail_app mail_app +COPY configuration configuration ENV APP_ENVIRONMENT production -ENTRYPOINT ["./target/release/mail_app"] \ No newline at end of file +ENTRYPOINT ["./mail_app"] \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 6a26967..bd71fe4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,10 @@ +use std::net::TcpListener; +use sqlx::PgPool; +use sqlx::postgres::PgPoolOptions; + use mail_app::startup::run; use mail_app::configuration::get_configuration; use mail_app::telemetry::{get_subscriber, init_subscriber}; -use std::net::TcpListener; -use sqlx::PgPool; #[actix_web::main] async fn main() -> std::io::Result<()> { @@ -13,7 +15,9 @@ async fn main() -> std::io::Result<()> { let configuration = get_configuration().expect("Failed to read configuration data."); // Configure connection to database for our startup - let connection_pool = PgPool::connect_lazy(&configuration.database.connection_string()) + let connection_pool = PgPool::new() + .connect_timeout(std::time::Duration::from_secs(2)) + .connect(&configuration.database.connection_string()) .expect("Failed to connect to Postgres."); // Take port from settings file diff --git a/src/startup.rs b/src/startup.rs index 485a885..40a03f9 100644 --- a/src/startup.rs +++ b/src/startup.rs @@ -1,6 +1,6 @@ use actix_web::{web, App, HttpServer}; use actix_web::dev::Server; -use actix_web::web::Data; +// use actix_web::web::Data; use std::net::TcpListener; use sqlx::PgPool; use tracing_actix_web::TracingLogger;