Skip to content

Commit cfe64c6

Browse files
committed
Add Docker Support
1 parent 808bd32 commit cfe64c6

File tree

5 files changed

+62
-0
lines changed

5 files changed

+62
-0
lines changed

Cargo.lock

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ repository = "https://github.com/SIMULATAN/ErrorServer"
88

99
[dependencies]
1010
regex = "1.7.0"
11+
signal-hook = "0.3.14"

Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM rust:alpine as builder
2+
3+
WORKDIR /app
4+
5+
RUN rustup toolchain install nightly
6+
7+
COPY Cargo.toml Cargo.lock ./
8+
COPY src ./src
9+
10+
RUN cargo +nightly build --release -Z sparse-registry
11+
12+
FROM alpine
13+
14+
WORKDIR /app
15+
16+
COPY error.html .
17+
COPY --from=builder /app/target/release/ErrorServer .
18+
19+
ENTRYPOINT [ "/app/ErrorServer" ]

src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ use regex::Regex;
55
use crate::http_codes::get_code;
66

77
mod http_codes;
8+
mod signals;
89

910
fn main() {
11+
signals::setup();
1012
let listener = TcpListener::bind("0.0.0.0:7878").unwrap();
1113
println!("Listening on :7878");
1214
let regex: Regex = Regex::new(r"GET /(.*) HTTP/\d.\d").unwrap();

src/signals.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use std::thread;
2+
use signal_hook::consts::{SIGINT, SIGTERM};
3+
use signal_hook::iterator::Signals;
4+
5+
pub fn setup() {
6+
let mut signals = Signals::new(&[SIGINT, SIGTERM]).unwrap();
7+
8+
thread::spawn(move || {
9+
for sig in signals.forever() {
10+
println!("Received signal {:?}", sig);
11+
std::process::exit(0);
12+
}
13+
});
14+
}

0 commit comments

Comments
 (0)