coder / envbuilder

Build development environments from a Dockerfile on Docker, Kubernetes, and OpenShift. Enable developers to modify their development environment quickly.
Apache License 2.0
111 stars 23 forks source link

coder/kaniko: support caching ENV and ARG directives #254

Closed johnstcn closed 27 minutes ago

johnstcn commented 2 weeks ago

Currently, when attempting to DoCacheProbe fails when encountering ENV directives:

#2: Using caching version of cmd: RUN cargo install exa bat ripgrep typos-cli watchexec-cli
#2: ENV CARGO_INSTALL_ROOT=/tmp/
error: get cached image: error probing build cache: uncached command *commands.EnvCommand encountered when probing cache

It looks like we need to implement the CachedExecuteCommand interface for both ENV and ARG commands:

To reproduce, here is a sample Dockerfile that fails to cache probe:

FROM alpine:latest
ENV FOO=hello
ARG BAR=world
RUN echo "$FOO $BAR" > /root/msg.txt

Alternatively, try to build the dogfood Dockerfile from coder/coder with ENVBUILDER_GET_CACHED_IMAGE=1 (assuming the image was previously built).

mafredri commented 4 days ago

As I was working on implementing tests for https://github.com/coder/kaniko/pull/17 to fix this issue, I noticed we have another issue with multi-stage builds. COPY directives in multi-stage builds (COPY --from=first /a /b) rely on extraction to get the file hash. It makes sense but throws a few wrenches in our approach. Tracking the file hash across stages seems like a non-trivial thing to do. Without extraction, I think we'd still need to read the tar of the first stage to figure out the hash of the file to be copied.