Skip to content

Commit

Permalink
Merge 7bc0ba9 into a6443b3
Browse files Browse the repository at this point in the history
  • Loading branch information
julienduchesne committed Apr 30, 2019
2 parents a6443b3 + 7bc0ba9 commit e18cbaa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 6 additions & 1 deletion docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const (
maxDockerTagLength = 128
)

func callDocker(withDockerMount bool, args ...string) int {
func callDocker(withCurrentUser bool, withDockerMount bool, args ...string) int {
command := append([]string{config.EntryPoint}, args...)

// Change the default log level for terragrunt
Expand Down Expand Up @@ -86,6 +86,11 @@ func callDocker(withDockerMount bool, args ...string) int {
dockerArgs = append(dockerArgs, withDockerMountArgs...)
}

if withCurrentUser {
currentUser := must(user.Current()).(*user.User)
dockerArgs = append(dockerArgs, fmt.Sprintf("--user=%s:%s", currentUser.Uid, currentUser.Gid))
}

if !noHome {
currentUser := must(user.Current()).(*user.User)
home := filepath.ToSlash(currentUser.HomeDir)
Expand Down
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func main() {
getAllVersions = app.Switch("all-versions", "Get versions of TGF & all others underlying utilities (alias --av)").Bool()
pruneImages = app.Switch("prune", "Remove all previous versions of the targeted image").Bool()
getCurrentVersion = app.Switch("current-version", "Get current version information (alias --cv)").Bool()
withCurrentUser = app.Switch("with-current-user", "Runs the docker command with the current user, using the --user arg (alias --cu)").Bool()
withDockerMount = app.Switch("with-docker-mount", "Mounts the docker socket to the image so the host's docker api is usable (alias --wd)").Bool()
entrypoint = app.Argument("entrypoint", "Override the entry point for docker", 'E').PlaceHolder("terragrunt").String()
image = app.Argument("image", "Use the specified image instead of the default one").PlaceHolder("coveo/tgf").String()
Expand All @@ -180,7 +181,8 @@ func main() {
app.Switch("na", "alias for no-aws").Hidden().BoolVar(&noAWS)
app.Switch("cv", "alias for current-version").Hidden().BoolVar(getCurrentVersion)
app.Switch("av", "alias for all-versions").Hidden().BoolVar(getAllVersions)
app.Switch("wd", "alias for with-docker").Hidden().BoolVar(withDockerMount)
app.Switch("cu", "alias for with-current-user").Hidden().BoolVar(withCurrentUser)
app.Switch("wd", "alias for with-docker-mount").Hidden().BoolVar(withDockerMount)
app.Switch("li", "alias for local-image").Hidden().BoolVar(&useLocalImage)
app.Switch("it", "alias for interactive").Hidden().BoolVar(&dockerInteractive)
app.Argument("da", "alias for docker-arg").Hidden().StringsVar(&dockerOptions)
Expand Down Expand Up @@ -271,7 +273,7 @@ func main() {
}
}

os.Exit(callDocker(*withDockerMount, unmanaged...))
os.Exit(callDocker(*withCurrentUser, *withDockerMount, unmanaged...))
}

func validateVersion(version string) bool {
Expand Down

0 comments on commit e18cbaa

Please sign in to comment.