-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
83 lines (61 loc) · 2.15 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
74
75
76
77
78
79
80
81
82
83
# Image containing dev dependencies
FROM rust:1.66.0-slim-bullseye AS tools
WORKDIR /build
# Remove the default, let the repo override choose its own
RUN rustup toolchain remove 1.66.0
RUN apt-get update -y && \
apt-get install -y \
cmake \
git \
jq \
protobuf-compiler \
&& \
rm -rf /var/lib/apt/lists/*
COPY rust-toolchain.toml ./
# Force rustup to install override toolchain
RUN rustc --version
# Skeleton image of the "best" initial commit
FROM tools AS skel-init
COPY .git .git/
COPY Cargo.lock ./
COPY scripts/checkout-init.sh scripts/install-skeleton.sh scripts/
RUN scripts/checkout-init.sh ../repo && scripts/install-skeleton.sh ../repo .
# Workspace skeleton image for cache coherence
FROM tools AS skel-fini
COPY scripts/install-skeleton.sh scripts/
COPY . ../repo
RUN scripts/install-skeleton.sh ../repo .
# Fat build image
FROM tools AS build
# Load INIT skeleton into a clean layer for caching against the manifests only
COPY --from=skel-init /build/Cargo.lock /build/Cargo.toml ./
COPY --from=skel-init /build/crates crates
# Perform an initial fetch and build of the INIT dependencies
RUN cargo fetch --locked
RUN cargo build --locked --profile=docker --bin the-q
# Load FINAL skeleton
COPY --from=skel-fini /build/Cargo.lock /build/Cargo.toml ./
COPY --from=skel-fini /build/crates crates
# Rebuild dependencies with current lockfile
RUN cargo fetch --locked
RUN cargo build --locked --profile=docker --bin the-q
# Load source code - source-only changes will begin building at this point
COPY scripts/install-skeleton.sh scripts/
COPY crates crates
# Skeleton has newer mtime than repo, touch all entrypoints to force rebuild
RUN scripts/install-skeleton.sh -t .
# Now perform a full build of the workspace
RUN cargo build --locked --profile=docker --bin the-q
# Base image for any output containers, to save space with common layers
FROM debian:bullseye-slim AS base
WORKDIR /opt/the-q
RUN apt-get update -y && \
apt-get install -y --no-install-recommends \
ffmpeg \
&& \
rm -rf /var/lib/apt/lists/*
COPY .env .env.prod ./
# Core bot image
FROM base AS bot
COPY --from=build /build/target/docker/the-q bin/
CMD ["bin/the-q"]