Skip to content

Commit bb49c2d

Browse files
committed
updated dockerfile to base image to red hat ubi, renamed binary to regex-detector
1 parent b94a4a7 commit bb49c2d

File tree

5 files changed

+64
-37
lines changed

5 files changed

+64
-37
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "local-detectors"
2+
name = "regex-detector"
33
version = "0.1.0"
44
edition = "2021"
55

@@ -14,5 +14,5 @@ tracing = "0.1.41"
1414
tracing-subscriber = "0.3.19"
1515

1616
[[bin]]
17-
name = "local-detectors"
17+
name = "regex-detector"
1818
path = "src/main.rs"

Dockerfile

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,45 @@
1-
# Use the official Rust image as a base
2-
FROM rust:latest
1+
ARG UBI_MINIMAL_BASE_IMAGE=registry.access.redhat.com/ubi9/ubi-minimal
2+
ARG UBI_BASE_IMAGE_TAG=latest
3+
4+
## Rust builder ################################################################
5+
# Specific debian version so that compatible glibc version is used
6+
FROM rust:1.84.0-bullseye AS rust-builder
37

4-
# Set the working directory to /app
58
WORKDIR /app
69

7-
# Copy the Cargo.toml file into the working directory
8-
COPY Cargo.toml .
10+
COPY rust-toolchain.toml rust-toolchain.toml
11+
12+
RUN rustup component add rustfmt
13+
14+
## Regex builder #########################################################
15+
FROM rust-builder AS regex-detector-builder
916

17+
COPY *.toml /app/
1018
COPY src/ /app/src/
1119

12-
# Build the Rust application
13-
RUN cargo build --release
20+
WORKDIR /app
21+
22+
RUN cargo install --root /app/ --path .
23+
24+
## Tests stage ##################################################################
25+
FROM regex-detector-builder AS tests
26+
RUN cargo test
27+
28+
## Lint stage ###################################################################
29+
FROM regex-detector-builder AS lint
30+
RUN cargo clippy --all-targets --all-features -- -D warnings
31+
32+
## Formatting check stage #######################################################
33+
FROM regex-detector-builder AS format
34+
RUN cargo fmt --check
35+
36+
## Release Image ################################################################
37+
38+
FROM ${UBI_MINIMAL_BASE_IMAGE}:${UBI_BASE_IMAGE_TAG} AS regex-detector-release
1439

15-
# Copy the built application into the working directory
16-
COPY target/release/* .
40+
COPY --from=regex-detector-builder /app/bin/ /app/bin/
1741

18-
# Expose the port that the application will listen on
19-
EXPOSE 8080
42+
RUN microdnf install -y --disableplugin=subscription-manager shadow-utils compat-openssl11 && \
43+
microdnf clean all --disableplugin=subscription-manager
2044

21-
# Run the command to start the application when the container is launched
22-
CMD ["/app/local-detectors"]
45+
CMD ["/app/bin/regex-detector"]

rust-toolchain.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[toolchain]
2+
channel = "1.84.0"
3+
components = ["rustfmt", "clippy"]

src/main.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
use std::{env, net::{SocketAddr, IpAddr}};
21
use axum::{
32
routing::{get, post},
43
Router,
54
};
5+
use std::{
6+
env,
7+
net::{IpAddr, SocketAddr},
8+
};
69
use tower_http::trace::{self, TraceLayer};
710
use tracing::Level;
811
mod detectors;
@@ -14,8 +17,7 @@ async fn main() {
1417
.with_target(false)
1518
.compact()
1619
.init();
17-
18-
// Get port from environment variable or use default
20+
1921
let mut http_port = 8080;
2022
if let Ok(port) = env::var("HTTP_PORT") {
2123
match port.parse::<u16>() {
@@ -24,9 +26,8 @@ async fn main() {
2426
}
2527
}
2628

27-
// Get host from environment variable or use default
2829
let host = env::var("HOST").unwrap_or_else(|_| "0.0.0.0".to_string());
29-
30+
3031
let app = Router::new()
3132
.route("/health", get(|| async { "Hello, World!" }))
3233
.route("/api/v1/text/contents", post(handle_text_contents))
@@ -38,8 +39,8 @@ async fn main() {
3839

3940
let ip: IpAddr = host.parse().expect("Failed to parse host IP address");
4041
let addr = SocketAddr::from((ip, http_port));
41-
42+
4243
tracing::info!("listening on {}", addr);
4344
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
4445
axum::serve(listener, app).await.unwrap();
45-
}
46+
}

0 commit comments

Comments
 (0)