@@ -861,35 +861,13 @@ func modifyTaskState(wf *AddWorkflow) (nextState optionals.Optional[AddWorkflowS
861861 Value : aws .String (akitaCreationTagValue ),
862862 })
863863
864- pKey , pEnv := cfg .GetPostmanAPIKeyAndEnvironment ()
865- envs := []types.KeyValuePair {}
866- if pEnv != "" {
867- envs = append (envs , []types.KeyValuePair {
868- {Name : aws .String ("POSTMAN_ENV" ), Value : & pEnv },
869- }... )
870- }
871-
872- var entryPoint []string
873-
874- if collectionId != "" {
875- entryPoint = []string {"/postman-insights-agent" , "apidump" , "--collection" , collectionId }
876- } else {
877- entryPoint = []string {"/postman-insights-agent" , "apidump" , "--project" , projectId }
878- }
879-
880- agentContainer := types.ContainerDefinition {
881- Name : aws .String ("postman-insights-agent" ),
882- EntryPoint : entryPoint ,
883- Environment : append (envs , []types.KeyValuePair {
884- {Name : aws .String ("POSTMAN_API_KEY" ), Value : & pKey },
885- // Setting these environment variables will cause the traces to be tagged.
886- {Name : aws .String ("POSTMAN_AWS_REGION" ), Value : & wf .awsRegion },
887- {Name : aws .String ("POSTMAN_ECS_SERVICE" ), Value : & wf .ecsService },
888- {Name : aws .String ("POSTMAN_ECS_TASK" ), Value : & wf .ecsTaskDefinitionFamily },
889- }... ),
890- Essential : aws .Bool (false ),
891- Image : aws .String (postmanECRImage ),
892- }
864+ const isEssential = false
865+ agentContainer := makeAgentContainerDefinition (
866+ optionals .Some (wf .awsRegion ),
867+ optionals .Some (wf .ecsService ),
868+ optionals .Some (wf .ecsTaskDefinitionFamily ),
869+ isEssential ,
870+ )
893871
894872 // If running on EC2, a memory size is required if no task-level memory size is specified.
895873 // If running on Fargate, a task-level memory size is required, and the container-level
@@ -929,6 +907,61 @@ func modifyTaskState(wf *AddWorkflow) (nextState optionals.Optional[AddWorkflowS
929907 return awf_next (updateServiceState )
930908}
931909
910+ func makeAgentContainerDefinition (
911+ awsRegion optionals.Optional [string ],
912+ ecsService optionals.Optional [string ],
913+ ecsTaskDefinitionFamily optionals.Optional [string ],
914+ essential bool ,
915+ ) types.ContainerDefinition {
916+ pKey , pEnv := cfg .GetPostmanAPIKeyAndEnvironment ()
917+
918+ envs := []types.KeyValuePair {}
919+ addToEnv := func (name string , value string ) {
920+ envs = append (envs , types.KeyValuePair {
921+ Name : & name ,
922+ Value : & value ,
923+ })
924+ }
925+
926+ // This is a no-op if valueOpt is None.
927+ addOptToEnv := func (name string , valueOpt optionals.Optional [string ]) {
928+ value , exists := valueOpt .Get ()
929+ if exists {
930+ addToEnv (name , value )
931+ }
932+ }
933+
934+ if pEnv != "" {
935+ addToEnv ("POSTMAN_ENV" , pEnv )
936+ }
937+
938+ addToEnv ("POSTMAN_API_KEY" , pKey )
939+
940+ // Setting these optional environment variables will cause the traces to be
941+ // tagged.
942+ addOptToEnv ("POSTMAN_AWS_REGION" , awsRegion )
943+ addOptToEnv ("POSTMAN_ECS_SERVICE" , ecsService )
944+ addOptToEnv ("POSTMAN_ECS_TASK" , ecsTaskDefinitionFamily )
945+
946+ entryPoint := []string {
947+ "/postman-insights-agent" ,
948+ "apidump" ,
949+ "--project" ,
950+ projectId ,
951+ }
952+
953+ // XXX If we instantiate any new fields in the container definition here, we
954+ // need to remember to update the code in the ecs_console_utils and the
955+ // ecs_cloudformation_utils packages.
956+ return types.ContainerDefinition {
957+ Name : aws .String ("postman-insights-agent" ),
958+ EntryPoint : entryPoint ,
959+ Environment : envs ,
960+ Essential : aws .Bool (essential ),
961+ Image : aws .String (postmanECRImage ),
962+ }
963+ }
964+
932965// Update a service with the newly created task definition
933966func updateServiceState (wf * AddWorkflow ) (nextState optionals.Optional [AddWorkflowState ], err error ) {
934967 reportStep ("Update ECS Service" )
0 commit comments