Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: refine the cache of the dockerfile layer to minimize build time AMAP #316

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions scripts/docker/ceseal/gramine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,30 @@ ARG BUILD=release
ARG OA
ARG VC

RUN : "${IAS_API_KEY:?IAS_API_KEY needs to be set and non-empty.}" \
&& : "${IAS_SPID:?IAS_SPID needs to be set and non-empty.}"

RUN mkdir ces-blockchain
ADD . ces-blockchain
RUN <<EOF
set -e
: "${IAS_API_KEY:?IAS_API_KEY needs to be set and non-empty.}"
: "${IAS_SPID:?IAS_SPID needs to be set and non-empty.}"
mkdir cess-code
EOF

COPY ./scripts/docker/cargo-config.toml /usr/local/cargo/config
COPY pallets ./cess-code/pallets
COPY crates ./cess-code/crates
COPY standalone ./cess-code/standalone
COPY Cargo.toml Cargo.lock rustfmt.toml rust-toolchain.toml Makefile ./cess-code/

RUN mkdir prebuilt

RUN cd ces-blockchain/standalone/teeworker/ceseal/gramine-build && \
PATH=$PATH:/root/.cargo/bin make dist PREFIX=/root/prebuilt && \
make clean && \
rm -rf /root/.cargo/registry && \
rm -rf /root/.cargo/git
RUN <<EOF
set -e
cd cess-code/standalone/teeworker/ceseal/gramine-build
PATH=$PATH:/root/.cargo/bin
make dist PREFIX=/root/prebuilt
make clean
rm -rf /root/.cargo/registry
rm -rf /root/.cargo/git
EOF

# ====== runtime ======

Expand Down
46 changes: 31 additions & 15 deletions scripts/docker/ceseal/gramine/handover.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,29 @@ ARG BUILD=release
ARG OA
ARG VC

RUN : "${IAS_API_KEY:?IAS_API_KEY needs to be set and non-empty.}" \
&& : "${IAS_SPID:?IAS_SPID needs to be set and non-empty.}" \
&& mkdir to_build_source \
&& mkdir prebuilt
ADD . to_build_source
RUN cd to_build_source/standalone/teeworker/ceseal/gramine-build && \
PATH=$PATH:/root/.cargo/bin make dist PREFIX=/root/prebuilt && \
make clean && \
rm -rf /root/.cargo/registry && \
rm -rf /root/.cargo/git
RUN <<EOF
set -e
: "${IAS_API_KEY:?IAS_API_KEY needs to be set and non-empty.}"
: "${IAS_SPID:?IAS_SPID needs to be set and non-empty.}"
mkdir cess-code
mkdir prebuilt
EOF

COPY ./scripts/docker/cargo-config.toml /usr/local/cargo/config
COPY pallets ./cess-code/pallets
COPY crates ./cess-code/crates
COPY standalone ./cess-code/standalone
COPY Cargo.toml Cargo.lock rustfmt.toml rust-toolchain.toml Makefile ./cess-code/

RUN <<EOF
set -e
cd cess-code/standalone/teeworker/ceseal/gramine-build
PATH=$PATH:/root/.cargo/bin
make dist PREFIX=/root/prebuilt
make clean
rm -rf /root/.cargo/registry
rm -rf /root/.cargo/git
EOF

# ====== runtime ======

Expand All @@ -42,11 +55,14 @@ ADD --chmod=0755 ./scripts/docker/ceseal/gramine/start.sh ${CESEAL_DIR}/start.sh
ADD --chmod=0755 ./scripts/docker/ceseal/gramine/start-with-handover.sh ${CESEAL_HOME}/start.sh
ADD ./scripts/docker/ceseal/gramine/handover.ts ${CESEAL_HOME}/handover.ts

