Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(deploy): deploy workloads with entrypoint and command overrides #1999

Merged
merged 9 commits into from
Mar 3, 2021
2 changes: 2 additions & 0 deletions internal/pkg/deploy/cloudformation/stack/backend_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ func (s *BackendService) Template() (string, error) {
DesiredCountLambda: desiredCountLambda.String(),
Storage: storage,
Network: convertNetworkConfig(s.manifest.Network),
EntryPoint: s.manifest.EntryPoint.ToStringSlice(),
Command: s.manifest.Command.ToStringSlice(),
})
if err != nil {
return "", fmt.Errorf("parse backend service template: %w", err)
Expand Down
2 changes: 2 additions & 0 deletions internal/pkg/deploy/cloudformation/stack/lb_web_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ func (s *LoadBalancedWebService) Template() (string, error) {
EnvControllerLambda: envControllerLambda.String(),
Storage: storage,
Network: convertNetworkConfig(s.manifest.Network),
EntryPoint: s.manifest.EntryPoint.ToStringSlice(),
Command: s.manifest.Command.ToStringSlice(),
})
if err != nil {
return "", err
Expand Down
2 changes: 2 additions & 0 deletions internal/pkg/deploy/cloudformation/stack/scheduled_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ func (j *ScheduledJob) Template() (string, error) {
LogConfig: convertLogging(j.manifest.Logging),
Storage: storage,
Network: convertNetworkConfig(j.manifest.Network),
EntryPoint: j.manifest.EntryPoint.ToStringSlice(),
Command: j.manifest.Command.ToStringSlice(),
})
if err != nil {
return "", fmt.Errorf("parse scheduled job template: %w", err)
Expand Down
5 changes: 3 additions & 2 deletions internal/pkg/manifest/backend_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ type BackendService struct {
// BackendServiceConfig holds the configuration that can be overriden per environments.
type BackendServiceConfig struct {
ImageConfig imageWithPortAndHealthcheck `yaml:"image,flow"`
TaskConfig `yaml:",inline"`
*Logging `yaml:"logging,flow"`
ImageOverride `yaml:",inline"`
TaskConfig `yaml:",inline"`
*Logging `yaml:"logging,flow"`
Sidecars map[string]*SidecarConfig `yaml:"sidecars"`
Network NetworkConfig `yaml:"network"`
}
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/manifest/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type ScheduledJob struct {
// ScheduledJobConfig holds the configuration for a scheduled job
type ScheduledJobConfig struct {
ImageConfig Image `yaml:"image,flow"`
ImageOverride `yaml:",inline"`
TaskConfig `yaml:",inline"`
*Logging `yaml:"logging,flow"`
Sidecars map[string]*SidecarConfig `yaml:"sidecars"`
Expand Down
7 changes: 4 additions & 3 deletions internal/pkg/manifest/lb_web_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ type LoadBalancedWebService struct {
// LoadBalancedWebServiceConfig holds the configuration for a load balanced web service.
type LoadBalancedWebServiceConfig struct {
ImageConfig ServiceImageWithPort `yaml:"image,flow"`
RoutingRule `yaml:"http,flow"`
TaskConfig `yaml:",inline"`
*Logging `yaml:"logging,flow"`
ImageOverride `yaml:",inline"`
RoutingRule `yaml:"http,flow"`
TaskConfig `yaml:",inline"`
*Logging `yaml:"logging,flow"`
Sidecars map[string]*SidecarConfig `yaml:"sidecars"`
Network NetworkConfig `yaml:"network"`
}
Expand Down
7 changes: 7 additions & 0 deletions internal/pkg/template/template_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ func TestTemplate_ParseLoadBalancedWebService(t *testing.T) {
},
},
},
"renders a valid template with entrypoint and command overrides": {
opts: template.WorkloadOpts{
HTTPHealthCheck: defaultHttpHealthCheck,
EntryPoint: []string{"/bin/echo", "hello"},
Command: []string{"world"},
},
},
}

for name, tc := range testCases {
Expand Down
3 changes: 3 additions & 0 deletions internal/pkg/template/workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var (
"env-controller",
"mount-points",
"volumes",
"image-overrides",
}
)

Expand Down Expand Up @@ -176,6 +177,8 @@ type WorkloadOpts struct {
Autoscaling *AutoscalingOpts
Storage *StorageOpts
Network *NetworkOpts
EntryPoint []string
Command []string

// Additional options for service templates.
HealthCheck *ecs.HealthCheck
Expand Down
2 changes: 2 additions & 0 deletions internal/pkg/template/workload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func TestTemplate_ParseSvc(t *testing.T) {
mockBox.AddString("workloads/partials/cf/env-controller.yml", "env-controller")
mockBox.AddString("workloads/partials/cf/mount-points.yml", "mount-points")
mockBox.AddString("workloads/partials/cf/volumes.yml", "volumes")
mockBox.AddString("workloads/partials/cf/image-overrides.yml", "image-overrides")

t.box = mockBox
},
Expand All @@ -67,6 +68,7 @@ func TestTemplate_ParseSvc(t *testing.T) {
env-controller
mount-points
volumes
image-overrides
`,
},
}
Expand Down
1 change: 1 addition & 0 deletions templates/workloads/jobs/scheduled-job/cf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Resources:
{{include "envvars" . | indent 10}}
{{include "secrets" . | indent 10}}
{{include "logconfig" . | indent 10}}
{{include "image-overrides" . | indent 10}}
{{- if .Storage -}}
{{include "mount-points" . | indent 10}}
{{- end -}}
Expand Down
12 changes: 12 additions & 0 deletions templates/workloads/partials/cf/image-overrides.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- if .EntryPoint}}
EntryPoint:
{{- range $part := .EntryPoint}}
- {{$part}}
{{- end}}
{{- end}}
{{- if .Command}}
Command:
{{- range $part := .Command}}
- {{$part}}
{{- end}}
{{- end}}
1 change: 1 addition & 0 deletions templates/workloads/services/backend/cf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Resources:
{{include "envvars" . | indent 10}}
{{include "secrets" . | indent 10}}
{{include "logconfig" . | indent 10}}
{{include "image-overrides" . | indent 10}}
{{- if .HealthCheck}}
HealthCheck:
Command: {{quoteSlice .HealthCheck.Command | fmtSlice}}
Expand Down
1 change: 1 addition & 0 deletions templates/workloads/services/lb-web/cf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Resources:
{{include "envvars" . | indent 10}}
- Name: COPILOT_LB_DNS
Value: !GetAtt EnvControllerAction.PublicLoadBalancerDNSName
{{include "image-overrides" . | indent 10}}
{{include "secrets" . | indent 10}}
{{include "logconfig" . | indent 10}}
{{- if .Storage -}}
Expand Down