Skip to content

Commit

Permalink
Explicitly set HOME for containers
Browse files Browse the repository at this point in the history
Podman sets this automatically to the working directory (and even extends
/etc/passwd). We make it explicit here and also allow to change it
(helpful to mount some specific folders into the home directory, e.g.,
credentials).
  • Loading branch information
aspettl committed Jan 23, 2022
1 parent 388a9e9 commit d128297
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions cfg/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type ToolConfig struct {
ImageName string
ImageTag ImageTagConfig
WorkDir string
HomeDir string
Command CommandConfig
Mounts []MountConfig
Env []EnvConfig
Expand Down
1 change: 1 addition & 0 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ var generateCmd = &cobra.Command{
ImageName: toolConfig.ImageName,
ImageTag: toolConfig.ImageTag,
WorkDir: toolConfig.WorkDir,
HomeDir: toolConfig.HomeDir,
Command: toolConfig.Command,
Mounts: toolConfig.Mounts,
Env: toolConfig.Env,
Expand Down
3 changes: 3 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ func initConfig() {
if toolConfig.WorkDir == "" {
toolConfig.WorkDir = "/work"
}
if toolConfig.HomeDir == "" {
toolConfig.HomeDir = "/home/container"
}
if !toolConfig.Command.Type.IsDoNotSpecify() && !toolConfig.Command.Type.IsReuseName() {
toolConfig.Command.Type = cfg.DoNotSpecify
}
Expand Down
10 changes: 5 additions & 5 deletions example/ccliwrapper.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ tools:
type: DoNotSpecify
mounts:
- source: $HOME/.aws
target: /root/.aws
target: /home/container/.aws

go:
type: WrapperScript
Expand Down Expand Up @@ -108,7 +108,7 @@ tools:
type: DoNotSpecify
mounts:
- source: $HOME/.kube
target: /.kube
target: /home/container/.kube
customScript: |-
# implement simple caching for "kubectl completion" commands so that this can be used
# in e.g. .bashrc without a big performance impact
Expand Down Expand Up @@ -140,11 +140,11 @@ tools:
type: DoNotSpecify
mounts:
- source: $HOME/.kube
target: /root/.kube
target: /home/container/.kube
- source: $HOME/.config/helm
target: /root/.config/helm
target: /home/container/.config/helm
- source: $HOME/.cache/helm
target: /root/.cache/helm
target: /home/container/.cache/helm
customScript: |-
# implement simple caching for "helm completion" commands so that this can be used
# in e.g. .bashrc without a big performance impact
Expand Down
1 change: 1 addition & 0 deletions gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type ToolParams struct {
ImageName string
ImageTag cfg.ImageTagConfig
WorkDir string
HomeDir string
Command cfg.CommandConfig
Mounts []cfg.MountConfig
Env []cfg.EnvConfig
Expand Down
4 changes: 4 additions & 0 deletions tpl/wrapperscript.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ declare -a additional_params=(
{{- range .Mounts }}
-v '{{ .Source }}:{{ .Target }}'
{{- end }}
{{- if ne .HomeDir .WorkDir }}
--tmpfs '{{ .HomeDir }}'
{{- end }}
-e 'HOME={{ .HomeDir }}'
{{- range .Env }}
-e '{{ .Name }}={{ .Value }}'
{{- end }}
Expand Down

0 comments on commit d128297

Please sign in to comment.