Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions internal/pkg/deploy/cloudformation/stack/backend_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func (s *BackendService) Template() (string, error) {
if err != nil {
return "", fmt.Errorf("convert the Auto Scaling configuration for service %s: %w", s.name, err)
}
storage, err := convertStorageOpts(s.manifest.Storage)
if err != nil {
return "", fmt.Errorf("convert storage options for service %s: %w", s.name, err)
}
content, err := s.parser.ParseBackendService(template.WorkloadOpts{
Variables: s.manifest.BackendServiceConfig.Variables,
Secrets: s.manifest.BackendServiceConfig.Secrets,
Expand All @@ -92,6 +96,7 @@ func (s *BackendService) Template() (string, error) {
HealthCheck: s.manifest.BackendServiceConfig.ImageConfig.HealthCheckOpts(),
LogConfig: convertLogging(s.manifest.Logging),
DesiredCountLambda: desiredCountLambda.String(),
Storage: storage,
})
if err != nil {
return "", fmt.Errorf("parse backend service template: %w", err)
Expand Down
7 changes: 7 additions & 0 deletions internal/pkg/deploy/cloudformation/stack/lb_web_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ func (s *LoadBalancedWebService) Template() (string, error) {
if err != nil {
return "", fmt.Errorf("convert the Auto Scaling configuration for service %s: %w", s.name, err)
}

storage, err := convertStorageOpts(s.manifest.Storage)
if err != nil {
return "", fmt.Errorf("convert storage options for service %s: %w", s.name, err)
}

content, err := s.parser.ParseLoadBalancedWebService(template.WorkloadOpts{
Variables: s.manifest.Variables,
Secrets: s.manifest.Secrets,
Expand All @@ -124,6 +130,7 @@ func (s *LoadBalancedWebService) Template() (string, error) {
RulePriorityLambda: rulePriorityLambda.String(),
DesiredCountLambda: desiredCountLambda.String(),
EnvControllerLambda: envControllerLambda.String(),
Storage: storage,
})
if err != nil {
return "", err
Expand Down
6 changes: 6 additions & 0 deletions internal/pkg/deploy/cloudformation/stack/scheduled_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ func (j *ScheduledJob) Template() (string, error) {
return "", fmt.Errorf("convert retry/timeout config for job %s: %w", j.name, err)
}

storage, err := convertStorageOpts(j.manifest.Storage)
if err != nil {
return "", fmt.Errorf("convert storage options for job %s: %w", j.name, err)
}

content, err := j.parser.ParseScheduledJob(template.WorkloadOpts{
Variables: j.manifest.Variables,
Secrets: j.manifest.Secrets,
Expand All @@ -145,6 +150,7 @@ func (j *ScheduledJob) Template() (string, error) {
ScheduleExpression: schedule,
StateMachine: stateMachine,
LogConfig: convertLogging(j.manifest.Logging),
Storage: storage,
})
if err != nil {
return "", fmt.Errorf("parse scheduled job template: %w", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@ retries: 3
# Optional. The timeout after which to stop the job if it's still running. You can use the units (h, m, s).
timeout: 1h

storage:
volumes:
myEFSVolume:
path: '/etc/mount1'
read_only: true
efs:
id: fs-12345

sidecars:
nginx:
image: public.ecr.aws/nginx/nginx
port: 8080
mount_points:
- source_volume: myEFSVolume
path: '/var/www'
variables:
NGINX_PORT: 8080
# Optional fields for more advanced use-cases.
#
#variables: # Pass environment variables as key value pairs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,48 @@ Resources:
Value: !Sub '${EnvName}'
- Name: COPILOT_SERVICE_NAME
Value: !Sub '${WorkloadName}'
- Name: COPILOT_MOUNT_POINTS
Value: '{"myEFSVolume":"/etc/mount1"}'

LogConfiguration:
LogDriver: awslogs
Options:
awslogs-region: !Ref AWS::Region
awslogs-group: !Ref LogGroup
awslogs-stream-prefix: copilot

MountPoints:
- ContainerPath: /etc/mount1
ReadOnly: true
SourceVolume: myEFSVolume
- Name: nginx
Image: 'public.ecr.aws/nginx/nginx'
LogConfiguration:
LogDriver: awslogs
Options:
awslogs-group: !Ref LogGroup
awslogs-region: !Ref AWS::Region
awslogs-stream-prefix: copilot
MountPoints:
- ContainerPath: '/var/www'
ReadOnly: true
SourceVolume: myEFSVolume
PortMappings:
- ContainerPort: 8080
Environment:
- Name: NGINX_PORT
Value: '8080'
- Name: COPILOT_MOUNT_POINTS
Value: '{"myEFSVolume":"/var/www"}'

Volumes:
- Name: myEFSVolume
EFSVolumeConfiguration:
FilesystemId: fs-12345
RootDirectory: /
TransitEncryption: ENABLED
AuthorizationConfig:
IAM: DISABLED


ExecutionRole:
Expand Down Expand Up @@ -145,7 +180,15 @@ Resources:
StringEquals:
'iam:ResourceTag/copilot-application': !Sub '${AppName}'
'iam:ResourceTag/copilot-environment': !Sub '${EnvName}'

- PolicyName: 'GrantEFSAccessfs-12345'
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: 'Allow'
Action:
- 'elasticfilesystem:ClientMount'
Resource:
- !Sub 'arn:aws:elasticfilesystem:${AWS::Region}:${AWS::AccountId}:file-system/fs-12345'

Rule:
Metadata:
Expand Down
22 changes: 15 additions & 7 deletions internal/pkg/deploy/cloudformation/stack/transformers.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,19 @@ func convertSidecar(s map[string]*manifest.SidecarConfig) ([]*template.SidecarOp
if err != nil {
return nil, err
}
mp, err := renderSidecarMountPoints(config.MountPoints)
if err != nil {
return nil, err
}
sidecars = append(sidecars, &template.SidecarOpts{
Name: aws.String(name),
Image: config.Image,
Port: port,
Protocol: protocol,
CredsParam: config.CredsParam,
Secrets: config.Secrets,
Variables: config.Variables,
Name: aws.String(name),
Image: config.Image,
Port: port,
Protocol: protocol,
CredsParam: config.CredsParam,
Secrets: config.Secrets,
Variables: config.Variables,
MountPoints: mp,
})
}
return sidecars, nil
Expand Down Expand Up @@ -153,6 +158,9 @@ func logConfigOpts(lc *manifest.Logging) *template.LogConfigOpts {
// convertStorageOpts converts a manifest Storage field into template data structures which can be used
// to execute CFN templates
func convertStorageOpts(in *manifest.Storage) (*template.StorageOpts, error) {
if in == nil {
return nil, nil
}
v, err := renderVolumes(in.Volumes)
if err != nil {
return nil, err
Expand Down
10 changes: 5 additions & 5 deletions internal/pkg/manifest/lb_web_svc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func TestLoadBalancedWebService_ApplyEnv(t *testing.T) {
Count: Count{
Value: aws.Int(1),
},
Storage: Storage{
Storage: &Storage{
Volumes: map[string]Volume{
"myEFSVolume": {
MountPointOpts: MountPointOpts{
Expand Down Expand Up @@ -205,7 +205,7 @@ func TestLoadBalancedWebService_ApplyEnv(t *testing.T) {
Count: Count{
Value: aws.Int(1),
},
Storage: Storage{
Storage: &Storage{
Volumes: map[string]Volume{
"myEFSVolume": {
MountPointOpts: MountPointOpts{
Expand Down Expand Up @@ -259,7 +259,7 @@ func TestLoadBalancedWebService_ApplyEnv(t *testing.T) {
"GITHUB_TOKEN": "1111",
"TWILIO_TOKEN": "1111",
},
Storage: Storage{
Storage: &Storage{
Volumes: map[string]Volume{
"myEFSVolume": {
MountPointOpts: MountPointOpts{
Expand Down Expand Up @@ -311,7 +311,7 @@ func TestLoadBalancedWebService_ApplyEnv(t *testing.T) {
Variables: map[string]string{
"DDB_TABLE_NAME": "awards-prod",
},
Storage: Storage{
Storage: &Storage{
Volumes: map[string]Volume{
"myEFSVolume": {
EFS: EFSVolumeConfiguration{
Expand Down Expand Up @@ -385,7 +385,7 @@ func TestLoadBalancedWebService_ApplyEnv(t *testing.T) {
"GITHUB_TOKEN": "1111",
"TWILIO_TOKEN": "1111",
},
Storage: Storage{
Storage: &Storage{
Volumes: map[string]Volume{
"myEFSVolume": {
MountPointOpts: MountPointOpts{
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/manifest/workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ type TaskConfig struct {
Count Count `yaml:"count"`
Variables map[string]string `yaml:"variables"`
Secrets map[string]string `yaml:"secrets"`
Storage Storage `yaml:"storage"`
Storage *Storage `yaml:"storage"`
}

// WorkloadProps contains properties for creating a new workload manifest.
Expand Down
6 changes: 3 additions & 3 deletions templates/workloads/jobs/scheduled-job/cf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ Resources:
{{include "envvars" . | indent 10}}
{{include "secrets" . | indent 10}}
{{include "logconfig" . | indent 10}}
{{- if .Storage}}
{{- if .Storage -}}
{{include "mount-points" . | indent 10}}
{{- end}}
{{- end -}}
{{include "sidecars" . | indent 8}}
{{- if .Storage}}
{{- if .Storage -}}
{{include "volumes" . | indent 6}}
{{- end}}
{{include "executionrole" . | indent 2}}
Expand Down
2 changes: 1 addition & 1 deletion templates/workloads/partials/cf/mount-points.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{- if .Storage.MountPoints}}
MountPoints:
{{- range $mp := .Storage.MountPoints}}
- ContainerPath: {{$mp.ContainerPath}}
- ContainerPath: '{{$mp.ContainerPath}}'
ReadOnly: {{$mp.ReadOnly}}
SourceVolume: {{$mp.SourceVolume}}
{{- end -}}
Expand Down
2 changes: 1 addition & 1 deletion templates/workloads/partials/cf/sidecars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
{{- range $mp := $sidecar.MountPoints}}
- SourceVolume: {{$mp.SourceVolume}}
ReadOnly: {{$mp.ReadOnly}}
ContainerPath: {{$mp.ContainerPath}}
ContainerPath: '{{$mp.ContainerPath}}'
{{- end}}
{{- end}}
{{- end}}
6 changes: 3 additions & 3 deletions templates/workloads/partials/cf/volumes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Volumes:
- Name: {{$vol.Name}}
EFSVolumeConfiguration:
FilesystemId: {{$vol.Filesystem}}
RootDirectory: {{$vol.RootDirectory}}
RootDirectory: '{{$vol.RootDirectory}}'
TransitEncryption: ENABLED
{{- if or $vol.AccessPointID $vol.IAM}}
AuthorizationConfig:
Expand All @@ -15,5 +15,5 @@ Volumes:
IAM: {{$vol.IAM}}
{{- end}}
{{- end}}
{{- end}}
{{- end}}
{{- end -}}
{{- end -}}
6 changes: 3 additions & 3 deletions templates/workloads/services/backend/cf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ Resources:
StartPeriod: {{.HealthCheck.StartPeriod}}
Timeout: {{.HealthCheck.Timeout}}
{{- end}}
{{- if .Storage}}
{{- if .Storage -}}
{{include "mount-points" . | indent 10}}
{{- end}}
{{- end -}}
{{include "sidecars" . | indent 8}}
{{- if .Storage}}
{{- if .Storage -}}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh does adding "-}}" remove an extra new line for these if blocks?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, that's right. It trims whitespace until the next directive. In these sections of template where there are multiple lines of interpolations one after another sometimes an extra newline can sneak in. The trailing -}} fixes that. I don't want to do it everywhere but it's helpful sometimes to clean up the rendered CF.

{{include "volumes" . | indent 6}}
{{- end}}
{{include "executionrole" . | indent 2}}
Expand Down
6 changes: 3 additions & 3 deletions templates/workloads/services/lb-web/cf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ Resources:
Value: !GetAtt EnvControllerAction.PublicLoadBalancerDNSName
{{include "secrets" . | indent 10}}
{{include "logconfig" . | indent 10}}
{{- if .Storage}}
{{- if .Storage -}}
{{include "mount-points" . | indent 10}}
{{- end}}
{{- end -}}
{{include "sidecars" . | indent 8}}
{{if .Storage}}
{{if .Storage -}}
{{include "volumes" . | indent 6}}
{{- end}}
{{include "executionrole" . | indent 2}}
Expand Down