Skip to content

Commit 828b3d2

Browse files
authored
feat: Build dockerfile (#88)
1 parent 8f53011 commit 828b3d2

2 files changed

Lines changed: 55 additions & 9 deletions

File tree

Dockerfile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# ---- Build stage ------------------------------------------------------------
2+
# Full Rust image to ensure C/C++ toolchains and proto deps are available.
3+
FROM rust:1.91 AS build
4+
5+
WORKDIR /app
6+
7+
# copy source
8+
# NOTE: if new modules are added to the Cargo workspaces, they must be added here.
9+
COPY Cargo.toml Cargo.lock ./
10+
COPY encoderfile ./encoderfile
11+
COPY encoderfile-core ./encoderfile-core
12+
13+
# Build flag used by the application.
14+
ENV ENCODERFILE_DEV=false
15+
16+
# Build release binary.
17+
RUN cargo build --bin encoderfile --release
18+
19+
20+
# ---- Final stage ------------------------------------------------------------
21+
# Final image must include the full Rust toolchain, since encoderfile
22+
# generates Rust code and performs on-the-fly cargo builds.
23+
FROM rust:1.91 AS final
24+
25+
# Default working directory.
26+
WORKDIR /data
27+
28+
# Install runtime dependencies.
29+
RUN apt-get update && \
30+
apt-get install -y --no-install-recommends \
31+
protobuf-compiler \
32+
ca-certificates && \
33+
rm -rf /var/lib/apt/lists/*
34+
35+
# Install binary into a standard PATH location.
36+
COPY --from=build /app/target/release/encoderfile /usr/local/bin/encoderfile
37+
38+
# Add documentation and license material.
39+
RUN mkdir -p /usr/share/docs/encoderfile
40+
COPY README.md THIRDPARTY.md LICENSE /usr/share/docs/encoderfile/
41+
42+
# Default command entry.
43+
ENTRYPOINT ["/usr/local/bin/encoderfile"]
44+
CMD ["--help"]

encoderfile/src/templates.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
use lazy_static::lazy_static;
22
use tera::Tera;
33

4+
const MAIN_RS: &str = include_str!("../templates/main.rs.tera");
5+
const CARGO_TOML: &str = include_str!("../templates/Cargo.toml.tera");
6+
47
lazy_static! {
58
pub static ref TEMPLATES: Tera = {
9+
let mut tera = Tera::default();
10+
11+
tera.add_raw_template("main.rs.tera", MAIN_RS)
12+
.expect("failed to load main.rs.tera");
13+
14+
tera.add_raw_template("Cargo.toml.tera", CARGO_TOML)
15+
.expect("failed to load Cargo.toml.tera");
616

7-
// tera.autoescape_on(vec![".html", ".sql"]);
8-
// tera.register_filter("do_nothing", do_nothing_filter);
9-
match Tera::new("encoderfile/templates/*") {
10-
Ok(t) => t,
11-
Err(e) => {
12-
println!("Parsing error(s): {}", e);
13-
::std::process::exit(1);
14-
}
15-
}
17+
tera
1618
};
1719
}

0 commit comments

Comments
 (0)