-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathDockerfile
More file actions
55 lines (47 loc) · 1.51 KB
/
Dockerfile
File metadata and controls
55 lines (47 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#
# Build stage
#
FROM rust:1-slim-bookworm AS builder
ARG SKIP_TESTS=no
ENV BUILD_ARGS="--bin scrut --release"
RUN apt update && \
apt install -y build-essential && \
apt clean && \
rm -rf /var/lib/apt/lists/*
# Cache build dependencies separately
WORKDIR /app
RUN mkdir -p src/bin && \
printf 'extern crate scrut;\n\ninclude!(concat!(env!("OUT_DIR"), "/version.rs"));\n\nfn main() {}\n' > src/bin/main.rs && \
echo > src/lib.rs
COPY Cargo.toml build.rs .
RUN --mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/app/target \
cargo build $BUILD_ARGS --features volatile_tests && \
rm -rf target/release
# Build the binary
RUN rm -rf src/ build.rs Cargo.toml
COPY . .
RUN --mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/app/target \
cargo build $BUILD_ARGS && \
ls -lha target/release/ && \
cat src/bin/main.rs && \
cp -av target/release/scrut .
# Run tests (conditionally)
RUN --mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/app/target \
if [ "$SKIP_TESTS" != "yes" ]; then \
SCRUT_BIN="$(pwd)"/scrut make cargotest selftest; \
fi
#
# Run stage
#
FROM debian:bookworm-slim
# Copy previously build binary
WORKDIR /app
COPY --from=builder /app/scrut /usr/local/bin
# Run the container to run scrut
ENTRYPOINT ["scrut"]