Skip to content

Commit

Permalink
Fix ordering of docker entrypoint and entrypoint prefix (#1291)
Browse files Browse the repository at this point in the history
The entrypoint prefix is appended to the entrypoint but should be
prepended
  • Loading branch information
djfinlay authored and nlopezgi committed Nov 26, 2019
1 parent 02d2544 commit a06815c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion container/go/pkg/compat/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ func updateConfig(overrideInfo *OverrideConfigOpts) error {
}

if len(overrideInfo.EntrypointPrefix) != 0 {
newEntrypoint := append(overrideInfo.ConfigFile.Config.Entrypoint, overrideInfo.EntrypointPrefix...)
newEntrypoint := append(overrideInfo.EntrypointPrefix, overrideInfo.ConfigFile.Config.Entrypoint...)
overrideInfo.ConfigFile.Config.Entrypoint = newEntrypoint
}
return nil
Expand Down
32 changes: 32 additions & 0 deletions container/go/pkg/compat/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,35 @@ func TestWorkdirOverride(t *testing.T) {
t.Errorf("WorkingDir field in config was updated to invalid value, got %q, want %q.", opts.ConfigFile.Config.WorkingDir, want)
}
}

func TestEntrypointPrefix(t *testing.T) {
want := []string{"prefix1", "prefix2", "entrypoint1", "entrypoint2"}
opts := &OverrideConfigOpts{
EntrypointPrefix: want[:2],
Entrypoint: want[2:],
ConfigFile: &v1.ConfigFile{
Config: v1.Config{
Entrypoint: want,
},
},
Stamper: &Stamper{},
}
if err := updateConfig(opts); err != nil {
t.Fatalf("Failed to update config: %v", err)
}
if !stringSlicesEqual(opts.ConfigFile.Config.Entrypoint, want) {
t.Errorf("Entrypoint field in config was updated to invalid value, got %q, want %q.", opts.ConfigFile.Config.Entrypoint, want)
}
}

func stringSlicesEqual(a, b []string) bool {
if len(a) != len(b) {
return false
}
for i := range a {
if a[i] != b[i] {
return false
}
}
return true
}

0 comments on commit a06815c

Please sign in to comment.