@@ -209,11 +209,11 @@ func (d *detector) checkApplication(ctx context.Context, app *model.Application,
209
209
d .logger .Info (fmt .Sprintf ("application %s has live ecs definition files" , app .Id ))
210
210
211
211
// Ignore some fields whech are not necessary or unable to detect diff.
212
- ignoreParameters (liveManifests , headManifests )
212
+ live , head := ignoreParameters (liveManifests , headManifests )
213
213
214
214
result , err := provider .Diff (
215
- liveManifests ,
216
- headManifests ,
215
+ live ,
216
+ head ,
217
217
diff .WithEquateEmpty (),
218
218
diff .WithIgnoreAddingMapKeys (),
219
219
diff .WithCompareNumberAndNumericString (),
@@ -237,8 +237,8 @@ func (d *detector) checkApplication(ctx context.Context, app *model.Application,
237
237
// TODO: Maybe we should check diff of following fields when not set in the head manifests in some way. Currently they are ignored:
238
238
// - service.PlatformVersion
239
239
// - service.RoleArn
240
- func ignoreParameters (liveManifests provider.ECSManifests , headManifests provider.ECSManifests ) {
241
- liveService := liveManifests .ServiceDefinition
240
+ func ignoreParameters (liveManifests provider.ECSManifests , headManifests provider.ECSManifests ) ( live , head provider. ECSManifests ) {
241
+ liveService := * liveManifests .ServiceDefinition
242
242
liveService .CreatedAt = nil
243
243
liveService .CreatedBy = nil
244
244
liveService .Events = nil
@@ -251,9 +251,10 @@ func ignoreParameters(liveManifests provider.ECSManifests, headManifests provide
251
251
liveService .TaskDefinition = nil // TODO: Find a way to compare the task definition if possible.
252
252
liveService .TaskSets = nil
253
253
254
- liveTask := liveManifests .TaskDefinition
255
- // When liveTask does not exist, e.g. right after the service is created.
256
- if liveTask != nil {
254
+ var liveTask types.TaskDefinition
255
+ if liveManifests .TaskDefinition != nil {
256
+ // When liveTask does not exist, e.g. right after the service is created.
257
+ liveTask = * liveManifests .TaskDefinition
257
258
liveTask .RegisteredAt = nil
258
259
liveTask .RegisteredBy = nil
259
260
liveTask .RequiresAttributes = nil
@@ -267,7 +268,7 @@ func ignoreParameters(liveManifests provider.ECSManifests, headManifests provide
267
268
}
268
269
}
269
270
270
- headService := headManifests .ServiceDefinition
271
+ headService := * headManifests .ServiceDefinition
271
272
if headService .PlatformVersion == nil {
272
273
// The LATEST platform version is used by default if PlatformVersion is not specified.
273
274
// See https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_CreateService.html#ECS-CreateService-request-platformVersion.
@@ -279,37 +280,43 @@ func ignoreParameters(liveManifests provider.ECSManifests, headManifests provide
279
280
headService .RoleArn = liveService .RoleArn
280
281
}
281
282
if headService .NetworkConfiguration != nil && headService .NetworkConfiguration .AwsvpcConfiguration != nil {
282
- awsvpcCfg := headService .NetworkConfiguration .AwsvpcConfiguration
283
+ awsvpcCfg := * headService .NetworkConfiguration .AwsvpcConfiguration
284
+ awsvpcCfg .Subnets = slices .Clone (awsvpcCfg .Subnets )
283
285
slices .Sort (awsvpcCfg .Subnets )
284
286
if len (awsvpcCfg .AssignPublicIp ) == 0 {
285
287
// AssignPublicIp is DISABLED by default.
286
288
// See https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_AwsVpcConfiguration.html#ECS-Type-AwsVpcConfiguration-assignPublicIp.
287
289
awsvpcCfg .AssignPublicIp = types .AssignPublicIpDisabled
288
290
}
291
+ headService .NetworkConfiguration = & types.NetworkConfiguration {AwsvpcConfiguration : & awsvpcCfg }
289
292
}
290
293
291
294
// Sort the subnets of the live service as well
292
295
if liveService .NetworkConfiguration != nil && liveService .NetworkConfiguration .AwsvpcConfiguration != nil {
293
- awsvpcCfg := liveService .NetworkConfiguration .AwsvpcConfiguration
296
+ awsvpcCfg := * liveService .NetworkConfiguration .AwsvpcConfiguration
297
+ awsvpcCfg .Subnets = slices .Clone (awsvpcCfg .Subnets )
294
298
slices .Sort (awsvpcCfg .Subnets )
299
+ liveService .NetworkConfiguration = & types.NetworkConfiguration {AwsvpcConfiguration : & awsvpcCfg }
295
300
}
296
301
297
302
// TODO: In order to check diff of the tags, we need to add pipecd-managed tags and sort.
298
303
liveService .Tags = nil
299
304
headService .Tags = nil
300
305
301
- headTask := headManifests .TaskDefinition
306
+ headTask := * headManifests .TaskDefinition
302
307
headTask .Status = types .TaskDefinitionStatusActive // If livestate's status is not ACTIVE, we should re-deploy a new task definition.
303
- if liveTask != nil {
308
+ if liveManifests . TaskDefinition != nil {
304
309
headTask .Compatibilities = liveTask .Compatibilities // Users can specify Compatibilities in a task definition file, but it is not used when registering a task definition.
305
310
}
306
311
312
+ headTask .ContainerDefinitions = slices .Clone (headManifests .TaskDefinition .ContainerDefinitions )
307
313
for i := range headTask .ContainerDefinitions {
308
314
cd := & headTask .ContainerDefinitions [i ]
309
315
if cd .Essential == nil {
310
316
// Essential is true by default. See https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerDefinition.html#ECS-Type-ContainerDefinition-es.
311
317
cd .Essential = aws .Bool (true )
312
318
}
319
+ cd .PortMappings = slices .Clone (cd .PortMappings )
313
320
for j := range cd .PortMappings {
314
321
pm := & cd .PortMappings [j ]
315
322
if len (pm .Protocol ) == 0 {
@@ -319,6 +326,10 @@ func ignoreParameters(liveManifests provider.ECSManifests, headManifests provide
319
326
pm .HostPort = nil // We ignore diff of HostPort because it has several default values.
320
327
}
321
328
}
329
+
330
+ live = provider.ECSManifests {ServiceDefinition : & liveService , TaskDefinition : & liveTask }
331
+ head = provider.ECSManifests {ServiceDefinition : & headService , TaskDefinition : & headTask }
332
+ return live , head
322
333
}
323
334
324
335
func (d * detector ) loadConfigs (app * model.Application , repo git.Repo , headCommit git.Commit ) (provider.ECSManifests , error ) {
0 commit comments