Skip to content

Commit

Permalink
Pond: add healthcheck πŸ‘©πŸ½β€βš•οΈ (#112)
Browse files Browse the repository at this point in the history
* add healthcheck to container

* print version

* add ping route

* Update version

* mount route

* update docker-compose, add autoheal image

* Use depends_on
  • Loading branch information
Terkwood authored Jul 31, 2019
1 parent f201cab commit 23b1225
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
9 changes: 9 additions & 0 deletions cloud_images/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion cloud_images/pond/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pond"
version = "0.4.2"
version = "0.4.3"
authors = ["Terkwood <[email protected]>"]
edition = "2018"

Expand Down
4 changes: 3 additions & 1 deletion cloud_images/pond/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ 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/

# .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" ]
5 changes: 5 additions & 0 deletions cloud_images/pond/src/bin/pond.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 6 additions & 1 deletion cloud_images/pond/src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,16 @@ pub fn push_redis(data: Json<PushData>, conn: RedisDbConn, config: State<Config>
}
}

#[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();
}

Expand Down

0 comments on commit 23b1225

Please sign in to comment.