Skip to content

Commit

Permalink
fix: allow docker and docker-compose run if WorkDirOuter or IdentityD…
Browse files Browse the repository at this point in the history
…irOuter does not exist
  • Loading branch information
xmik committed Feb 1, 2019
1 parent faaca44 commit 0f0c7da
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
* fix: resolve relative paths in config object
* fix: allow docker and docker-compose run if WorkDirOuter or IdentityDirOuter does not exist

### 0.2.0 (2019-Jan-25)

Expand Down
5 changes: 1 addition & 4 deletions docker_compose_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,7 @@ func safelyCloseChannel(ch chan bool) (justClosed bool) {
}

func (dc DockerComposeDriver) HandleRun(mergedConfig Config, runID string, envService EnvServiceInterface) int {
if envService.IsCurrentUserRoot() {
dc.Logger.Log("warn", "Current user is root, which is not recommended")
}

warnGeneral(dc.FileService, mergedConfig, envService, dc.Logger)
envFile := getEnvFilePath(runID, mergedConfig.Test)
saveEnvToFile(dc.FileService, envFile, mergedConfig.BlacklistVariables, envService.Variables())
err := dc.handleDCFilesForRun(mergedConfig, envFile)
Expand Down
7 changes: 1 addition & 6 deletions docker_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ func (d DockerDriver) ConstructDockerRunCmd(config Config, envFilePath string, c
if config.RemoveContainers == "true" {
cmd += " --rm"
}
if d.FileService.GetFileUid(config.WorkDirOuter) == 0 {
d.Logger.Log("warn", fmt.Sprintf("WorkDirOuter: %s is owned by root, which is not recommended", config.WorkDirOuter))
}
cmd += fmt.Sprintf(" -v %s:%s -v %s:/dojo/identity:ro", config.WorkDirOuter, config.WorkDirInner, config.IdentityDirOuter)
cmd += fmt.Sprintf(" --env-file=%s", envFilePath)
if os.Getenv("DISPLAY") != "" {
Expand All @@ -69,9 +66,7 @@ func (d DockerDriver) ConstructDockerRunCmd(config Config, envFilePath string, c
}

func (d DockerDriver) HandleRun(mergedConfig Config, runID string, envService EnvServiceInterface) int {
if envService.IsCurrentUserRoot() {
d.Logger.Log("warn", "Current user is root, which is not recommended")
}
warnGeneral(d.FileService, mergedConfig, envService, d.Logger)
envFile := getEnvFilePath(runID, mergedConfig.Test)
saveEnvToFile(d.FileService, envFile, mergedConfig.BlacklistVariables, envService.Variables())

Expand Down
21 changes: 21 additions & 0 deletions driver.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
package main

import "fmt"

type DojoDriverInterface interface {
HandleRun(mergedConfig Config, runID string, envService EnvServiceInterface) int
CleanAfterRun(mergedConfig Config, runID string) int
HandlePull(mergedConfig Config) int
HandleSignal(mergedConfig Config, runID string) int
HandleMultipleSignal(mergedConfig Config, runID string) int
}

func warnGeneral(fileService FileServiceInterface, config Config, envService EnvServiceInterface, logger *Logger) {
if fileService.FileExists(config.WorkDirOuter) {
if fileService.GetFileUid(config.WorkDirOuter) == 0 {
logger.Log("warn", fmt.Sprintf(
"WorkDirOuter: %s is owned by root, which is not recommended", config.WorkDirOuter))
}
} else {
logger.Log("warn", fmt.Sprintf(
"WorkDirOuter: %s does not exist", config.WorkDirOuter))
}
if !fileService.FileExists(config.IdentityDirOuter) {
logger.Log("warn", fmt.Sprintf(
"IdentityDirOuter: %s does not exist", config.IdentityDirOuter))
}
if envService.IsCurrentUserRoot() {
logger.Log("warn", "Current user is root, which is not recommended")
}
}
20 changes: 20 additions & 0 deletions test/02-docker-run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,26 @@ DOJO_PATH=$(readlink -f "./bin/dojo")
testEnvFileIsRemoved
testDockerContainerIsRemoved
}
@test "driver: docker, action: run; custom, relative work directory - does not exist" {
cleanUpDockerContainer
cleanUpEnvFiles
rm -rf ./test/test-files/not-existent
run ${DOJO_PATH} -c test/test-files/Dojofile.work_not_exists --debug=true --test=true --image=alpine:3.8 whoami
assert_output --partial "Dojo version"
assert_output --partial "root"
assert_output --partial "alpine:3.8 whoami"
assert_output --partial "Exit status from run command: 0"
assert_output --partial "Exit status from cleaning: 0"
assert_output --partial "Exit status from signals: 0"
assert_output --partial "test/test-files/not-existent does not exist"
assert_output --partial "WARN"
refute_output --partial "ERROR"
refute_output --partial "error"
assert_equal "$status" 0
rm -rf ./test/test-files/not-existent
testEnvFileIsRemoved
testDockerContainerIsRemoved
}
@test "driver: docker, action: run, --rm=false" {
cleanUpDockerContainer
cleanUpEnvFiles
Expand Down
2 changes: 2 additions & 0 deletions test/test-files/Dojofile.work_not_exists
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DOJO_DRIVER=docker
DOJO_WORK_OUTER="./test/test-files/not-existent"

0 comments on commit 0f0c7da

Please sign in to comment.