Coverage for src/container_collection/fargate/make_fargate_task.py: 100%

2 statements  

« prev     ^ index     » next       coverage.py v7.1.0, created at 2024-09-25 18:23 +0000

1def make_fargate_task( 

2 name: str, 

3 image: str, 

4 region: str, 

5 user: str, 

6 vcpus: int, 

7 memory: int, 

8 task_role_arn: str, 

9 execution_role_arn: str, 

10) -> dict: 

11 """ 

12 Create Fargate task definition. 

13 

14 Docker images on the Docker Hub registry are available by default, and can 

15 be specified using ``image:tag``. Otherwise, use ``repository/image:tag``. 

16 

17 Parameters 

18 ---------- 

19 name 

20 Task definition name. 

21 image 

22 Docker image. 

23 region 

24 Logging region. 

25 user 

26 User name prefix for task name. 

27 vcpus 

28 Hard limit of CPU units to present to the task. 

29 memory 

30 Hard limit of memory to present to the task. 

31 task_role_arn 

32 ARN for IAM role for the task container. 

33 execution_role_arn : str 

34 ARN for IAM role for the container agent. 

35 

36 Returns 

37 ------- 

38 : 

39 Task definition. 

40 """ 

41 

42 return { 

43 "containerDefinitions": [ 

44 { 

45 "name": f"{user}_{name}", 

46 "image": image, 

47 "essential": True, 

48 "portMappings": [], 

49 "environment": [], 

50 "mountPoints": [], 

51 "volumesFrom": [], 

52 "logConfiguration": { 

53 "logDriver": "awslogs", 

54 "options": { 

55 "awslogs-group": f"/ecs/{user}_{name}", 

56 "awslogs-region": region, 

57 "awslogs-stream-prefix": "ecs", 

58 "awslogs-create-group": "true", 

59 }, 

60 }, 

61 } 

62 ], 

63 "family": f"{user}_{name}", 

64 "networkMode": "awsvpc", 

65 "requiresCompatibilities": ["FARGATE"], 

66 "taskRoleArn": task_role_arn, 

67 "executionRoleArn": execution_role_arn, 

68 "cpu": str(vcpus), 

69 "memory": str(memory), 

70 }