Skip to content

Commit 8e3f287

Browse files
committed
Use a deterministic target path for feature dir mounts with useBuildContexts
This avoids caching issues when using the Dockerfile produced in useBuildContexts mode. See #205 (comment) for context.
1 parent 7ebdf44 commit 8e3f287

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

devcontainer/devcontainer_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@ FROM localhost:5000/envbuilder-test-codercom-code-server:latest
131131
132132
USER root
133133
# Rust tomato - Example description!
134-
WORKDIR `+featureOneDir+`
134+
WORKDIR /envbuilder_features/one
135135
ENV TOMATO=example
136-
RUN --mount=type=bind,from=envbuilder_feature_one,target=`+featureOneDir+`,rw _CONTAINER_USER="1000" _REMOTE_USER="1000" ./install.sh
136+
RUN --mount=type=bind,from=envbuilder_feature_one,target=/envbuilder_features/one,rw _CONTAINER_USER="1000" _REMOTE_USER="1000" ./install.sh
137137
# Go potato - Example description!
138-
WORKDIR `+featureTwoDir+`
138+
WORKDIR /envbuilder_features/two
139139
ENV POTATO=example
140-
RUN --mount=type=bind,from=envbuilder_feature_two,target=`+featureTwoDir+`,rw VERSION="potato" _CONTAINER_USER="1000" _REMOTE_USER="1000" ./install.sh
140+
RUN --mount=type=bind,from=envbuilder_feature_two,target=/envbuilder_features/two,rw VERSION="potato" _CONTAINER_USER="1000" _REMOTE_USER="1000" ./install.sh
141141
USER 1000`, params.DockerfileContent)
142142

143143
require.Equal(t, map[string]string{

devcontainer/features/features.go

+2
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ func (s *Spec) Compile(featureRef, featureName, featureDir, containerUser, remot
218218
sort.Strings(runDirective)
219219
// See https://containers.dev/implementors/features/#invoking-installsh
220220
if useBuildContexts {
221+
// Use a deterministic target directory to make the resulting Dockerfile cacheable
222+
featureDir = "/envbuilder_features/" + featureName
221223
fromDirective = "FROM scratch AS envbuilder_feature_" + featureName + "\nCOPY --from=" + featureRef + " / /\n"
222224
runDirective = append([]string{"RUN", "--mount=type=bind,from=envbuilder_feature_" + featureName + ",target=" + featureDir + ",rw"}, runDirective...)
223225
} else {

0 commit comments

Comments
 (0)