Skip to content

Commit

Permalink
Use a deterministic target path for feature dir mounts with useBuildC…
Browse files Browse the repository at this point in the history
…ontexts

This avoids caching issues when using the Dockerfile produced in
useBuildContexts mode. See
#205 (comment) for
context.
  • Loading branch information
aaronlehmann committed Jun 24, 2024
1 parent 7ebdf44 commit 8e3f287
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 4 additions & 4 deletions devcontainer/devcontainer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ FROM localhost:5000/envbuilder-test-codercom-code-server:latest
USER root
# Rust tomato - Example description!
WORKDIR `+featureOneDir+`
WORKDIR /envbuilder_features/one
ENV TOMATO=example
RUN --mount=type=bind,from=envbuilder_feature_one,target=`+featureOneDir+`,rw _CONTAINER_USER="1000" _REMOTE_USER="1000" ./install.sh
RUN --mount=type=bind,from=envbuilder_feature_one,target=/envbuilder_features/one,rw _CONTAINER_USER="1000" _REMOTE_USER="1000" ./install.sh
# Go potato - Example description!
WORKDIR `+featureTwoDir+`
WORKDIR /envbuilder_features/two
ENV POTATO=example
RUN --mount=type=bind,from=envbuilder_feature_two,target=`+featureTwoDir+`,rw VERSION="potato" _CONTAINER_USER="1000" _REMOTE_USER="1000" ./install.sh
RUN --mount=type=bind,from=envbuilder_feature_two,target=/envbuilder_features/two,rw VERSION="potato" _CONTAINER_USER="1000" _REMOTE_USER="1000" ./install.sh
USER 1000`, params.DockerfileContent)

require.Equal(t, map[string]string{
Expand Down
2 changes: 2 additions & 0 deletions devcontainer/features/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ func (s *Spec) Compile(featureRef, featureName, featureDir, containerUser, remot
sort.Strings(runDirective)
// See https://containers.dev/implementors/features/#invoking-installsh
if useBuildContexts {
// Use a deterministic target directory to make the resulting Dockerfile cacheable
featureDir = "/envbuilder_features/" + featureName
fromDirective = "FROM scratch AS envbuilder_feature_" + featureName + "\nCOPY --from=" + featureRef + " / /\n"
runDirective = append([]string{"RUN", "--mount=type=bind,from=envbuilder_feature_" + featureName + ",target=" + featureDir + ",rw"}, runDirective...)
} else {
Expand Down

0 comments on commit 8e3f287

Please sign in to comment.