RUN ln -s ${CESEAL_DIR} ${CESEAL_HOME}/releases/current \
&& mkdir -p ${REAL_CESEAL_DATA_DIR} \
&& rm -rf ${CESEAL_DIR}/data \
&& ln -s ${REAL_CESEAL_DATA_DIR} ${CESEAL_DIR}/data \
&& deno cache --reload ${CESEAL_HOME}/handover.ts
RUN <<EOF
set -e
ln -s ${CESEAL_DIR} ${CESEAL_HOME}/releases/current
mkdir -p ${REAL_CESEAL_DATA_DIR}
rm -rf ${CESEAL_DIR}/data
ln -s ${REAL_CESEAL_DATA_DIR} ${CESEAL_DIR}/data
deno cache --reload ${CESEAL_HOME}/handover.ts
EOF

WORKDIR ${CESEAL_HOME}/releases/current

Expand Down
23 changes: 15 additions & 8 deletions scripts/docker/cifrost/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
FROM cesslab/rust-chef-protoc-env:latest as chef
WORKDIR /cifrost
WORKDIR /cess-code

FROM chef AS planner
ARG https_proxy
ARG http_proxy

COPY ./scripts/docker/cargo-config.toml /usr/local/cargo/config
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
COPY pallets pallets
COPY crates crates
COPY standalone standalone
COPY Cargo.toml Cargo.lock rustfmt.toml rust-toolchain.toml Makefile ./
RUN --mount=type=cache,target=/usr/local/cargo/registry cargo chef prepare --recipe-path recipe.json

## build Rust project use caching manner
FROM chef AS builder
Expand All @@ -18,21 +21,25 @@ ARG OA
ARG VC

COPY ./scripts/docker/cargo-config.toml /usr/local/cargo/config
COPY --from=planner /cifrost/recipe.json recipe.json
COPY --from=planner /cess-code/recipe.json recipe.json

# Build dependencies - this is the caching Docker layer!
RUN cargo chef cook --release --recipe-path recipe.json
RUN --mount=type=cache,target=/usr/local/cargo/registry cargo chef cook --release --recipe-path recipe.json

# Build application
COPY . .
COPY ./scripts/docker/cargo-config.toml /usr/local/cargo/config
COPY pallets pallets
COPY crates crates
COPY standalone standalone
COPY Cargo.toml Cargo.lock rustfmt.toml rust-toolchain.toml Makefile ./

RUN make cifrost
RUN --mount=type=cache,target=/usr/local/cargo/registry make cifrost

## We do not need the Rust toolchain to run the binary!
FROM ubuntu:20.04 AS runtime

WORKDIR /opt/cifrost

COPY --from=builder /cifrost/target/release/cifrost .
COPY --from=builder /cess-code/target/release/cifrost .

ENTRYPOINT ["./cifrost"]
20 changes: 13 additions & 7 deletions scripts/docker/node/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
FROM cesslab/rust-chef-protoc-env:latest as chef
WORKDIR /node
COPY ./scripts/docker/cargo-config.toml /usr/local/cargo/config

FROM chef AS planner
COPY ./scripts/docker/cargo-config.toml /usr/local/cargo/config
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

COPY pallets pallets
COPY crates crates
COPY standalone standalone
COPY Cargo.toml Cargo.lock rustfmt.toml rust-toolchain.toml Makefile ./

RUN --mount=type=cache,target=/usr/local/cargo/registry cargo chef prepare --recipe-path recipe.json

## build Rust project use caching manner
FROM chef AS builder
Expand All @@ -14,14 +19,15 @@ ARG BUILD=release
ARG OA
ARG VC

COPY ./scripts/docker/cargo-config.toml /usr/local/cargo/config
COPY --from=planner /node/recipe.json recipe.json

# Build dependencies - this is the caching Docker layer!
RUN cargo chef cook --release --recipe-path recipe.json
RUN --mount=type=cache,target=/usr/local/cargo/registry cargo chef cook --release --recipe-path recipe.json

# Build application
COPY . .
COPY pallets pallets
COPY crates crates
COPY standalone standalone
COPY Cargo.toml Cargo.lock rustfmt.toml rust-toolchain.toml Makefile ./

RUN make node

Expand Down
Loading