-
Notifications
You must be signed in to change notification settings - Fork 91
/
Dockerfile
73 lines (60 loc) · 2.17 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# This Dockerfile is composed of two steps: the first one builds the release
# binary, and then the binary is copied inside another, empty image.
#################
# Build image #
#################
FROM ubuntu:24.04 AS build
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
ca-certificates \
curl \
build-essential \
git \
pkg-config \
cmake \
libsqlite3-dev \
libssl-dev
# Install the currently pinned toolchain with rustup
RUN curl https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init >/tmp/rustup-init && \
chmod +x /tmp/rustup-init && \
/tmp/rustup-init -y --no-modify-path --default-toolchain nightly --profile minimal
ENV PATH=/root/.cargo/bin:$PATH
# Build the dependencies in a separate step to avoid rebuilding all of them
# every time the source code changes. This takes advantage of Docker's layer
# caching, and it works by copying the Cargo.{toml,lock} with dummy source code
# and doing a full build with it.
WORKDIR /source
COPY Cargo.lock Cargo.toml /source/
RUN mkdir -p /source/src && \
echo "fn main() {}" > /source/src/main.rs && \
echo "fn main() {}" > /source/build.rs
RUN cargo fetch
RUN cargo build --release
# Dependencies are now cached, copy the actual source code and do another full
# build. The touch on all the .rs files is needed, otherwise cargo assumes the
# source code didn't change thanks to mtime weirdness.
RUN rm -rf /source/src /source/build.rs
COPY src /source/src
COPY build.rs /source/build.rs
COPY assets /source/assets
COPY templates /source/templates
COPY .git /source/.git
RUN find /source -name "*.rs" -exec touch {} \; && cargo build --release
##################
# Output image #
##################
FROM ubuntu:24.04 AS binary
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
docker.io \
build-essential \
pkg-config \
libssl-dev \
ca-certificates \
tini
RUN mkdir /workspace
ENV CRATER_WORK_DIR=/workspace
ENV CRATER_INSIDE_DOCKER=1
RUN mkdir /crater
COPY config.toml /crater/config.toml
WORKDIR /crater
COPY --from=build /source/target/release/crater /usr/local/bin/
ENTRYPOINT ["tini", "--", "crater"]