6464import software .amazon .awssdk .services .ecs .model .NetworkMode ;
6565import software .amazon .awssdk .services .ecs .model .PropagateTags ;
6666import software .amazon .awssdk .services .ecs .model .RegisterTaskDefinitionResponse ;
67+ import software .amazon .awssdk .services .ecs .model .RepositoryCredentials ;
6768import software .amazon .awssdk .services .ecs .model .RunTaskResponse ;
6869import software .amazon .awssdk .services .ecs .model .RuntimePlatform ;
6970import software .amazon .awssdk .services .ecs .model .Tag ;
@@ -108,6 +109,7 @@ public class EcsBackend extends AbstractContainerBackend {
108109 private List <String > securityGroups ;
109110 private int totalWaitMs ;
110111 private String cluster ;
112+ private String defaultRepositoryCredentialsParameter ;
111113
112114 @ Inject
113115 private IProxySpecProvider proxySpecProvider ;
@@ -134,7 +136,8 @@ public void initialize() {
134136 enableCloudWatch = environment .getProperty ("proxy.ecs.enable-cloudwatch" , Boolean .class , false );
135137 cloudWatchGroupPrefix = environment .getProperty ("proxy.ecs.cloud-watch-group-prefix" , String .class , "/ecs/" );
136138 cloudWatchRegion = environment .getProperty ("proxy.ecs.cloud-watch-region" , String .class , getProperty (PROPERTY_REGION ));
137- cloudWatchStreamPrefix = environment .getProperty ("proxy.ecs.cloud-watch-stream-prefix" , String .class , "ecs" );
139+ cloudWatchStreamPrefix = environment .getProperty ("proxy.ecs.cloud-watch-stream-prefix" , String .class , "ecs" );
140+ defaultRepositoryCredentialsParameter = environment .getProperty ("proxy.ecs.default-repository-credentials-parameter" , String .class );
138141
139142 if (cluster == null ) {
140143 throw new IllegalStateException ("Error in configuration of ECS backend: proxy.ecs.cluster not set to name of cluster" );
@@ -242,7 +245,8 @@ public Proxy startContainer(Authentication user, Container initialContainer, Con
242245 if (task .lastStatus ().equals ("RUNNING" )) {
243246 return Retrying .SUCCESS ;
244247 } else if (!STARTING_STATES .contains (task .lastStatus ()) || !task .desiredStatus ().equals ("RUNNING" )) {
245- slog .warn (proxy , String .format ("ECS container failed: task not running, stopCode: '%s', stoppingAt: '%s', stoppedAt: '%s', stoppedReason: '%s'" , task .stopCode (), task .stoppingAt (), task .stoppedAt (), task .stoppedReason ()));
248+ slog .warn (proxy , String .format ("ECS container failed: task not running, stopCode: '%s', stoppingAt: '%s', stoppedAt: '%s', stoppedReason: '%s'" , task .stopCode (), task .stoppingAt (), task .stoppedAt (),
249+ task .stoppedReason ()));
246250 return new Retrying .Result (false , false );
247251 }
248252 }
@@ -300,18 +304,24 @@ private String getTaskDefinition(Authentication user, ContainerSpec spec, EcsSpe
300304 // automatically used in the cloudwatch stream name
301305 String containerName = StringUtils .left (spec .getResourceName ().getValueOrDefault ("sp-container-" + proxy .getId () + "-" + initialContainer .getIndex ()), 255 );
302306
303- RegisterTaskDefinitionResponse registerTaskDefinitionResponse = ecsClient .registerTaskDefinition (builder -> builder
307+ ContainerDefinition .Builder containerDefinitionBuilder = ContainerDefinition .builder ()
308+ .name (containerName )
309+ .image (spec .getImage ().getValue ())
310+ .command (spec .getCmd ().getValueOrNull ())
311+ .environment (env )
312+ .stopTimeout (2 )
313+ .dockerLabels (dockerLabels )
314+ .logConfiguration (getLogConfiguration (proxy .getSpecId ()))
315+ .mountPoints (volumes .getSecond ());
316+
317+ String credentials = specExtension .getEcsRepositoryCredentialsParameter ().getValueOrDefault (defaultRepositoryCredentialsParameter );
318+ if (credentials != null && !credentials .isBlank ()) {
319+ containerDefinitionBuilder .repositoryCredentials (RepositoryCredentials .builder ().credentialsParameter (credentials ).build ());
320+ }
321+
322+ RegisterTaskDefinitionResponse registerTaskDefinitionResponse = ecsClient .registerTaskDefinition (builder -> builder
304323 .family ("sp-task-definition-" + proxy .getId ()) // family is a name for the task definition
305- .containerDefinitions (ContainerDefinition .builder ()
306- .name (containerName )
307- .image (spec .getImage ().getValue ())
308- .command (spec .getCmd ().getValueOrNull ())
309- .environment (env )
310- .stopTimeout (2 )
311- .dockerLabels (dockerLabels )
312- .logConfiguration (getLogConfiguration (proxy .getSpecId ()))
313- .mountPoints (volumes .getSecond ())
314- .build ())
324+ .containerDefinitions (containerDefinitionBuilder .build ())
315325 .networkMode (NetworkMode .AWSVPC ) // only option when using fargate
316326 .requiresCompatibilities (Compatibility .FARGATE )
317327 .cpu (spec .getCpuRequest ().getValue ()) // required by fargate
0 commit comments