From 23b1225a80a262cee5f4ef1b7f81e47740eb380b Mon Sep 17 00:00:00 2001 From: Terkwood <38859656+Terkwood@users.noreply.github.com> Date: Wed, 31 Jul 2019 17:45:51 -0400 Subject: [PATCH] =?UTF-8?q?Pond:=20add=20healthcheck=20=F0=9F=91=A9?= =?UTF-8?q?=F0=9F=8F=BD=E2=80=8D=E2=9A=95=EF=B8=8F=20(#112)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add healthcheck to container * print version * add ping route * Update version * mount route * update docker-compose, add autoheal image * Use depends_on --- cloud_images/docker-compose.yml | 9 +++++++++ cloud_images/pond/Cargo.toml | 2 +- cloud_images/pond/Dockerfile | 4 +++- cloud_images/pond/src/bin/pond.rs | 5 +++++ cloud_images/pond/src/web.rs | 7 ++++++- 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/cloud_images/docker-compose.yml b/cloud_images/docker-compose.yml index 5cdcba4b..76be975a 100644 --- a/cloud_images/docker-compose.yml +++ b/cloud_images/docker-compose.yml @@ -3,12 +3,21 @@ services: pond: image: "prawnalith/pond:latest" build: "pond/." + labels: + autoheal: "true" ports: - "443:8000" volumes: - "/var/volumes/pond:/data" depends_on: - "redis" + autoheal: + image: "willfarrell/autoheal" + volumes: + - "/var/run/docker.sock:/var/run/docker.sock" + restart: always + depends_on: + - pond redis: image: "redis" volumes: diff --git a/cloud_images/pond/Cargo.toml b/cloud_images/pond/Cargo.toml index 80fd0d8d..9ab276f8 100644 --- a/cloud_images/pond/Cargo.toml +++ b/cloud_images/pond/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pond" -version = "0.4.2" +version = "0.4.3" authors = ["Terkwood "] edition = "2018" diff --git a/cloud_images/pond/Dockerfile b/cloud_images/pond/Dockerfile index 412dd26f..e47892c6 100644 --- a/cloud_images/pond/Dockerfile +++ b/cloud_images/pond/Dockerfile @@ -23,7 +23,7 @@ RUN cargo build --release # Now, we need to build our _real_ Docker container, copying in `pond`. FROM alpine:latest -RUN apk --no-cache add ca-certificates +RUN apk --no-cache add ca-certificates curl COPY --from=builder \ /home/rust/src/target/x86_64-unknown-linux-musl/release/pond \ /usr/local/bin/ @@ -31,4 +31,6 @@ COPY --from=builder \ # .env, Rocket.toml, etc will be mounted here WORKDIR /data +HEALTHCHECK CMD curl --fail --insecure https://0.0.0.0:8000/ping || exit 1 + CMD [ "/usr/local/bin/pond" ] diff --git a/cloud_images/pond/src/bin/pond.rs b/cloud_images/pond/src/bin/pond.rs index 2cd6a9f7..e6d2de2e 100644 --- a/cloud_images/pond/src/bin/pond.rs +++ b/cloud_images/pond/src/bin/pond.rs @@ -8,7 +8,12 @@ use pond::web; use std::process; use std::thread; +const NAME: &'static str = env!("CARGO_PKG_NAME"); +const VERSION: &'static str = env!("CARGO_PKG_VERSION"); + fn main() { + println!("🔢 {:<8} {}", NAME, VERSION); + dotenv::dotenv().expect("Unable to load .env file"); let config = Config::new(); diff --git a/cloud_images/pond/src/web.rs b/cloud_images/pond/src/web.rs index 36ca5bda..021fb6d0 100644 --- a/cloud_images/pond/src/web.rs +++ b/cloud_images/pond/src/web.rs @@ -165,11 +165,16 @@ pub fn push_redis(data: Json, conn: RedisDbConn, config: State } } +#[get("/ping")] +pub fn ping() -> Status { + Status::NoContent +} + pub fn startup(config: Config) { rocket::ignite() .manage(config) .attach(RedisDbConn::fairing()) - .mount("/", routes![tanks, tanks_options, push_redis]) + .mount("/", routes![tanks, tanks_options, push_redis, ping]) .launch(); }