From 93f4416e06e21251116b223de43112f1f875f74b Mon Sep 17 00:00:00 2001 From: MarcoIeni <11428655+MarcoIeni@users.noreply.github.com> Date: Tue, 3 Sep 2024 16:54:42 +0200 Subject: [PATCH] chore(docker): add healthcheck --- Dockerfile | 6 +++++- src/github/server.rs | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index e44010d..fdbe012 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,10 +29,14 @@ FROM ubuntu:22.04 as runtime WORKDIR / -RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y ca-certificates +# curl is needed for healthcheck +RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y ca-certificates curl COPY --from=build /app/target/release/bors . EXPOSE 80 +HEALTHCHECK --timeout=10s --start-period=10s \ + CMD curl -f http://localhost/health || exit 1 + ENTRYPOINT ["./bors"] diff --git a/src/github/server.rs b/src/github/server.rs index 9e508f0..69fa4ab 100644 --- a/src/github/server.rs +++ b/src/github/server.rs @@ -8,7 +8,7 @@ use anyhow::Error; use axum::extract::State; use axum::http::StatusCode; use axum::response::IntoResponse; -use axum::routing::post; +use axum::routing::{get, post}; use axum::Router; use octocrab::Octocrab; use std::future::Future; @@ -47,10 +47,15 @@ pub type ServerStateRef = Arc; pub fn create_app(state: ServerState) -> Router { Router::new() .route("/github", post(github_webhook_handler)) + .route("/health", get(health_handler)) .layer(ConcurrencyLimitLayer::new(100)) .with_state(Arc::new(state)) } +async fn health_handler() -> impl IntoResponse { + (StatusCode::OK, "") +} + /// Axum handler that receives a webhook and sends it to a webhook channel. pub async fn github_webhook_handler( State(state): State,