Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add task def override #2763

Merged
merged 6 commits into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ nav:
- Custom Environment Resources: docs/developing/custom-environment-resources.en.md
- Secrets: docs/developing/secrets.en.md
- Service Discovery: docs/developing/service-discovery.en.md
- Task Definition Overrides: docs/developing/taskdef-overrides.en.md
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's move this to last in the list as it's an advanced feature 🙏

- Additional AWS Resources: docs/developing/additional-aws-resources.en.md
- Sidecars: docs/developing/sidecars.en.md
- Storage: docs/developing/storage.en.md
Expand Down
55 changes: 55 additions & 0 deletions site/content/docs/developing/taskdef-overrides.en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Task Definition Overrides
If there are fields that are not configurable in the [manifest](../manifest/overview.en.md), users can bypass some of the [ECS Task Definition setting](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-taskdefinition.html) by applying override rules to the CloudFormation template Copilot generates out of the manifest.
iamhopaul123 marked this conversation as resolved.
Show resolved Hide resolved

## How to specify override rules?
For each override rule, users need to construct the **path** and **value** of the CloudFormation resource field they want to override.
iamhopaul123 marked this conversation as resolved.
Show resolved Hide resolved

``` yaml
taskdef_overrides:
- path: <ECS Task Definition field path>
value: <value>
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of this? (inspired by https://datatracker.ietf.org/doc/html/rfc6902)

The following is an example valid `taskdef_overrides` field that can be applied to a manifest file:

``` yaml
taskdef_overrides:
- path: ContainerDefinitions[0].Cpu
  value: 512
- path: ContainerDefinitions[0].Memory
   value: 1024

Each rule is applied sequentially to the CloudFormation template. The resulting CloudFormation template becomes the target of the next rule. Evaluation continues until all rules are successfully applied or an error is encountered.


## Override Behaviors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Override Behaviors
### Path evaluation
The `path` field is a `'.'` character separated path to a target [Task Definition field under `Properties` in CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-taskdefinition.html).
- Copilot recursively inserts fields if they don't ....
- To append a new member to a `list` field such as `Ulimits` you can use the special character `-`: `Ulimits[-]`.


- Use `-` as index to append a new member to a `list` field
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this the last item in the list?


- When applying the override rule, Copilot inserts or updates the fields along the path. More specifically, Copilot recursively inserts fields if they don't exist in the **path**. For example: if `B` and `C` don't exist, `A.B[-].C` will create `B` and `C`
iamhopaul123 marked this conversation as resolved.
Show resolved Hide resolved

!!! Attention
Users are not allowed to modify the following fields in the task definition.

* [Family](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-taskdefinition.html#cfn-ecs-taskdefinition-family)
* [ContainerDefinitions[<index>].Name](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ecs-taskdefinition-containerdefinitions.html#cfn-ecs-taskdefinition-containerdefinition-name)

efekarakus marked this conversation as resolved.
Show resolved Hide resolved
## Examples
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice examples!


**Add [`Ulimits`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ecs-taskdefinition-containerdefinitions-ulimit.html) to the main container**

``` yaml
taskdef_overrides:
- path: ContainerDefinitions[0].Ulimits[-]
value:
Name: "cpu"
SoftLimit: 1024
HardLimit: 2048
```

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to explain a bit how this works, for example

What Copilot does:
1. In the CloudFormation template that Copilot generates, the first `ContainerDefinition` is the main container for your workload. Using this override rule, Copilot looks for the first  `ContainerDefinition` (i.e. the main container definition). 
2. Since the `Ulimits` field doesn't exist in the original template, Copilot inserts a `Ulimits` field.
3. To add a first element to the `Ulimits` field, use `[-]` to signal an "append" action. You can think of this as appending to an empty list. 

and samesies for the other examples.

**Expose an extra UDP port**

``` yaml
taskdef_overrides:
- path: "ContainerDefinitions[0].PortMappings[-].ContainerPort"
value: 2056
// PortMappings[1] gets the port mapping added by the previous rule, since by default Copilot creates a port mapping.
- path: "ContainerDefinitions[0].PortMappings[1].Protocol"
value: "udp"
```

**Give read-only access to the root file system**

``` yaml
taskdef_overrides:
- path: "ContainerDefinitions[0].ReadonlyRootFilesystem"
value: true
```
15 changes: 13 additions & 2 deletions site/content/docs/include/common-svc-fields.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,10 @@ Required. The ID of the filesystem you would like to mount.
Optional. Defaults to `/`. Specify the location in the EFS filesystem you would like to use as the root of your volume. Must be fewer than 255 characters and must consist only of the characters `a-zA-Z0-9.-_/`. If using an access point, `root_dir` must be either empty or `/` and `auth.iam` must be `true`.

<span class="parent-field">volume.efs.</span><a id="uid" href="#uid" class="field">`uid`</a> <span class="type">Uint32</span>
Optional. Must be specified with `gid`. Mutually exclusive with `root_dir`, `auth`, and `id`. The POSIX UID to use for the dedicated access point created for the managed EFS filesystem.
Optional. Must be specified with `gid`. Mutually exclusive with `root_dir`, `auth`, and `id`. The POSIX UID to use for the dedicated access point created for the managed EFS filesystem.

<span class="parent-field">volume.efs.</span><a id="gid" href="#gid" class="field">`gid`</a> <span class="type">Uint32</span>
Optional. Must be specified with `uid`. Mutually exclusive with `root_dir`, `auth`, and `id`. The POSIX GID to use for the dedicated access point created for the managed EFS filesystem.
Optional. Must be specified with `uid`. Mutually exclusive with `root_dir`, `auth`, and `id`. The POSIX GID to use for the dedicated access point created for the managed EFS filesystem.

<span class="parent-field">volume.efs.</span><a id="auth" href="#auth" class="field">`auth`</a> <span class="type">Map</span>
Specify advanced authorization configuration for EFS.
Expand Down Expand Up @@ -240,5 +240,16 @@ Optional. The full config file path in your custom Fluent Bit image.

<div class="separator"></div>

<a id="taskdef_overrides" href="#taskdef_overrides" class="field">`taskdef_overrides`</a> <span class="type">Array</span>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe

Suggested change
<a id="taskdef_overrides" href="#taskdef_overrides" class="field">`taskdef_overrides`</a> <span class="type">Array</span>
<a id="taskdef_overrides" href="#taskdef_overrides" class="field">`taskdef_overrides`</a> <span class="type">Array of Rules</span>

The `taskdef_overrides` section allows users to apply overriding rules to their ECS Task Definitions (see examples [here](../developing/taskdef-overrides.en.md#examples)).

<span class="parent-field">taskdef_overrides.</span><a id="taskdef_overrides-path" href="#taskdef_overrides-path" class="field">`path`</a> <span class="type">String</span>
Required. Path to the Task Definition field to override.

<span class="parent-field">taskdef_overrides.</span><a id="taskdef_overrides-value" href="#taskdef_overrides-value" class="field">`value`</a> <span class="type">Any</span>
Required. Value of the Task Definition field to override.

<div class="separator"></div>

<a id="environments" href="#environments" class="field">`environments`</a> <span class="type">Map</span>
The environment section lets you override any value in your manifest based on the environment you're in. In the example manifest above, we're overriding the count parameter so that we can run 2 copies of our service in our 'prod' environment, and 2 copies using Fargate Spot capacity in our 'staging' environment.