-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathDockerfile
55 lines (40 loc) · 1.57 KB
/
Dockerfile
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
###############################
# STEP 1: build rust executable
###############################
FROM rust:bookworm AS rustbuilder
# Create appuser
RUN adduser --no-create-home --disabled-password appuser
# Set workdir
WORKDIR /app
# Copy local dependencies
COPY . .
# Build the app using a dummy main in order to cache dependencies
RUN mv /app/mithril-relay /app/mithril-relay.1 && mkdir -p /app/mithril-relay/src
COPY mithril-relay/Cargo.toml /app/mithril-relay/
RUN echo "fn main () {}" > /app/mithril-relay/src/main.rs
RUN cargo build --release -p mithril-relay --manifest-path /app/mithril-relay/Cargo.toml
# Rollback the rest of the files into the container
RUN rm -rf /app/mithril-relay && mv /app/mithril-relay.1 /app/mithril-relay
COPY ./mithril-relay/src/main.rs /app/mithril-relay/src/
# Build the binary
RUN cargo build --release -p mithril-relay
RUN /app/target/release/mithril-relay --version
###############################
# STEP 2: build a small image
###############################
FROM debian:12-slim
# Upgrade
RUN apt-get update -y && apt-get install -y libssl-dev ca-certificates wget sqlite3 && rm -rf /var/lib/apt/lists/*
# Import the user and group files from the builder
COPY --from=rustbuilder /etc/passwd /etc/passwd
# Copy the executable
COPY --from=rustbuilder /app/target/release/mithril-relay /app/bin/mithril-relay
# Copy the config files
COPY --from=rustbuilder /app/mithril-relay/config /app/config
#Workdir
WORKDIR /app/
RUN chown -R appuser /app/
# Use an unprivileged user
USER appuser
# Run the executable
ENTRYPOINT ["/app/bin/mithril-relay", "-vvv"]