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

Optimizes docker layer #337

Merged
merged 4 commits into from
Mar 16, 2022
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
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
.github
.gitignore
.gitlab-ci.yml
.rustfmt.toml
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignoring everything and the un-ignoring things that are actually needed for build is typically a more productive approach than block-listing

**/.maintain*
**/target*
**/*.rs.bk
*.iml
Expand Down
21 changes: 1 addition & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ WORKDIR /build

ARG FEATURES=default

COPY ./nodes /build/nodes
COPY ./pallets /build/pallets
COPY ./runtimes /build/runtimes
COPY ./support /build/support
COPY ./Cargo.lock /build/Cargo.lock
COPY ./Cargo.toml /build/Cargo.toml
Comment on lines -11 to -16
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither new nor old are great. If there is any layer caching at all, Cargo.toml and Cargo.lock should be copied first, dependencies installed (those don't change often) and then the rest of the code should be copied and the project itself compiled. This way code changes don't result in rebuilding of everything.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tip! We had dependency caching in our Dockerfile a while ago but experienced some issues. In the end there where some compile errors because of the dependency caching. This and the not so huge improvement by the cache lead us to remove the caching again. Last time we where hoping that cargo-wharf would solve the caching, but it looks like no development was done in 2y.

COPY . .

RUN cargo build --locked --release --features $FEATURES

Expand All @@ -24,20 +19,6 @@ LABEL description="This is the 2nd stage: a very small image where we copy the k

ARG NODE_TYPE=kilt-parachain

# install tools and dependencies
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get upgrade -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
libssl1.1 \
ca-certificates \
curl && \
# apt cleanup
apt-get autoremove -y && \
apt-get clean && \
find /var/lib/apt/lists/ -type f -not -name lock -delete

COPY ./LICENSE /build/LICENSE
COPY ./README.md /build/README.md
COPY --from=builder /build/target/release/$NODE_TYPE /usr/local/bin/node-executable

RUN useradd -m -u 1000 -U -s /bin/sh -d /node node && \
Expand Down