Skip to content

Commit e726229

Browse files
authored
Update ECS Executor Readme (#12)
* add cicd pipeline * updates * Update the changelog * merge with develop * update executor * Add tests and logging statements * fix a test * Add a validation layer to the ECS instantiation step * Change some of the variable names * fix config key * Fix tests * minor typo * Update changelog date * Update changelog * Update readme and add banner * ensure that fargate policy link works * Update broken readme ling * Update broken readme link * Remove some of the Fargate references * update readme - remove my personal file name from config * Fix breaking change * Update readme * Update the policy to remove the specific aws account info * Clean up IAM policy
1 parent 34cc6ce commit e726229

7 files changed

+46
-178
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.4.0] - 2022-08-09
9+
10+
### Changed
11+
12+
- README.md file to include correct instructions on how to use the ECS executor.
13+
814
## [0.3.0] - 2022-08-09
915

1016
### Added

README.md

+21-21
Original file line numberDiff line numberDiff line change
@@ -2,75 +2,75 @@
22

33
<div align="center">
44

5-
![covalent logo](https://github.com/AgnostiqHQ/covalent/blob/master/doc/source/_static/dark.png#gh-dark-mode-only)
6-
![covalent logo](https://github.com/AgnostiqHQ/covalent/blob/master/doc/source/_static/light.png#gh-light-mode-only)
7-
8-
&nbsp;
5+
<img src="https://github.com/AgnostiqHQ/covalent-ecs-plugin/blob/main/doc/source/_static/aws_ecs_readme_banner.jpg" width=150%>
96

107
</div>
118

12-
## Covalent Fargate Plugin
9+
## Covalent ECS Plugin
1310

14-
Covalent is a Pythonic workflow tool used to execute tasks on advanced computing hardware. This executor plugin interfaces Covalent with AWS Fargate via the [Elastic Container Service](https://docs.aws.amazon.com/ecs/index.html). In order for workflows to be deployable, users must have AWS credentials attached to the [CovalentFargateExecutorPolicy](https://github.com/AgnostiqHQ/covalent-fargate-executor/infra/iam/CovalentFargateExecutorPolicy.json). Users will need additional permissions to provision or manage cloud infrastructure used by this plugin.
11+
Covalent is a Pythonic workflow tool used to execute tasks on advanced computing hardware. This executor plugin interfaces Covalent with AWS [Elastic Container Service](https://docs.aws.amazon.com/ecs/index.html) where the tasks are run using Fargate. In order for workflows to be deployable, users must have AWS credentials attached to the [CovalentECSExecutorPolicy](https://github.com/AgnostiqHQ/covalent-ecs-plugin/blob/main/infra/iam/CovalentECSExecutorPolicy.json). Users will need additional permissions to provision or manage cloud infrastructure used by this plugin.
1512

1613
To use this plugin with Covalent, clone this repository and install it using `pip`:
1714

1815
```
19-
git clone [email protected]:AgnostiqHQ/covalent-fargate-plugin.git
20-
cd covalent-fargate-plugin
16+
git clone [email protected]:AgnostiqHQ/covalent-ecs-plugin.git
17+
cd covalent-ecs-plugin
2118
pip install .
2219
```
2320

24-
Users must add the correct entries to their Covalent [configuration](https://covalent.readthedocs.io/en/latest/how_to/config/customization.html) to support the Fargate plugin. Below is an example which works using some basic infrastructure created for testing purposes:
21+
Users must add the correct entries to their Covalent [configuration](https://covalent.readthedocs.io/en/latest/how_to/config/customization.html) to support the ECS plugin. Below is an example which works using some basic infrastructure created for testing purposes:
2522

2623
```console
27-
[executors.fargate]
24+
[executors.ecs]
2825
credentials = "/home/user/.aws/credentials"
29-
profile = ""
26+
profile = "default"
3027
s3_bucket_name = "covalent-fargate-task-resources"
3128
ecr_repo_name = "covalent-fargate-task-images"
3229
ecs_cluster_name = "covalent-fargate-cluster"
3330
ecs_task_family_name = "covalent-fargate-tasks"
31+
ecs_task_execution_role_name = "ecsTaskExecutionRole"
3432
ecs_task_role_name = "CovalentFargateTaskRole"
33+
ecs_task_subnet_id = "subnet-871545e1"
34+
ecs_task_security_group_id = "sg-0043541a"
35+
ecs_task_log_group_name = "covalent-fargate-task-logs"
3536
vcpu = 0.25
3637
memory = 0.5
3738
cache_dir = "/tmp/covalent"
38-
ecs_task_subnets = "subnet-994c4697,subnet-861e43d9,subnet-779cc356,subnet-326a0e03,subnet-871545e1,subnet-6793732b"
39-
ecs_task_vpc = "vpc-b2bdd0cf"
40-
ecs_task_security_groups = "sg-0043541a"
4139
poll_freq = 10
42-
ecs_task_execution_role_name = "ecsTaskExecutionRole"
43-
ecs_task_log_group_name = "covalent-fargate-task-logs"
4440
```
4541

4642
Within a workflow, users can then decorate electrons using these default settings:
4743

4844
```python
4945
import covalent as ct
5046

51-
@ct.electron(executor="fargate")
47+
@ct.electron(executor="ecs")
5248
def my_task(x, y):
5349
return x + y
5450
```
5551

5652
or use a class object to customize the resources and other behavior:
5753

5854
```python
59-
executor = ct.executor.FargateExecutor(
55+
executor = ct.executor.ECSExecutor(
6056
vcpu=1,
61-
memory=2
57+
memory=2,
58+
ecs_task_subnet_id="subnet-871545e1",
59+
ecs_task_security_group_id="sg-0043541a"
6260
)
6361

6462
@ct.electron(executor=executor)
6563
def my_custom_task(x, y):
6664
return x + y
6765
```
6866

67+
Ensure that Docker is running on the client side machine before deploying the workflow.
68+
6969
For more information about how to get started with Covalent, check out the project [homepage](https://github.com/AgnostiqHQ/covalent) and the official [documentation](https://covalent.readthedocs.io/en/latest/).
7070

7171
## Release Notes
7272

73-
Release notes are available in the [Changelog](https://github.com/AgnostiqHQ/covalent-fargate-executor/blob/main/CHANGELOG.md).
73+
Release notes are available in the [Changelog](https://github.com/AgnostiqHQ/covalent-ecs-executor/blob/main/CHANGELOG.md).
7474

7575
## Citation
7676

@@ -81,4 +81,4 @@ Please use the following citation in any publications:
8181
8282
## License
8383

84-
Covalent is licensed under the GNU Affero GPL 3.0 License. Covalent may be distributed under other licenses upon request. See the [LICENSE](https://github.com/AgnostiqHQ/covalent-fargate-executor/blob/main/LICENSE) file or contact the [support team](mailto:[email protected]) for more details.
84+
Covalent is licensed under the GNU Affero GPL 3.0 License. Covalent may be distributed under other licenses upon request. See the [LICENSE](https://github.com/AgnostiqHQ/covalent-ecs-executor/blob/main/LICENSE) file or contact the [support team](mailto:[email protected]) for more details.

covalent_ecs_plugin/ecs.py

+2-67
Original file line numberDiff line numberDiff line change
@@ -20,71 +20,6 @@
2020

2121
"""AWS ECSExecutor plugin for the Covalent dispatcher."""
2222

23-
# Infrastructure required for this executor:
24-
# 1. VPC
25-
# - IPv4 CIDR: 10.0.0.0/16
26-
# 2. Private Subnets (1 per zone)
27-
# - IPv4 CIDR: 10.0.X.0/24
28-
# 3. Route Table
29-
# 4. Elastic IP
30-
# 5. NAT Gateway
31-
# 6. Outbound route to NAT Gateway
32-
# - 0.0.0.0/0 -> NAT Addr
33-
# 7. Security Group (empty)
34-
# 8. S3 Bucket
35-
# 9. ECR Repository
36-
# - Immutable tags
37-
# - KMS encryption
38-
# 10. ECS Cluster
39-
# 11. CloudWatch Log Group
40-
# 12. IAM Policy - CovalentFargateTaskExecutionPolicy (see below)
41-
# 13. IAM Role - CovalentFargateTaskExecutionRole
42-
# 14. IAM Policy - CovalentFargateTaskPolicy (see below)
43-
# 15. IAM Role - CovalentFargateTaskRole
44-
# 16. IAM Policy - CovalentFargateExecutorPolicy (see below)
45-
# 17. IAM Policy - CovalentFargateExecutorInfraPolicy (see below)
46-
# 18. ECS Task Definition - created at runtime
47-
# 19. ECS Task - created at runtime
48-
49-
50-
# IAM policies needed for the actions related to this executor:
51-
# 1. CovalentFargateExecutorPolicy: the policy needed to use the FargateExecutor, without
52-
# provisioning infrastructure -- see infra/iam/CovalentFargateExecutorPolicy.json
53-
# 2. CovalentFargateExecutorInfraPolicy: Same as above, except additionally allowing provisioning;
54-
# Below is an in-progress list.
55-
# - Action:
56-
# - logs:CreateLogGroup
57-
# - ecs:CreateCluster
58-
# - ecr:CreateRepository
59-
# - s3:CreateBucket
60-
# Resource: *
61-
# 3. CovalentFargateTaskExecutionPolicy: ECS task execution role's policy -- see
62-
# infra/iam/CovalentFargateTaskExecutionPolicy.json
63-
# 4. CovalentFargateTaskPolicy: ECS task's policy -- see infra/iam/CovalentFargateTaskPolicy.json
64-
65-
66-
# Network configuration:
67-
# 1. There are new changes in Fargate 1.4.0 which require the ECS agent to be able to communicate
68-
# to the internet in order to access ECR images. This means that either we use public subnets
69-
# in a VPC connected to an internet gateway, or we can use private subnets which route
70-
# 0.0.0.0/0 to one or more NAT gateways. If we choose the former option, it is important to
71-
# provide "assignPublicIp": "ENABLED" in the network configuration when calling ecs.run_task.
72-
# 2. For the purposes of testing this executor, the default VPC and default subnets are used in
73-
# us-east-1. These fall into the first category above.
74-
# 3. The recommended option for production is to use a set of private subnets all connected
75-
# to the same NAT gateway. This also will need a dedicated VPC.
76-
77-
78-
# Synchronization:
79-
# 1. Consider adding a sync/async bool option to execute. Sync should poll the result, while
80-
# async should include a callback within the script that's run on the remote machine. This will
81-
# allow the runner to interact with any given executor in both ways; we expect synchronous behavior
82-
# in a self-hosted runner, and async behavior in the hosted (Covalent Cloud) runner.
83-
# 2. The lifecycle of an ECS task includes [Provisioning -> Pending -> Activating -> Running ->
84-
# Deactivating -> Stopping -> Deprovisioning -> Stopped]. Polling means waiting until the Stopped
85-
# state has been reached, then returning the
86-
87-
8823
import base64
8924
import os
9025
import re
@@ -312,8 +247,8 @@ def execute(
312247
count=1,
313248
networkConfiguration={
314249
"awsvpcConfiguration": {
315-
"subnets": self.ecs_task_subnet_id.split(","),
316-
"securityGroups": self.ecs_task_security_group_id.split(","),
250+
"subnets": [self.ecs_task_subnet_id],
251+
"securityGroups": [self.ecs_task_security_group_id],
317252
# This is only needed if we're using public subnets
318253
"assignPublicIp": "ENABLED",
319254
},
359 KB
Loading

infra/iam/CovalentFargateExecutorPolicy.json infra/iam/CovalentECSExecutorPolicy.json

+17-48
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"Version": "2012-10-17",
33
"Statement": [
44
{
5-
"Sid": "ECSTaskMgmt",
5+
"Sid": "VisualEditor0",
66
"Effect": "Allow",
77
"Action": [
88
"ecs:RunTask",
@@ -17,71 +17,40 @@
1717
}
1818
},
1919
{
20-
"Sid": "ECSTaskRegistration",
21-
"Effect": "Allow",
22-
"Action": [
23-
"ecs:RegisterTaskDefinition"
24-
],
25-
"Resource": "*"
26-
},
27-
{
28-
"Sid": "ECRAuth",
20+
"Sid": "VisualEditor1",
2921
"Effect": "Allow",
3022
"Action": [
23+
"ecs:RegisterTaskDefinition",
3124
"ecr:GetAuthorizationToken"
3225
],
3326
"Resource": "*"
3427
},
3528
{
36-
"Sid": "ECRUpload",
29+
"Sid": "VisualEditor2",
3730
"Effect": "Allow",
3831
"Action": [
32+
"iam:GetRole",
3933
"ecr:GetDownloadUrlForLayer",
40-
"ecr:BatchGetImage",
41-
"ecr:BatchCheckLayerAvailability",
42-
"ecr:InitiateLayerUpload",
34+
"s3:ListBucket",
4335
"ecr:UploadLayerPart",
36+
"ecr:PutImage",
37+
"s3:PutObject",
38+
"s3:GetObject",
39+
"iam:PassRole",
40+
"ecr:BatchGetImage",
4441
"ecr:CompleteLayerUpload",
45-
"ecr:PutImage"
46-
],
47-
"Resource": [
48-
"arn:aws:ecr:<region>:<account>:repository/<ecr_repo_name>"
49-
]
50-
},
51-
{
52-
"Sid": "IAMRoles",
53-
"Effect": "Allow",
54-
"Action": [
55-
"iam:GetRole",
56-
"iam:PassRole"
42+
"logs:GetLogEvents",
43+
"ecr:InitiateLayerUpload",
44+
"ecr:BatchCheckLayerAvailability"
5745
],
5846
"Resource": [
47+
"arn:aws:ecr:<region>:<account>:repository/<ecr_repo_name>",
5948
"arn:aws:iam::<account>:role/CovalentFargateTaskRole",
60-
"arn:aws:iam::<account>:role/ecsTaskExecutionRole"
61-
]
62-
},
63-
{
64-
"Sid": "ObjectStore",
65-
"Effect": "Allow",
66-
"Action": [
67-
"s3:ListBucket",
68-
"s3:PutObject",
69-
"s3:GetObject"
70-
],
71-
"Resource": [
49+
"arn:aws:iam::<account>:role/ecsTaskExecutionRole",
50+
"arn:aws:logs:*:<account>:log-group:<cloudwatch_log_group_name>:log-stream:*",
7251
"arn:aws:s3:::<s3_resource_bucket>/*",
7352
"arn:aws:s3:::<s3_resource_bucket>"
7453
]
75-
},
76-
{
77-
"Sid": "LogRead",
78-
"Effect": "Allow",
79-
"Action": [
80-
"logs:GetLogEvents"
81-
],
82-
"Resource": [
83-
"arn:aws:logs:<region>:<account>:log-group:<cloudwatch_log_group_name>:log-stream:*"
84-
]
8554
}
8655
]
8756
}

infra/iam/CovalentFargateTaskExecutionPolicy.json

-18
This file was deleted.

infra/iam/CovalentFargateTaskPolicy.json

-24
This file was deleted.

0 commit comments

Comments
 (0)