aws / amazon-ecs-cli

The Amazon ECS CLI enables users to run their applications on ECS/Fargate using the Docker Compose file format, quickly provision resources, push/pull images in ECR, and monitor running applications on ECS/Fargate.
https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_CLI.html
Other
1.76k stars 301 forks source link

Add "dry run" to compose cmd #588

Open allisaurus opened 6 years ago

allisaurus commented 6 years ago

Summary

Per the request in https://github.com/aws/amazon-ecs-cli/issues/569 , add a "dry run" or "test" functionality to compose to confirm provided values are valid prior to creating a task.

leriel commented 3 years ago

A little workaround for anyone who needs to get the json without actually creating any aws resources

ecs-cli compose -f docker-compose.yml --verbose --region fail create|perl -nle'print $& while m{(?<=TaskDefinition=).*}g'|jq -r

Critical parts:

Parts that make life easier:

Example docker-compose.yml:

version: '2'

services:
  nginx:
    image: nginx:latest
    network_mode: "bridge"
    restart: always
    logging:
      driver: awslogs
      options:
        awslogs-region: eu-central-1
        awslogs-group: test-loggroup
        awslogs-stream-prefix: nginx

Example raw output (ecs-cli compose -f docker-compose.yml --verbose --region fail create):

DEBU[0000] Parsing the compose yaml...
DEBU[0000] Docker Compose version found: 2
DEBU[0000] Parsing v1/2 project...
DEBU[0000] Opening compose files: docker-compose.yml
WARN[0000] Skipping unsupported YAML option for service...  option name=network_mode service name=nginx
WARN[0000] Skipping unsupported YAML option for service...  option name=networks service name=nginx
WARN[0000] Skipping unsupported YAML option for service...  option name=restart service name=nginx
DEBU[0000] [0/1] [nginx]: Adding
DEBU[0000] Parsing the ecs-params yaml...
DEBU[0000] Parsing the ecs-registry-creds yaml...
DEBU[0000] Transforming yaml to task definition...
DEBU[0000] Finding task definition in cache or creating if needed  TaskDefinition="{\n  ContainerDefinitions: [{\n      Command: [],\n      Cpu: 0,\n      DnsSearchDomains: [],\n      DnsServers: [],\n      DockerLabels: {\n\n      },\n      DockerSecurityOptions: [],\n      EntryPoint: [],\n      Environment: [],\n      Essential: true,\n      ExtraHosts: [],\n      Image: \"nginx:latest\",\n      Links: [],\n      LinuxParameters: {\n        Capabilities: {\n\n        },\n        Devices: []\n      },\n      LogConfiguration: {\n        LogDriver: \"awslogs\",\n        Options: {\n          awslogs-stream-prefix: \"nginx\",\n          awslogs-group: \"test-loggroup\",\n          awslogs-region: \"eu-central-1\"\n        }\n      },\n      Memory: 512,\n      MountPoints: [],\n      Name: \"nginx\",\n      PortMappings: [],\n      Privileged: false,\n      PseudoTerminal: false,\n      ReadonlyRootFilesystem: false,\n      Ulimits: [],\n      VolumesFrom: []\n    }],\n  Cpu: \"\",\n  ExecutionRoleArn: \"\",\n  Family: \"tmp\",\n  Memory: \"\",\n  NetworkMode: \"\",\n  TaskRoleArn: \"\",\n  Volumes: []\n}"
ERRO[0001] Error registering task definition             error="RequestError: send request failed\ncaused by: Post https://ecs.fail.amazonaws.com/: dial tcp: lookup ecs.fail.amazonaws.com on 1.1.1.1:53: no such host" family=tmp
ERRO[0001] Create task definition failed                 error="RequestError: send request failed\ncaused by: Post https://ecs.fail.amazonaws.com/: dial tcp: lookup ecs.fail.amazonaws.com on 1.1.1.1:53: no such host"
FATA[0001] RequestError: send request failed
caused by: Post https://ecs.fail.amazonaws.com/: dial tcp: lookup ecs.fail.amazonaws.com on 1.1.1.1:53: no such host

Example formatted output (ecs-cli compose -f docker-compose.yml --verbose --region fail create|perl -nle'print $& while m{(?<=TaskDefinition=).*}g'|jq -r):

{
  ContainerDefinitions: [{
      Command: [],
      Cpu: 0,
      DnsSearchDomains: [],
      DnsServers: [],
      DockerLabels: {

      },
      DockerSecurityOptions: [],
      EntryPoint: [],
      Environment: [],
      Essential: true,
      ExtraHosts: [],
      Image: "nginx:latest",
      Links: [],
      LinuxParameters: {
        Capabilities: {

        },
        Devices: []
      },
      LogConfiguration: {
        LogDriver: "awslogs",
        Options: {
          awslogs-region: "eu-central-1",
          awslogs-stream-prefix: "nginx",
          awslogs-group: "test-loggroup"
        }
      },
      Memory: 512,
      MountPoints: [],
      Name: "nginx",
      PortMappings: [],
      Privileged: false,
      PseudoTerminal: false,
      ReadonlyRootFilesystem: false,
      Ulimits: [],
      VolumesFrom: []
    }],
  Cpu: "",
  ExecutionRoleArn: "",
  Family: "tmp",
  Memory: "",
  NetworkMode: "",
  TaskRoleArn: "",
  Volumes: []
}
rulatir commented 2 months ago

Not including a dry-run option in any command interface that manages costly infrastructure should be banned.