diff --git a/Cargo.toml b/Cargo.toml index 4ccde79..45ccd6a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,4 +9,4 @@ chrono = { version = "0.4", features = ["serde"] } serde = { version = "1.0", features = ["derive"] } serde_json = { version = "1.0" } icalendar = { version = "0.17", features = ["serde", "serde_json"] } -tokio = { version = "1.47.1", features = ["macros", "rt-multi-thread"] } \ No newline at end of file +tokio = { version = "1.47.1", features = ["macros", "rt-multi-thread"] } diff --git a/Containerfile b/Containerfile new file mode 100644 index 0000000..67b69b2 --- /dev/null +++ b/Containerfile @@ -0,0 +1,27 @@ +# Use a Rust base image with Cargo installed +FROM rust:1.90 AS builder +LABEL authors="Martin Berg Alstad" + +# Set the working directory inside the container +WORKDIR /usr/src/app + +# Now copy the source code +COPY Cargo.toml Cargo.lock ./ +COPY ./src ./src + +# Build your application +RUN cargo build --release + +# Start a new stage to create a smaller image without unnecessary build dependencies +FROM debian:trixie-slim + +# Set the working directory +WORKDIR /usr/src/app + +# Copy the built binary from the previous stage +COPY --from=builder /usr/src/app/target/release/recurring-event-api ./ + +EXPOSE 8000 + +# Command to run the application +ENTRYPOINT ["./recurring-event-api"] \ No newline at end of file diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..6bae3da --- /dev/null +++ b/compose.yaml @@ -0,0 +1,10 @@ +services: + recurring-event-api: + restart: unless-stopped + container_name: recurring-event-api + image: recurring-event-api + build: + dockerfile: Containerfile + context: . + ports: + - "8095:8000" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index be27c45..f403220 100644 --- a/src/main.rs +++ b/src/main.rs @@ -151,10 +151,13 @@ fn get_dates( #[tokio::main] async fn main() { + const PORT: &'static str = "8000"; let app = Router::new() .route("/", get(get_calendar)) .route("/ics", get(get_ics)); - let listener = tokio::net::TcpListener::bind("0.0.0.0:8000").await.unwrap(); + println!("Starting Application on port {PORT}"); + + let listener = tokio::net::TcpListener::bind(format!("0.0.0.0:{PORT}")).await.unwrap(); axum::serve(listener, app).await.unwrap(); }