|
| 1 | +# AWS ECS Deploy Action |
| 2 | +_To automatically edit task definitions via jq to then deploy & monitor._ |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | +### How it works |
| 7 | + |
| 8 | + * Optionally, the action downloads the latest task definition from the given prepare task name (`ecs_prepare_task_definition_name`). |
| 9 | + * If fulfilled, it edits the task definition for each image change in `prepare_container_image_changes` |
| 10 | + * The task is executed one-off and requires successful completion before next step. |
| 11 | + * (this may require setting `prepare_container_network_config_filepath` to a JSON file representing the network configuration) |
| 12 | + * Afterwards, the action downloads the latest task definition from given main task parameter (`service_task_definition_name`). |
| 13 | + * Task definition is edited for each image change listed in `container_image_changes`. |
| 14 | + * Service update (with forced deployment) is triggered with that modified task definition file under the named service: `ecs_service_name`. |
| 15 | + * Status updates are provided as the deployment continues until either a successful or failure state is encountered. |
| 16 | + |
| 17 | +### Assumptions |
| 18 | + |
| 19 | +This is used in many applications for production level deployments. However, there are a few things that are untested as we do not use them. |
| 20 | + |
| 21 | + * Non-FARGATE deployments |
| 22 | + * CodeDeploy within ECS |
| 23 | + |
| 24 | +--- |
| 25 | + |
| 26 | +## Usage |
| 27 | +_includes examples from other packages to give context_ |
| 28 | + |
| 29 | +```yaml |
| 30 | +- name: Configure AWS Credentials |
| 31 | + uses: aws-actions/configure-aws-credentials@v1 |
| 32 | + with: |
| 33 | + role-to-assume: arn:aws:iam::123456789100:role/my-github-actions-role |
| 34 | + aws-region: us-east-1 |
| 35 | + |
| 36 | +- name: Login to Amazon ECR |
| 37 | + uses: aws-actions/amazon-ecr-login@v1 |
| 38 | + |
| 39 | +- name: "Build, tag, push image: ..." |
| 40 | + uses: docker/build-push-action@v4 |
| 41 | + with: |
| 42 | + push: true |
| 43 | + |
| 44 | +- name: ECS Deploy |
| 45 | + uses: sourcetoad/aws-ecs-deploy-action@v1 |
| 46 | + with: |
| 47 | + ecs_service_name: project |
| 48 | + service_task_definition_name: project-alpha |
| 49 | + container_image_changes: > |
| 50 | + nginx|123456789100.dkr.ecr.us-east-1.amazonaws.com/nginx:version |
| 51 | + php|123456789100.dkr.ecr.us-east-1.amazonaws.com/php:version |
| 52 | +``` |
| 53 | +
|
| 54 | +## Customizing |
| 55 | +
|
| 56 | +### inputs |
| 57 | +
|
| 58 | +Following inputs can be used as `step.with` keys |
| 59 | + |
| 60 | +| Name | Required | Type | Description | |
| 61 | +|--------------------------------------------------|----------|--------|--------------------------------------------------------------------| |
| 62 | +| `ecs_cluster_name` | yes | string | ECS Cluster Name | |
| 63 | +| `aws_region` | no | string | AWS Region (default: `us-east-1`) | |
| 64 | +| `ecs_service_name` | yes | string | ECS Service Name | |
| 65 | +| `ecs_launch_type` | no | string | ECS Launch Type for tasks. (default: `FARGATE`) | |
| 66 | +| `service_task_definition_name` | yes | string | ECS Task Definition Name | |
| 67 | +| `service_container_image_changes` | yes | string | space delimited keypairs (`container|image`) | |
| 68 | +| `prepare_task_definition_name` | no | string | ECS Task Definition Name (Runs prior to execution) | |
| 69 | +| `prepare_task_container_image_changes` | no | string | space delimited keypairs for prepare step (`container|image`) | |
| 70 | + | `prepare_task_container_network_config_filepath` | no | string | filepath from context of root to json configuration | |
| 71 | +| `max_polling_iterations` | no | Number | Number of 15s iterations to poll max (default: `60`) | |
| 72 | +| `dry_run` | no | bool | Whether to skip write related AWS commands. | |
| 73 | + |
| 74 | +## Skip waiting during update |
| 75 | +Some projects may not want to poll till completion. Setting `max_polling_iterations` to `0` will exit the script cleanly |
| 76 | +after the service update was triggered. Progress will have to be monitored elsewhere. |
| 77 | + |
| 78 | +## Prepare Task |
| 79 | +Some projects may require a task to complete prior to the rollout of the main system. This is commonly for migrations in Laravel projects. |
| 80 | +These set of configurations allow when set require the task to execute and continue to completion prior to the main services updating. |
| 81 | + |
| 82 | +* `prepare_task_definition_name` - The task name for the prepare task. |
| 83 | +* `prepare_task_container_image_changes` - Image changes, much like explained below for container images |
| 84 | +* `prepare_task_container_network_config_filepath` - JSON file for network configuration (example below) |
| 85 | +```json |
| 86 | +{ |
| 87 | + "awsvpcConfiguration": { |
| 88 | + "subnets": ["string", "string2"], |
| 89 | + "securityGroups": ["string", "string2"], |
| 90 | + "assignPublicIp": "ENABLED|DISABLED" |
| 91 | + } |
| 92 | +} |
| 93 | +``` |
| 94 | + |
| 95 | +## Container Image Changes |
| 96 | + |
| 97 | +When wishing to change multiple images in one task definition, leverage the formatting of Folded Style parameters. |
| 98 | + |
| 99 | +Given this example: |
| 100 | +```yaml |
| 101 | +- uses: sourcetoad/aws-ecs-deploy-action@v1 |
| 102 | + with: |
| 103 | + container_image_changes: > |
| 104 | + nginx|123456789100.dkr.ecr.us-east-1.amazonaws.com/nginx:version |
| 105 | + php|123456789100.dkr.ecr.us-east-1.amazonaws.com/php:version |
| 106 | +``` |
| 107 | + * This will crawl the `containerDefinitions` of the task definition |
| 108 | + * Finding the first container that has name `nginx` |
| 109 | + * Adapting the `image` property to `123456789100.dkr.ecr.us-east-1.amazonaws.com/nginx:version` |
| 110 | + * Finding the next container that has name `php` |
| 111 | + * Adapting the `image` property to `123456789100.dkr.ecr.us-east-1.amazonaws.com/php:version` |
0 commit comments