forked from hasura/graphql-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
73 lines (56 loc) · 1.68 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 should match the Rust version in rust-toolchain.yaml and the other Dockerfiles.
FROM rust:1.80.0 as chef
WORKDIR app
ENV DEBIAN_FRONTEND=noninteractive
RUN set -ex;\
apt-get update; \
apt-get install --no-install-recommends --assume-yes \
curl git jq pkg-config ssh \
libssl-dev lld protobuf-compiler
# Set up a directory to store Cargo files.
ENV CARGO_HOME=/app/.cargo
ENV PATH="$PATH:$CARGO_HOME/bin"
# Switch to `lld` as the linker.
ENV RUSTFLAGS="-C link-arg=-fuse-ld=lld"
# Building with build.rs requires the Git context to be available across volumes.
ENV GIT_DISCOVERY_ACROSS_FILESYSTEM=1
# Install Rust tools.
COPY rust-toolchain.toml .
RUN rustup show
RUN cargo install cargo-chef
###
# Plan recipe
FROM chef AS planner
# Copy files
COPY .cargo ./.cargo
COPY Cargo.toml Cargo.lock ./
COPY crates ./crates
# Prepare the recipe
RUN cargo chef prepare --recipe-path recipe.json
###
# Build recipe
FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json
COPY --from=planner /app/.cargo/config.toml /app/.cargo/config.toml
# Build dependencies - this is the caching Docker layer!
RUN cargo chef cook --release --all-targets --recipe-path recipe.json
###
# Builds the application
FROM builder AS built
# Copy files
COPY .cargo ./.cargo
COPY Cargo.toml Cargo.lock ./
COPY crates ./crates
COPY .git ./.git
# Build the app
RUN cargo build --release --all-targets
###
# Ship the app in an image with `curl` and very little else
FROM ubuntu:jammy
# Install `curl` for health checks
RUN set -ex; \
apt-get update; \
apt-get install --assume-yes curl
# Install the engine
COPY --from=built /app/target/release/engine /usr/local/bin
ENTRYPOINT ["engine"]