Skip to content

Commit

Permalink
[SHIPA-1131] Fix app deploy for minimal images (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
murphybytes authored Mar 9, 2021
1 parent f2b3b8f commit bfb585f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion internal/chart/application_chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func New(application *ketchv1.App, pool *ketchv1.Pool, opts ...Option) (*Applica
return nil, err
}
exposedPorts := options.ExposedPorts[deployment.Version]
c := NewConfigurator(deploymentSpec.KetchYaml, *procfile, exposedPorts, DefaultApplicationPort)
c := NewConfigurator(deploymentSpec.KetchYaml, *procfile, exposedPorts, DefaultApplicationPort, application.Spec.Platform)
for _, processSpec := range deploymentSpec.Processes {
name := processSpec.Name
isRoutable := procfile.IsRoutable(name)
Expand Down
1 change: 1 addition & 0 deletions internal/chart/application_chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func TestNew(t *testing.T) {
Name: "dashboard",
},
Spec: ketchv1.AppSpec{
Platform: "static",
Deployments: []ketchv1.AppDeploymentSpec{
{
Image: "shipasoftware/go-app:v1",
Expand Down
9 changes: 8 additions & 1 deletion internal/chart/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ type Configurator struct {
procfile Procfile
exposedPorts []ketchv1.ExposedPort
defaultPort int
platform string
}

// NewConfigurator returns a Configurator instance.
func NewConfigurator(data *ketchv1.KetchYamlData, procfile Procfile, exposedPorts []ketchv1.ExposedPort, defaultPort int) Configurator {
func NewConfigurator(data *ketchv1.KetchYamlData, procfile Procfile, exposedPorts []ketchv1.ExposedPort, defaultPort int, platform string) Configurator {
shipaYaml := ketchv1.KetchYamlData{}
if data != nil {
shipaYaml = *data
Expand All @@ -32,6 +33,7 @@ func NewConfigurator(data *ketchv1.KetchYamlData, procfile Procfile, exposedPort
procfile: procfile,
exposedPorts: exposedPorts,
defaultPort: defaultPort,
platform: strings.ToLower(platform),
}
}

Expand Down Expand Up @@ -206,6 +208,11 @@ func (c Configurator) ServicePortsForProcess(process string) []apiv1.ServicePort
}

func (c Configurator) ProcessCmd(process string) []string {
// If we are not using an existing Shipa platform return the commands unmodified. In this case
// the onus is on the image creator to build an image with entry points/commands that k8s understands.
if c.platform == "" {
return c.procfile.Processes[process]
}
cmd := c.procfile.Processes[process]
before := ""
if c.data.Hooks != nil {
Expand Down
27 changes: 17 additions & 10 deletions internal/chart/configurator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func TestKubernetesConfigurator_ProcessCmd(t *testing.T) {
procfile Procfile
process string
want []string
platform string
}{
{
name: "single command without changing working directory",
Expand All @@ -22,8 +23,9 @@ func TestKubernetesConfigurator_ProcessCmd(t *testing.T) {
"web": {"python web.py"},
},
},
process: "web",
want: []string{"/bin/sh", "-lc", "exec python web.py"},
process: "web",
want: []string{"/bin/sh", "-lc", "exec python web.py"},
platform: "python",
},
{
name: "single command",
Expand All @@ -32,8 +34,9 @@ func TestKubernetesConfigurator_ProcessCmd(t *testing.T) {
"web": {"python web.py"},
},
},
process: "web",
want: []string{"/bin/sh", "-lc", "exec python web.py"},
process: "web",
want: []string{"/bin/sh", "-lc", "exec python web.py"},
platform: "python",
},
{
name: "single command with hooks",
Expand All @@ -51,8 +54,9 @@ func TestKubernetesConfigurator_ProcessCmd(t *testing.T) {
"web": {"python web.py"},
},
},
process: "web",
want: []string{"/bin/sh", "-lc", "cmd1 && cmd2 && exec python web.py"},
process: "web",
want: []string{"/bin/sh", "-lc", "cmd1 && cmd2 && exec python web.py"},
platform: "python",
},
{
name: "single command with hooks, without changing working directory",
Expand All @@ -70,8 +74,9 @@ func TestKubernetesConfigurator_ProcessCmd(t *testing.T) {
"web": {"python web.py"},
},
},
process: "web",
want: []string{"/bin/sh", "-lc", "cmd1 && cmd2 && exec python web.py"},
process: "web",
want: []string{"/bin/sh", "-lc", "cmd1 && cmd2 && exec python web.py"},
platform: "python",
},
{
name: "many commands",
Expand All @@ -80,15 +85,17 @@ func TestKubernetesConfigurator_ProcessCmd(t *testing.T) {
"web": {"python", "web.py"},
},
},
process: "web",
want: []string{"/bin/sh", "-lc", "exec $0 \"$@\"", "python", "web.py"},
process: "web",
want: []string{"/bin/sh", "-lc", "exec $0 \"$@\"", "python", "web.py"},
platform: "python",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
conf := Configurator{
data: tt.data,
procfile: tt.procfile,
platform: tt.platform,
}
if got := conf.ProcessCmd(tt.process); !reflect.DeepEqual(got, tt.want) {
t.Errorf("ProcessCmd() = %v, want %v", got, tt.want)
Expand Down

0 comments on commit bfb585f

Please sign in to comment.