Skip to content

Commit

Permalink
Use working_dir in generated compose instead of always overriding, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rfay committed Aug 14, 2021
1 parent 65b8151 commit a5eb4ab
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
5 changes: 3 additions & 2 deletions pkg/ddevapp/apptypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,13 @@ func (app *DdevApp) ImportFilesAction(importPath, extPath string) error {

// DefaultWorkingDirMap returns the app type's default working directory map.
func (app *DdevApp) DefaultWorkingDirMap() map[string]string {
_, _, username := util.GetContainerUIDGid()
// Default working directory values are defined here.
// Services working directories can be overridden by app types if needed.
defaults := map[string]string{
"web": "/var/www/html/",
"db": "/home",
"dba": "/home",
"db": "/home/" + username,
"dba": "/root",
}

if appFuncs, ok := appTypeMatrix[app.Type]; ok && appFuncs.defaultWorkingDirMap != nil {
Expand Down
6 changes: 6 additions & 0 deletions pkg/ddevapp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,9 @@ type composeYAMLVars struct {
GID string
AutoRestartContainers bool
FailOnHookFail bool
WebWorkingDir string
DBWorkingDir string
DBAWorkingDir string
WebEnvironment []string
}

Expand Down Expand Up @@ -727,6 +730,9 @@ func (app *DdevApp) RenderComposeYAML() (string, error) {
DBBuildDockerfile: "../.dbimageBuild/Dockerfile",
AutoRestartContainers: globalconfig.DdevGlobalConfig.AutoRestartContainers,
FailOnHookFail: app.FailOnHookFail || app.FailOnHookFailGlobal,
WebWorkingDir: app.GetWorkingDir("web", ""),
DBWorkingDir: app.GetWorkingDir("db", ""),
DBAWorkingDir: app.GetWorkingDir("dba", ""),
WebEnvironment: webEnvironment,
}
if app.NFSMountEnabled || app.NFSMountEnabledGlobal {
Expand Down
10 changes: 5 additions & 5 deletions pkg/ddevapp/ddevapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -1141,8 +1141,8 @@ func (app *DdevApp) Exec(opts *ExecOpts) (string, string, error) {
}

args := []string{"exec"}
if workingDir := app.GetWorkingDir(opts.Service, opts.Dir); workingDir != "" {
args = append(args, "-w", workingDir)
if opts.Dir != "" {
args = append(args, "-w", opts.Dir)
}

if !isatty.IsTerminal(os.Stdin.Fd()) || !opts.Tty {
Expand All @@ -1169,7 +1169,7 @@ func (app *DdevApp) Exec(opts *ExecOpts) (string, string, error) {
errcheck := "set -eu"
args = append(args, shell, "-c", errcheck+` && ( `+opts.Cmd+`)`)

files, err := app.ComposeFiles()
files := []string{app.DockerComposeFullRenderedYAMLPath()}
if err != nil {
return "", "", err
}
Expand Down Expand Up @@ -1213,8 +1213,8 @@ func (app *DdevApp) ExecWithTty(opts *ExecOpts) error {
}

args := []string{"exec"}
if workingDir := app.GetWorkingDir(opts.Service, opts.Dir); workingDir != "" {
args = append(args, "-w", workingDir)
if opts.Dir != "" {
args = append(args, "-w", opts.Dir)
}

args = append(args, opts.Service)
Expand Down
3 changes: 3 additions & 0 deletions pkg/ddevapp/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ services:
gid: '{{ .GID }}'
image: ${DDEV_DBIMAGE}-${DDEV_SITENAME}-built
stop_grace_period: 60s
working_dir: "{{ .DBWorkingDir }}"
volumes:
- type: "volume"
source: mariadb-database
Expand Down Expand Up @@ -75,6 +76,7 @@ services:
image: ${DDEV_WEBIMAGE}-${DDEV_SITENAME}-built
cap_add:
- SYS_PTRACE
working_dir: "{{ .WebWorkingDir }}"
volumes:
{{ if not .NoProjectMount }}
- type: {{ .MountType }}
Expand Down Expand Up @@ -165,6 +167,7 @@ services:
dba:
container_name: ddev-${DDEV_SITENAME}-dba
image: $DDEV_DBAIMAGE
working_dir: "{{ .DBAWorkingDir }}"
restart: "{{ if .AutoRestartContainers }}always{{ else }}no{{ end }}"
labels:
com.ddev.site-name: ${DDEV_SITENAME}
Expand Down

0 comments on commit a5eb4ab

Please sign in to comment.