Skip to content

Commit e070b5f

Browse files
authored
feat: add credential param for private repository #2101 (#2582)
This PR add support for private repositories. It adds new parameter `credential` for ECS services which contain ARN of the AWS secret. This parameter generates corresponding CloudFormation resources. Fixes #2101 By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent 64920a0 commit e070b5f

File tree

8 files changed

+78
-64
lines changed

8 files changed

+78
-64
lines changed

internal/pkg/deploy/cloudformation/stack/backend_svc.go

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -118,25 +118,26 @@ func (s *BackendService) Template() (string, error) {
118118
return "", err
119119
}
120120
content, err := s.parser.ParseBackendService(template.WorkloadOpts{
121-
Variables: s.manifest.BackendServiceConfig.Variables,
122-
Secrets: s.manifest.BackendServiceConfig.Secrets,
123-
NestedStack: outputs,
124-
Sidecars: sidecars,
125-
Autoscaling: autoscaling,
126-
CapacityProviders: capacityProviders,
127-
DesiredCountOnSpot: desiredCountOnSpot,
128-
ExecuteCommand: convertExecuteCommand(&s.manifest.ExecuteCommand),
129-
WorkloadType: manifest.BackendServiceType,
130-
HealthCheck: s.manifest.BackendServiceConfig.ImageConfig.HealthCheckOpts(),
131-
LogConfig: convertLogging(s.manifest.Logging),
132-
DockerLabels: s.manifest.ImageConfig.DockerLabels,
133-
DesiredCountLambda: desiredCountLambda.String(),
134-
EnvControllerLambda: envControllerLambda.String(),
135-
Storage: storage,
136-
Network: convertNetworkConfig(s.manifest.Network),
137-
EntryPoint: entrypoint,
138-
Command: command,
139-
DependsOn: dependencies,
121+
Variables: s.manifest.BackendServiceConfig.Variables,
122+
Secrets: s.manifest.BackendServiceConfig.Secrets,
123+
NestedStack: outputs,
124+
Sidecars: sidecars,
125+
Autoscaling: autoscaling,
126+
CapacityProviders: capacityProviders,
127+
DesiredCountOnSpot: desiredCountOnSpot,
128+
ExecuteCommand: convertExecuteCommand(&s.manifest.ExecuteCommand),
129+
WorkloadType: manifest.BackendServiceType,
130+
HealthCheck: s.manifest.BackendServiceConfig.ImageConfig.HealthCheckOpts(),
131+
LogConfig: convertLogging(s.manifest.Logging),
132+
DockerLabels: s.manifest.ImageConfig.DockerLabels,
133+
DesiredCountLambda: desiredCountLambda.String(),
134+
EnvControllerLambda: envControllerLambda.String(),
135+
Storage: storage,
136+
Network: convertNetworkConfig(s.manifest.Network),
137+
EntryPoint: entrypoint,
138+
Command: command,
139+
DependsOn: dependencies,
140+
CredentialsParameter: aws.StringValue(s.manifest.ImageConfig.Credentials),
140141
ServiceDiscoveryEndpoint: s.rc.ServiceDiscoveryEndpoint,
141142
})
142143
if err != nil {

internal/pkg/deploy/cloudformation/stack/lb_web_svc.go

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -157,29 +157,30 @@ func (s *LoadBalancedWebService) Template() (string, error) {
157157
allowedSourceIPs = *s.manifest.AllowedSourceIps
158158
}
159159
content, err := s.parser.ParseLoadBalancedWebService(template.WorkloadOpts{
160-
Variables: s.manifest.Variables,
161-
Secrets: s.manifest.Secrets,
162-
Aliases: aliases,
163-
NestedStack: outputs,
164-
Sidecars: sidecars,
165-
LogConfig: convertLogging(s.manifest.Logging),
166-
DockerLabels: s.manifest.ImageConfig.DockerLabels,
167-
Autoscaling: autoscaling,
168-
CapacityProviders: capacityProviders,
169-
DesiredCountOnSpot: desiredCountOnSpot,
170-
ExecuteCommand: convertExecuteCommand(&s.manifest.ExecuteCommand),
171-
WorkloadType: manifest.LoadBalancedWebServiceType,
172-
HealthCheck: s.manifest.ImageConfig.HealthCheckOpts(),
173-
HTTPHealthCheck: convertHTTPHealthCheck(&s.manifest.HealthCheck),
174-
AllowedSourceIps: allowedSourceIPs,
175-
RulePriorityLambda: rulePriorityLambda.String(),
176-
DesiredCountLambda: desiredCountLambda.String(),
177-
EnvControllerLambda: envControllerLambda.String(),
178-
Storage: storage,
179-
Network: convertNetworkConfig(s.manifest.Network),
180-
EntryPoint: entrypoint,
181-
Command: command,
182-
DependsOn: dependencies,
160+
Variables: s.manifest.Variables,
161+
Secrets: s.manifest.Secrets,
162+
Aliases: aliases,
163+
NestedStack: outputs,
164+
Sidecars: sidecars,
165+
LogConfig: convertLogging(s.manifest.Logging),
166+
DockerLabels: s.manifest.ImageConfig.DockerLabels,
167+
Autoscaling: autoscaling,
168+
CapacityProviders: capacityProviders,
169+
DesiredCountOnSpot: desiredCountOnSpot,
170+
ExecuteCommand: convertExecuteCommand(&s.manifest.ExecuteCommand),
171+
WorkloadType: manifest.LoadBalancedWebServiceType,
172+
HealthCheck: s.manifest.ImageConfig.HealthCheckOpts(),
173+
HTTPHealthCheck: convertHTTPHealthCheck(&s.manifest.HealthCheck),
174+
AllowedSourceIps: allowedSourceIPs,
175+
RulePriorityLambda: rulePriorityLambda.String(),
176+
DesiredCountLambda: desiredCountLambda.String(),
177+
EnvControllerLambda: envControllerLambda.String(),
178+
Storage: storage,
179+
Network: convertNetworkConfig(s.manifest.Network),
180+
EntryPoint: entrypoint,
181+
Command: command,
182+
DependsOn: dependencies,
183+
CredentialsParameter: aws.StringValue(s.manifest.ImageConfig.Credentials),
183184
ServiceDiscoveryEndpoint: s.rc.ServiceDiscoveryEndpoint,
184185
})
185186
if err != nil {

internal/pkg/deploy/cloudformation/stack/scheduled_job.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -163,20 +163,21 @@ func (j *ScheduledJob) Template() (string, error) {
163163
}
164164

165165
content, err := j.parser.ParseScheduledJob(template.WorkloadOpts{
166-
Variables: j.manifest.Variables,
167-
Secrets: j.manifest.Secrets,
168-
NestedStack: outputs,
169-
Sidecars: sidecars,
170-
ScheduleExpression: schedule,
171-
StateMachine: stateMachine,
172-
HealthCheck: j.manifest.ImageConfig.HealthCheckOpts(),
173-
LogConfig: convertLogging(j.manifest.Logging),
174-
DockerLabels: j.manifest.ImageConfig.DockerLabels,
175-
Storage: storage,
176-
Network: convertNetworkConfig(j.manifest.Network),
177-
EntryPoint: entrypoint,
178-
Command: command,
179-
DependsOn: dependencies,
166+
Variables: j.manifest.Variables,
167+
Secrets: j.manifest.Secrets,
168+
NestedStack: outputs,
169+
Sidecars: sidecars,
170+
ScheduleExpression: schedule,
171+
StateMachine: stateMachine,
172+
HealthCheck: j.manifest.ImageConfig.HealthCheckOpts(),
173+
LogConfig: convertLogging(j.manifest.Logging),
174+
DockerLabels: j.manifest.ImageConfig.DockerLabels,
175+
Storage: storage,
176+
Network: convertNetworkConfig(j.manifest.Network),
177+
EntryPoint: entrypoint,
178+
Command: command,
179+
DependsOn: dependencies,
180+
CredentialsParameter: aws.StringValue(j.manifest.ImageConfig.Credentials),
180181
ServiceDiscoveryEndpoint: j.rc.ServiceDiscoveryEndpoint,
181182

182183
EnvControllerLambda: envControllerLambda.String(),

internal/pkg/manifest/svc_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ name: frontend
2727
type: "Load Balanced Web Service"
2828
image:
2929
location: foo/bar
30+
credentials: some arn
3031
port: 80
3132
cpu: 512
3233
memory: 1024
@@ -80,6 +81,7 @@ environments:
8081
ImageConfig: ImageWithPortAndHealthcheck{
8182
ImageWithPort: ImageWithPort{Image: Image{Build: BuildArgsOrString{},
8283
Location: aws.String("foo/bar"),
84+
Credentials: aws.String("some arn"),
8385
}, Port: aws.Uint16(80)},
8486
},
8587
RoutingRule: RoutingRule{

internal/pkg/manifest/workload.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ type Workload struct {
7272
type Image struct {
7373
Build BuildArgsOrString `yaml:"build"` // Build an image from a Dockerfile.
7474
Location *string `yaml:"location"` // Use an existing image instead.
75+
Credentials *string `yaml:"credentials"` // ARN of the secret containing the private repository credentials.
7576
DockerLabels map[string]string `yaml:"labels,flow"` // Apply Docker labels to the container at runtime.
7677
DependsOn map[string]string `yaml:"depends_on,flow"` // Add any sidecar dependencies.
7778
}

internal/pkg/template/workload.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,14 @@ type WorkloadOpts struct {
252252
ServiceDiscoveryEndpoint string
253253

254254
// Additional options for service templates.
255-
WorkloadType string
256-
HealthCheck *ecs.HealthCheck
257-
HTTPHealthCheck HTTPHealthCheckOpts
258-
AllowedSourceIps []string
259-
RulePriorityLambda string
260-
DesiredCountLambda string
261-
EnvControllerLambda string
255+
WorkloadType string
256+
HealthCheck *ecs.HealthCheck
257+
HTTPHealthCheck HTTPHealthCheckOpts
258+
AllowedSourceIps []string
259+
RulePriorityLambda string
260+
DesiredCountLambda string
261+
EnvControllerLambda string
262+
CredentialsParameter string
262263

263264
// Additional options for job templates.
264265
ScheduleExpression string

site/content/docs/include/image-config.en.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ All paths are relative to your workspace root.
3434
Instead of building a container from a Dockerfile, you can specify an existing image name. Mutually exclusive with [`image.build`](#image-build).
3535
The `location` field follows the same definition as the [`image` parameter](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html#container_definition_image) in the Amazon ECS task definition.
3636

37+
<span class="parent-field">image.</span><a id="image-credential" href="#image-credential" class="field">`credentials`</a> <span class="type">String</span>
38+
An optional credentials arn for private repository. The `credentials` field follows the same definition as the [`credentialsParameter`](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/private-auth.html) in the Amazon ECS task definition.
39+
3740
<span class="parent-field">image.</span><a id="image-port" href="#image-port" class="field">`port`</a> <span class="type">Integer</span>
3841
The port exposed in your Dockerfile. Copilot should parse this value for you from your `EXPOSE` instruction.
3942

@@ -54,4 +57,4 @@ image:
5457
nginx: start
5558
startup: success
5659
```
57-
In the above example, the task's main container will only start after the `nginx` sidecar has started and the `startup` container has completed successfully.
60+
In the above example, the task's main container will only start after the `nginx` sidecar has started and the `startup` container has completed successfully.

templates/workloads/partials/cf/workload-container.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,8 @@
3232
Retries: {{.HealthCheck.Retries}}
3333
StartPeriod: {{.HealthCheck.StartPeriod}}
3434
Timeout: {{.HealthCheck.Timeout}}
35+
{{- end}}
36+
{{- if .CredentialsParameter}}
37+
RepositoryCredentials:
38+
CredentialsParameter: {{.CredentialsParameter}}
3539
{{- end}}

0 commit comments

Comments
 (0)