-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
60 lines (46 loc) · 1.96 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
# syntax=docker/dockerfile:1.12-labs
# The above line is so we can use can use heredocs in Dockerfiles. No more && and \!
# https://www.docker.com/blog/introduction-to-heredocs-in-dockerfiles/
FROM rust:latest AS build
RUN mkdir app
# We create a new lib and then use our own Cargo.toml
RUN cargo new --lib /app/lib
COPY lib/Cargo.toml /app/lib/
COPY lib/build.rs /app/lib/build.rs
# We do the same for our mcf cli
RUN cargo new /app/cli
COPY cli/Cargo.toml /app/cli/
# This step compiles only our dependencies and saves them in a layer. This is the most impactful time savings
# Note the use of --mount=type=cache. On subsequent runs, we'll have the crates already downloaded
WORKDIR /app/cli
RUN --mount=type=cache,target=/usr/local/cargo/registry cargo build
# Copy our sources
COPY ./cli /app/cli
COPY ./lib /app/lib
COPY ./integration /app/integration
# A bit of magic here!
# * We're mounting that cache again to use during the build, otherwise it's not present and we'll have to download those again - bad!
# * EOF syntax is neat but not without its drawbacks. We need to `set -e`, otherwise a failing command is going to continue on
# * Rust here is a bit fiddly, so we'll touch the files (even though we copied over them) to force a new build
RUN <<EOF
--mount=type=cache,target=/usr/local/cargo/registry
set -e
# update timestamps to force a new build
touch /app/lib/src/lib.rs /app/cli/src/main.rs
cargo build
EOF
FROM rust:latest AS runner
# Download cf cli
RUN <<EOF
curl -L "https://packages.cloudfoundry.org/stable?release=linux64-binary&version=v8&source=github" | tar -zx
mv cf8 /usr/bin
mv cf /usr/bin
EOF
# Copy and build integration
COPY --from=build /app/integration /integration
COPY ./entrypoint.sh /integration/entrypoint.sh
WORKDIR integration
RUN --mount=type=cache,target=/usr/local/cargo/registry cargo build
# Copy mcf binary into integration
COPY --from=build /app/cli/target/debug/mcf /integration/target/debug/mcf
ENTRYPOINT ["./entrypoint.sh"]