actix_web app doesn't boot outside of RustRover. #3450
-
actix web version 4.9.0 + 4.8.0 i use this dockerfile FROM lukemathwalker/cargo-chef:latest AS chef
WORKDIR /app
FROM chef AS planner
WORKDIR /app
COPY ./Cargo.toml ./Cargo.lock ./
COPY ./src ./src
COPY ./handlers ./handlers
COPY ./models ./models
COPY ./middleware ./middleware
COPY ./tools ./tools
RUN cargo chef prepare
FROM chef AS builder
WORKDIR /app
COPY --from=planner /app/src .
COPY --from=planner /app/tools /app/tools
COPY --from=planner /app/handlers /app/handlers
COPY --from=planner /app/models /app/models
COPY --from=planner /app/middleware /app/middleware
COPY --from=planner /app/recipe.json .
RUN cargo chef cook --release
RUN cargo build --release
RUN mv ./target/release/phq365 ./app
FROM debian:stable-slim AS final
RUN apt update -y
RUN apt install libssl-dev ca-certificates -y
RUN update-ca-certificates
WORKDIR /app
COPY --from=builder /app/app /usr/local/bin/
ENTRYPOINT ["/usr/local/bin/app"] build command used
then this is the main.rs extern crate middleware as mw;
use actix_web::{App, HttpResponse, HttpServer, middleware, web};
use actix_cors::Cors;
use actix_web_httpauth::middleware::HttpAuthentication;
use mw::jwt;
extern crate handlers;
#[actix_web::main] // or #[tokio::main]
async fn main() -> std::io::Result<()> {
println!("booting");
HttpServer::new(move || {
let cors = Cors::default()
.allowed_origin("http://localhost:3000") // Allow requests from any origin
.allowed_methods(vec!["GET", "POST"]) // Specify allowed HTTP methods
.allowed_headers(vec![
http::header::AUTHORIZATION,
http::header::ACCEPT,
http::header::CONTENT_TYPE,
]) // Specify allowed headers
.max_age(3600);
App::new()
.wrap(cors)
.wrap(middleware::Logger::default())
.service(handlers::misc::healthcheck)
.service(web::scope("/api")
.wrap(HttpAuthentication::bearer(jwt::validator))
.service(handlers::users::create)
.service(handlers::users::questionnaires)
.service(handlers::users::get_answers)
.service(handlers::questionnaires::create)
.service(handlers::questionnaires::get_all)
.service(handlers::questionnaires::uses)
.service(handlers::answered::label)
.service(handlers::answered::answer_question)
.service(handlers::questions::create)
.service(handlers::questions::get_all)
.service(handlers::questions::has_answer)
.service(handlers::answers::create)
.service(handlers::answers::get_all))
.service(web::scope("/admin")
.wrap(HttpAuthentication::bearer(jwt::validator))
.service(handlers::clinic::create)
.service(handlers::clinic::create_location)
.service(handlers::owner::create)
.service(handlers::owner::create_cc)
.service(handlers::owner::read_single))
.default_service(web::to(|| HttpResponse::NotFound()))
})
.bind(("0.0.0.0", 8080))?
.run()
.await.expect("TODO: panic message");
Ok(())
} however anytime i try to boot the docker container either via terminal using this command
or
the application just exits with code |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I can only guess that this is something wrong with cargo-chef or your setup with it because even if you remove everything related to Actix Web I still get the strange exit 0 with no output behavior as you describe. Sorry I can be of more help. Using this Dockerfile, without cargo-chef, and running it prints the "booting" log as we'd expect: FROM rust:1-bookworm AS builder
WORKDIR /app
COPY ./Cargo.toml ./Cargo.lock ./
COPY ./src ./src
RUN cargo build --release
RUN mv ./target/release/playground ./app
FROM debian:bookworm-slim AS final
WORKDIR /app
COPY --from=builder /app/app /usr/local/bin/
CMD ["/usr/local/bin/app"] |
Beta Was this translation helpful? Give feedback.
I can only guess that this is something wrong with cargo-chef or your setup with it because even if you remove everything related to Actix Web I still get the strange exit 0 with no output behavior as you describe. Sorry I can be of more help.
Using this Dockerfile, without cargo-chef, and running it prints the "booting" log as we'd expect: