Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

Commit 295a097

Browse files
author
Athos Couto
committed
Optimize runtime container layers
- Remove apt update, since it invalidate subsequent layers - Only copy sqld binary in the last step, since it changes the most - Copy ca-certificates.crt from builder image
1 parent 146df90 commit 295a097

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

Dockerfile

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
# build sqld
22
FROM rust:slim-bullseye AS chef
3-
RUN apt update \
4-
&& apt install -y libclang-dev clang \
5-
build-essential tcl protobuf-compiler file \
6-
libssl-dev pkg-config git\
7-
&& apt clean \
8-
&& cargo install cargo-chef
3+
4+
RUN apt update
5+
RUN apt install -y libclang-dev clang \
6+
build-essential tcl protobuf-compiler file \
7+
libssl-dev pkg-config git
8+
RUN apt clean
9+
910
# We need to install and set as default the toolchain specified in rust-toolchain.toml
1011
# Otherwise cargo-chef will build dependencies using wrong toolchain
1112
# This also prevents planner and builder steps from installing the toolchain over and over again
1213
COPY rust-toolchain.toml rust-toolchain.toml
13-
RUN cat rust-toolchain.toml | grep "channel" | awk '{print $3}' | sed 's/\"//g' > toolchain.txt \
14-
&& rustup update $(cat toolchain.txt) \
15-
&& rustup default $(cat toolchain.txt) \
16-
&& rm toolchain.txt rust-toolchain.toml
14+
RUN cat rust-toolchain.toml | grep "channel" | awk '{print $3}' | sed 's/\"//g' > toolchain.txt; \
15+
rustup update $(cat toolchain.txt); \
16+
rustup default $(cat toolchain.txt); \
17+
rm toolchain.txt rust-toolchain.toml;
18+
19+
RUN cargo install cargo-chef
1720

1821
FROM chef AS planner
1922
COPY . .
@@ -27,14 +30,19 @@ RUN cargo build -p sqld --release
2730

2831
# runtime
2932
FROM debian:bullseye-slim
30-
COPY --from=builder /target/release/sqld /bin/sqld
33+
34+
EXPOSE 5001 8080
35+
VOLUME [ "/var/lib/sqld" ]
36+
3137
RUN groupadd --system --gid 666 sqld
3238
RUN adduser --system --home /var/lib/sqld --uid 666 --gid 666 sqld
33-
RUN apt-get update && apt-get install -y ca-certificates
34-
COPY docker-entrypoint.sh /usr/local/bin
35-
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
36-
VOLUME [ "/var/lib/sqld" ]
3739
WORKDIR /var/lib/sqld
3840
USER sqld
39-
EXPOSE 5001 8080
41+
42+
COPY docker-entrypoint.sh /usr/local/bin
43+
44+
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
45+
COPY --from=builder /target/release/sqld /bin/sqld
46+
47+
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
4048
CMD ["/bin/sqld"]

0 commit comments

Comments
 (0)