Skip to content

Commit 1748e9a

Browse files
authored
Revert full-project Dockerfile context, fixes ddev#4727 (ddev#4728) [skip ci]
1 parent c298b5c commit 1748e9a

File tree

4 files changed

+10
-28
lines changed

4 files changed

+10
-28
lines changed

docs/content/users/extend/customizing-images.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ RUN chmod -R ugo+rw $COMPOSER_HOME
7878
ENV COMPOSER_HOME=""
7979
```
8080

81-
**Remember that the Dockerfile is normally building a Docker image that will be used later with DDEV.** At the time the Dockerfile is executing, your code by default is not mounted and the container is not running, it’s just being built. So for example, an `npm install` in `/var/www/html` will not do anything useful because the code is not there at image building time. However, you use `RUN` in the context of your codebase using something like `RUN --mount=type=bind,source=.,target=/var/www/html cp /var/www/html/index.php /var/tmp/` would mount your code and make it available at the normal `/var/www/html` mount. However, you can't make changes to the mounted code, so things like an early `npm install` wouldn't work, although `npm install -g` would work.
81+
**Remember that the Dockerfile is building a Docker image that will be used later with DDEV.** At the time the Dockerfile is executing, your code is not mounted and the container is not running, the image is just being built. So for example, an `npm install` in `/var/www/html` will not do anything to your project because the code is not there at image building time.
8282

8383
### Build Time Environment Variables
8484

pkg/ddevapp/app_compose_template.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ services:
8585
web:
8686
container_name: {{ .Plugin }}-${DDEV_SITENAME}-web
8787
build:
88-
context: '../'
89-
dockerfile: './.ddev/.webimageBuild/Dockerfile'
88+
context: '{{ .WebBuildContext }}'
9089
args:
9190
BASE_IMAGE: $DDEV_WEBIMAGE
9291
username: '{{ .Username }}'

pkg/ddevapp/config.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ func (app *DdevApp) RenderComposeYAML() (string, error) {
767767
Username: username,
768768
UID: uid,
769769
GID: gid,
770-
WebBuildContext: "../",
770+
WebBuildContext: "./.webimageBuild",
771771
DBBuildContext: "./.dbimageBuild",
772772
AutoRestartContainers: globalconfig.DdevGlobalConfig.AutoRestartContainers,
773773
FailOnHookFail: app.FailOnHookFail || app.FailOnHookFailGlobal,
@@ -904,14 +904,14 @@ redirect_stderr=true
904904
if err != nil {
905905
return "", fmt.Errorf("failed to write .webimageBuild/%s.conf: %v", appStart.Name, err)
906906
}
907-
extraWebContent = extraWebContent + fmt.Sprintf("\nADD .ddev/.webimageBuild/%s.conf /etc/supervisor/conf.d\n", appStart.Name)
907+
extraWebContent = extraWebContent + fmt.Sprintf("\nADD %s.conf /etc/supervisor/conf.d\n", appStart.Name)
908908
}
909909
if len(supervisorGroup) > 0 {
910910
err = os.WriteFile(app.GetConfigPath(".webimageBuild/webextradaemons.conf"), []byte("[group:webextradaemons]\nprograms="+strings.Join(supervisorGroup, ",")), 0755)
911911
if err != nil {
912912
return "", fmt.Errorf("failed to write .webimageBuild/webextradaemons.conf: %v", err)
913913
}
914-
extraWebContent = extraWebContent + "\nADD .ddev/.webimageBuild/webextradaemons.conf /etc/supervisor/conf.d\n"
914+
extraWebContent = extraWebContent + "\nADD webextradaemons.conf /etc/supervisor/conf.d\n"
915915
}
916916

917917
err = WriteBuildDockerfile(app.GetConfigPath(".webimageBuild/Dockerfile"), app.GetConfigPath("web-build"), app.WebImageExtraPackages, app.ComposerVersion, extraWebContent)

pkg/ddevapp/config_test.go

+5-22
Original file line numberDiff line numberDiff line change
@@ -1129,31 +1129,15 @@ func TestCustomBuildDockerfiles(t *testing.T) {
11291129
assert.NoError(err)
11301130

11311131
t.Cleanup(func() {
1132+
runTime()
11321133
err = app.Stop(true, false)
11331134
assert.NoError(err)
11341135
err = os.RemoveAll(app.GetConfigPath("web-build"))
11351136
assert.NoError(err)
11361137
err = os.RemoveAll(app.GetConfigPath("db-build"))
11371138
assert.NoError(err)
1138-
runTime()
11391139
})
11401140

1141-
// web-build Dockerfile.test - slightly different from db-build because of
1142-
// different context; this tests to see that the code can be mounted from context to
1143-
// /var/www/html and we can access index.php in docroot
1144-
err = WriteImageDockerfile(app.GetConfigPath("web-build/Dockerfile.test1"), []byte(fmt.Sprintf(`
1145-
ADD .ddev/web-build/junkfile /
1146-
RUN --mount=type=bind,source=.,target=/var/www/html cp /var/www/html/%s/index.php /var/tmp/%s-index.php
1147-
RUN touch /var/tmp/`+"added-by-web-test1.txt", app.Docroot, t.Name())))
1148-
require.NoError(t, err)
1149-
1150-
// db-build Dockerfile.test - slightly different from web-build because of
1151-
// different context
1152-
err = WriteImageDockerfile(app.GetConfigPath("db-build/Dockerfile.test1"), []byte(`
1153-
ADD junkfile /
1154-
RUN touch /var/tmp/`+"added-by-db-test1.txt"))
1155-
require.NoError(t, err)
1156-
11571141
// Create simple dockerfiles that just touch /var/tmp/added-by-<container>txt
11581142
for _, item := range []string{"web", "db"} {
11591143
err = fileutil.TemplateStringToFile("junkfile", nil, app.GetConfigPath(fmt.Sprintf("%s-build/junkfile", item)))
@@ -1163,6 +1147,10 @@ RUN touch /var/tmp/`+"added-by-"+item+".txt"))
11631147
assert.NoError(err)
11641148
// Add also Dockerfile.* alternatives
11651149
// Last one includes previously recommended ARG/FROM that needs to be removed
1150+
err = WriteImageDockerfile(app.GetConfigPath(item+"-build/Dockerfile.test1"), []byte(`
1151+
ADD junkfile /
1152+
RUN touch /var/tmp/`+"added-by-"+item+"-test1.txt"))
1153+
assert.NoError(err)
11661154

11671155
err = WriteImageDockerfile(app.GetConfigPath(item+"-build/Dockerfile.test2"), []byte(`
11681156
RUN touch /var/tmp/`+"added-by-"+item+"-test2.txt"))
@@ -1232,11 +1220,6 @@ RUN touch /var/tmp/running-php-${DDEV_PHP_VERSION}
12321220
Cmd: fmt.Sprintf("ls /var/tmp/running-php-%s >/dev/null", app.PHPVersion),
12331221
})
12341222
assert.NoError(err)
1235-
1236-
_, _, err = app.Exec(&ExecOpts{
1237-
Cmd: fmt.Sprintf("ls /var/tmp/%s-index.php >/dev/null", t.Name()),
1238-
})
1239-
assert.NoError(err)
12401223
}
12411224

12421225
// TestConfigLoadingOrder verifies that configs load in lexicographical order

0 commit comments

Comments
 (0)