amazon-ecs-fargate-cdk-v2-cicd icon indicating copy to clipboard operation
amazon-ecs-fargate-cdk-v2-cicd copied to clipboard

container initial port

Open davidlondono opened this issue 2 years ago • 9 comments

The initial port 5000 cannot be deployed as the initial image doesn't have this port enabled and fail to health check

davidlondono avatar Nov 27 '23 23:11 davidlondono

Hi @davidlondono -

Thanks for reporting the issue you're facing.

There is an addPortMappings section in the cdk code which should accomplish this. See https://github.com/search?q=repo%3Aaws-samples%2Famazon-ecs-fargate-cdk-v2-cicd%205000&type=code

Possibly something has changed in the CDK libs or how things are getting deployed.

Do you have any more information, logs, or details you can share?

Feel free to ping me on slack @mimjasov

jasonmimick-aws avatar Dec 21 '23 14:12 jasonmimick-aws

Hi @jasonmimick-aws, but there is no http service (with a /health endpoint) for the amazonlinux:2022 image running on port 5000, so the initial deployment will get stuck when ECS is provisioned, isn't it?

https://github.com/aws-samples/amazon-ecs-fargate-cdk-v2-cicd/blob/a1ad3e7cdc4e7ca32a328f135f2a20cbf45e75d4/cdk-v2/lib/ecs_cdk-stack.ts#L93

Thanks

rverton avatar Jan 25 '24 10:01 rverton

@jasonmimick-aws My stack is also stuck in progress endlessly. Is there a different image and port number we can use for initial deployment?

saurabhmarwaha avatar Jan 30 '24 07:01 saurabhmarwaha

Hey @saurabhmarwaha, you can use public.ecr.aws/nginx/nginx-unprivileged as a 'dummy' container. I'm using it with port 8080. If you want/need port 80, you can use http://public.ecr.aws/nginx/nginx. They are also available as ARM containers.

rverton avatar Jan 30 '24 07:01 rverton

@rverton Container / Task is still taking unusually longer with below changes due to which stack continues to be In progress status. Is that how you are using a dummy container.

const baseImage = 'public.ecr.aws/nginx/nginx-unprivileged'

container.addPortMappings({
  containerPort: **8080**,
  protocol: ecs.Protocol.TCP
});

saurabhmarwaha avatar Jan 30 '24 08:01 saurabhmarwaha

@rverton Container / Task is still taking unusually longer with below changes due to which stack continues to be In progress status. Is that how you are using a dummy container.

const baseImage = 'public.ecr.aws/nginx/nginx-unprivileged'

container.addPortMappings({
  containerPort: **8080**,
  protocol: ecs.Protocol.TCP
});

You also need to adjust the health check because the nginx container will not have a /health endpoint:

    const fgService = new ecs_patterns.ApplicationLoadBalancedFargateService(this, `${id}-ecs-service`, {
      cluster,
      // ...
    });

    fgService.targetGroup.configureHealthCheck({
      path: "/",
    });

rverton avatar Jan 30 '24 08:01 rverton

Still no progress. Stack is stuck in progress and task stopped eventually

const baseImage = 'public.ecr.aws/nginx/nginx-unprivileged'
const container = taskDef.addContainer('nodejs-docker-example', {
  image: ecs.ContainerImage.fromRegistry(baseImage),
  memoryLimitMiB: 256,
  cpu: 256,
  logging
});

container.addPortMappings({
  containerPort: 8080,
  protocol: ecs.Protocol.TCP
});

const fargateService = new ecs_patterns.ApplicationLoadBalancedFargateService(this, "ecs-service", {
  cluster: cluster,
  taskDefinition: taskDef,
  publicLoadBalancer: true,
  desiredCount: 1,
  listenerPort: 80,
});

fargateService.targetGroup.configureHealthCheck({
  path: "/",
});

Task stopped at: 2024-01-30T08:41:02.149Z CannotPullContainerError: pull image manifest has been retried 5 time(s): failed to resolve ref public.ecr.aws/nginx/nginx-unprivileged:latest: failed to do request: Head "https://public.ecr.aws/v2/nginx/nginx-unprivileged/manifests/latest": dial tcp 75.2.101.78:443: i/o timeout

Container

Container-2

saurabhmarwaha avatar Jan 30 '24 08:01 saurabhmarwaha

As I understand this error, ECS is not able to pull the container. Does your ECS service have a route to the public ECR repository?

rverton avatar Jan 30 '24 08:01 rverton

@rverton I believe you mean if subnet where cluster is created have access to Internet (IGW). I will check the routing and will verify. Could be related to Auto-assign public IP.

Will come back to in a few hours..Here it's 4:00 am..Getting some sleep...:)

saurabhmarwaha avatar Jan 30 '24 09:01 saurabhmarwaha