Skip to content

Commit f75b1d4

Browse files
committed
Add docker healtcheck
1 parent cc44f9f commit f75b1d4

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,13 @@ WORKDIR /usr/src/underpass-api
5151
COPY src ./src
5252

5353
CMD ["underpass-api", "serve"]
54+
55+
EXPOSE 9292
56+
57+
HEALTHCHECK \
58+
--start-interval=1s \
59+
--start-period=30s \
60+
--interval=30s \
61+
--timeout=20s \
62+
--retries=5 \
63+
CMD curl -f http://127.0.0.1:9292/up || exit 1

src/main_serve.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use axum::Router;
22
use axum::body::Body;
33
use axum::extract::Request;
4-
use axum::http::{Method, Uri};
4+
use axum::http::{Method, StatusCode, Uri};
55
use axum::middleware::Next;
66
use axum::response::Response;
77
use axum::routing::{get, post};
@@ -31,6 +31,14 @@ async fn uri_middleware(request: Request<Body>, next: Next) -> Response {
3131
response
3232
}
3333

34+
#[axum::debug_handler]
35+
pub async fn get_health_status() -> Response<Body> {
36+
Response::builder()
37+
.status(StatusCode::NO_CONTENT)
38+
.body(Body::empty())
39+
.unwrap()
40+
}
41+
3442
#[tokio::main]
3543
async fn serve_async() -> () {
3644
let dialect = BackendType::new(true).await;
@@ -59,6 +67,7 @@ async fn serve_async() -> () {
5967
);
6068

6169
let app = Router::new()
70+
.route("/up", get(get_health_status))
6271
.route("/interpreter", get(query_get))
6372
.route("/interpreter", post(query_post))
6473
.with_state(Arc::new(Mutex::new(Box::new(dialect))))

0 commit comments

Comments
 (0)