Set up dockerfile, and handle SIGINT signals
This commit is contained in:
parent
f78d762999
commit
65619653c6
2
api/.dockerignore
Normal file
2
api/.dockerignore
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
target
|
||||||
|
.env
|
||||||
4
api/Cargo.lock
generated
4
api/Cargo.lock
generated
|
|
@ -1122,7 +1122,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "google-cloud"
|
name = "google-cloud"
|
||||||
version = "0.2.1"
|
version = "0.2.1"
|
||||||
source = "git+https://github.com/GRA0007/google-cloud-rs.git#5b2c3d6dcde9e58528c90c0a3016f123104c5fe3"
|
source = "git+https://github.com/GRA0007/google-cloud-rs.git#4a2db92efd57a896e14d18877458c6ae43418aec"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"futures",
|
"futures",
|
||||||
|
|
@ -1144,7 +1144,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "google-cloud-derive"
|
name = "google-cloud-derive"
|
||||||
version = "0.2.1"
|
version = "0.2.1"
|
||||||
source = "git+https://github.com/GRA0007/google-cloud-rs.git#5b2c3d6dcde9e58528c90c0a3016f123104c5fe3"
|
source = "git+https://github.com/GRA0007/google-cloud-rs.git#4a2db92efd57a896e14d18877458c6ae43418aec"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"darling",
|
"darling",
|
||||||
"quote",
|
"quote",
|
||||||
|
|
|
||||||
31
api/Dockerfile
Normal file
31
api/Dockerfile
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
# This dockerfile builds the API and runs it on a minimal container with the Datastore adaptor
|
||||||
|
|
||||||
|
FROM rust:latest as builder
|
||||||
|
|
||||||
|
# Install CA Certs for Hyper
|
||||||
|
RUN apt-get install -y --no-install-recommends ca-certificates
|
||||||
|
RUN update-ca-certificates
|
||||||
|
|
||||||
|
WORKDIR /usr/src/app
|
||||||
|
COPY . .
|
||||||
|
# Will build and cache the binary and dependent crates in release mode
|
||||||
|
RUN --mount=type=cache,target=/usr/local/cargo,from=rust:latest,source=/usr/local/cargo \
|
||||||
|
--mount=type=cache,target=target \
|
||||||
|
cargo build --release --features datastore-adaptor && mv ./target/release/crabfit-api ./api
|
||||||
|
|
||||||
|
# Runtime image
|
||||||
|
FROM debian:bullseye-slim
|
||||||
|
|
||||||
|
# Run as "app" user
|
||||||
|
RUN useradd -ms /bin/bash app
|
||||||
|
|
||||||
|
USER app
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Get compiled binaries from builder's cargo install directory
|
||||||
|
COPY --from=builder /usr/src/app/api /app/api
|
||||||
|
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||||
|
|
||||||
|
# Run the app
|
||||||
|
EXPOSE 3000
|
||||||
|
CMD ./api
|
||||||
|
|
@ -89,7 +89,7 @@ async fn main() {
|
||||||
.layer(rate_limit)
|
.layer(rate_limit)
|
||||||
.layer(TraceLayer::new_for_http());
|
.layer(TraceLayer::new_for_http());
|
||||||
|
|
||||||
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
|
let addr = SocketAddr::from(([0, 0, 0, 0], 3000));
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"🦀 Crab Fit API listening at http://{} in {} mode",
|
"🦀 Crab Fit API listening at http://{} in {} mode",
|
||||||
|
|
@ -102,6 +102,11 @@ async fn main() {
|
||||||
);
|
);
|
||||||
Server::bind(&addr)
|
Server::bind(&addr)
|
||||||
.serve(app.into_make_service_with_connect_info::<SocketAddr>())
|
.serve(app.into_make_service_with_connect_info::<SocketAddr>())
|
||||||
|
.with_graceful_shutdown(async {
|
||||||
|
tokio::signal::ctrl_c()
|
||||||
|
.await
|
||||||
|
.expect("Failed to install Ctrl+C handler")
|
||||||
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue