tracker_env = { "AWS_DEFAULT_REGION": "eu-west-1", "AWS_REGION": "eu-west-1", "WL_SECRETS_MANAGER_KEY_NAME": "WhitelistKeys" } def tracker_def(script_name, with_selenium=True, environ_dict={}, tag='latest', with_actuary=False, memoryReservation=256, portMappings=[]): env = dict(tracker_env, **environ_dict) links = [] if with_selenium: links.append('selenium') if with_actuary: links.append('actuary') return { "command": ["/tracker/bin/launch.py", script_name] if script_name else [], "cpu": 0, "dnsSearchDomains": [], "dnsServers": [], "dockerSecurityOptions": [], "entryPoint": [], "environment": [{"name": k, "value": v} for k, v in env.items()], "essential": True, "image": "322697034778.dkr.ecr.eu-west-1.amazonaws.com/tracker:{}".format(tag), "links": links, "logConfiguration": { "logDriver": "awslogs", "options": { "awslogs-group": "ecs", "awslogs-region": "eu-west-1", "awslogs-stream-prefix": script_name, }, }, "memoryReservation": memoryReservation, "mountPoints": [], "name": "tracker", "portMappings": portMappings, "privileged": False, "readonlyRootFilesystem": False, "volumesFrom": [], } def tikpuppet(tag="latest", env_dict={}): return { "cpu": 0, "environment": [dict(name=k, value=v) for k, v in dict(tracker_env, **env_dict).items()], "essential": True, "image": f"322697034778.dkr.ecr.eu-west-1.amazonaws.com/tikpuppet:{tag}", "links": [], "logConfiguration": { "logDriver": "awslogs", "options": { "awslogs-group": "ecs", "awslogs-region": "eu-west-1", "awslogs-stream-prefix": "tikpuppet", }, }, "memoryReservation": 128, "mountPoints": [{"containerPath": "/dev/shm", "sourceVolume": "shm"}], "name": "tikpuppet", "portMappings": [{"containerPort": 5900, "hostPort": 0, "protocol": "tcp"}], "readonlyRootFilesystem": False, "volumesFrom": [], } def actuary(script_name, tag): return { "cpu": 0, "environment": [], "essential": True, "image": "322697034778.dkr.ecr.eu-west-1.amazonaws.com/actuary:{}".format('latest'), "links": [], "logConfiguration": { "logDriver": "awslogs", "options": { "awslogs-group": "actuary", "awslogs-region": "eu-west-1", "awslogs-stream-prefix": script_name, }, }, "memoryReservation": 128, "mountPoints": [], "name": "actuary", "portMappings": [], "readonlyRootFilesystem": False, "volumesFrom": [], } def selenium(script_name, with_tiksniff_proxy=False): links = [] envdict = {} if with_tiksniff_proxy: links = ['tiksniff'] envdict = { "HTTP_PROXY": "http://tiksniff:8080", "HTTPS_PROXY": "https://tiksniff:8080", "NO_PROXY": "localhost,127.0.0.1,localaddress,.localdomain.com", } return { "cpu": 0, "environment": [dict(name=k, value=v) for k,v in envdict.items()], "essential": True, "image": "selenium/standalone-chrome-debug:3.141.59-radium", # "image": "selenium/standalone-chrome-debug:3.12.0-cobalt", # "image": "selenium/standalone-chrome-debug:3.4.0-dysprosium", "links": links, "logConfiguration": { "logDriver": "awslogs", "options": { "awslogs-group": "selenium", "awslogs-region": "eu-west-1", "awslogs-stream-prefix": script_name, }, }, "memoryReservation": 128, "mountPoints": [{"containerPath": "/dev/shm", "sourceVolume": "shm"}], "name": "selenium", "portMappings": [{"containerPort": 5900, "hostPort": 0, "protocol": "tcp"}], "readonlyRootFilesystem": False, "volumesFrom": [], } # def tiksniff(script_name): # return { # "cpu": 0, # "environment": [{"name": "WL_PG_URI", "value": tracker_env['WL_PG_URI']}], # "essential": True, # "image": "322697034778.dkr.ecr.eu-west-1.amazonaws.com/tiksniff:{}".format('latest'), # "links": [], # "logConfiguration": { # "logDriver": "awslogs", # "options": { # "awslogs-group": "actuary", # "awslogs-region": "eu-west-1", # "awslogs-stream-prefix": script_name, # }, # }, # "memoryReservation": 128, # "mountPoints": [], # "name": "tiksniff", # "portMappings": [], # "readonlyRootFilesystem": False, # "volumesFrom": [], # } ecs_task_role_arn = "arn:aws:iam::322697034778:role/ecs-task" def tracker_task(script_name, with_selenium=False, environ_dict={}, tag='latest', with_actuary=False, memoryReservation=512, trackerPortMappings=[], with_tracker=True, with_tikpuppet=False): container_defs = [] if with_tracker: container_defs.append(tracker_def(script_name, with_selenium=with_selenium, environ_dict=environ_dict, tag=tag, with_actuary=with_actuary, memoryReservation=memoryReservation, portMappings=trackerPortMappings)) if with_selenium: container_defs.append(selenium(script_name)) if with_actuary: container_defs.append(actuary(script_name, tag)) if with_tikpuppet: container_defs.append(tikpuppet(tag=tag, env_dict=environ_dict)) assert len(container_defs) > 0, ( f"There should be at least one container definition with_tracker={with_tracker}, " f"with_actuary={with_actuary}, with_selenium={with_selenium}, with_tikpuppet={with_tikpuppet}" ) return { "containerDefinitions": container_defs, "family": "tracker-{}".format(script_name), "placementConstraints": [], "taskRoleArn": ecs_task_role_arn, "volumes": [{"host": {"sourcePath": "/dev/shm"}, "name": "shm"}] } def whitelist_api_task(tag='latest', include_xray=True): env = dict( tracker_env, WL_API_ECHO_STATEMENTS='false', WL_API_PRETTY_JSON='false', WL_API_ENABLE_ROLLBAR='true', WL_ENABLE_AWS_XRAY='true', WL_ES_SEARCH_HOST='', WL_ES_USE_AWS_SIGNING='true', AWS_XRAY_DAEMON_ADDRESS="xray-daemon:2000", ) container_defs = [ { "command": [], "cpu": 0, "dnsSearchDomains": [], "dnsServers": [], "dockerSecurityOptions": [], "entryPoint": [], "environment": [{"name": k, "value": v} for k, v in env.items()], "essential": True, "image": "322697034778.dkr.ecr.eu-west-1.amazonaws.com/whitelist-api:{}".format(tag), "links": ["xray-daemon"] if include_xray else [], "logConfiguration": { "logDriver": "awslogs", "options": { "awslogs-group": "api" if tag == 'latest' else 'api-candidate', "awslogs-region": "eu-west-1", "awslogs-stream-prefix": 'api', }, }, "memoryReservation": 512, "mountPoints": [], "name": "tracker", "portMappings": [ { "hostPort": 0, # for dynamic port mapping with the ALB "containerPort": 5000 } ], "privileged": False, "readonlyRootFilesystem": False, "volumesFrom": [], }, ] if include_xray: container_defs.append({ "name": "xray-daemon", "image": "amazon/aws-xray-daemon", "cpu": 32, "memoryReservation": 256, "portMappings": [ { "hostPort": 0, "containerPort": 2000, "protocol": "udp" } ], }) return { "containerDefinitions": container_defs, "family": "whitelist-api", "placementConstraints": [], "taskRoleArn": ecs_task_role_arn, }