docker setup

This commit is contained in:
Robin Appelman 2020-11-15 17:28:50 +01:00
commit f7bd166df2
5 changed files with 47 additions and 3 deletions

2
.dockerignore Normal file
View file

@ -0,0 +1,2 @@
.env
target

23
Cargo.lock generated
View file

@ -176,6 +176,16 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634"
[[package]]
name = "ctrlc"
version = "3.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b57a92e9749e10f25a171adcebfafe72991d45e7ec2dcb853e8f83d9dafaeb08"
dependencies = [
"nix",
"winapi 0.3.9",
]
[[package]]
name = "dashmap"
version = "3.11.10"
@ -711,6 +721,18 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "nix"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83450fe6a6142ddd95fb064b746083fc4ef1705fe81f64a64e1d4b39f54a1055"
dependencies = [
"bitflags",
"cc",
"cfg-if 0.1.10",
"libc",
]
[[package]]
name = "num_cpus"
version = "1.13.0"
@ -1185,6 +1207,7 @@ dependencies = [
name = "taspromto"
version = "0.1.0"
dependencies = [
"ctrlc",
"dashmap",
"dotenv",
"json",

View file

@ -12,4 +12,5 @@ tokio = "0.2"
dashmap = "3.11"
json = "0.12.4"
warp = "0.2.5"
dotenv = "0.15.0"
dotenv = "0.15.0"
ctrlc = { version = "3.1.7", features = ["termination"] }

13
Dockerfile Normal file
View file

@ -0,0 +1,13 @@
FROM ekidd/rust-musl-builder AS build
ADD . ./
RUN sudo chown -R rust:rust .
RUN cargo build --release
FROM scratch
COPY --from=build /home/rust/src/target/x86_64-unknown-linux-musl/release/taspromto /
EXPOSE 80
CMD ["/taspromto"]

View file

@ -18,10 +18,15 @@ async fn main() {
let host_port = dotenv::var("PORT")
.ok()
.and_then(|port| u16::from_str(&port).ok())
.unwrap_or(3030);
.unwrap_or(80);
let device_states = DeviceStates::default();
ctrlc::set_handler(move || {
std::process::exit(0);
})
.expect("Error setting Ctrl-C handler");
tokio::task::spawn(mqtt_client(mqtt_host, mqtt_port, device_states.clone()));
let state = warp::any().map(move || device_states.clone());
@ -71,7 +76,7 @@ async fn main() {
response
});
warp::serve(metrics).run(([127, 0, 0, 1], host_port)).await;
warp::serve(metrics).run(([0, 0, 0, 0], host_port)).await;
}
async fn mqtt_client(host: String, port: u16, device_states: DeviceStates) {