Sign inSign up

lejmr/amazon-ecs-render-task-definition

By lejmr

•Updated about 5 years ago

Image
0

760

lejmr/amazon-ecs-render-task-definition repository overview

⁠Amazon AWS - ECS Task renderer using Jinja2

Known Vulnerabilities codecov Unit tests

The goal of this project is to deliver a very simple templating library that can generate Amazon ECS - Task definition which can be later used by other tools to update the relevant ECS Task definition or even ECS Service. Since I like to work with Helm⁠, this library produces similar output like helm template command, but in Amazon AWS ECS notion. The main motivation for templating is deployment to different environmnents where some variables or even a combinaton of containers can be different within a task. For example database container is added to the Task when deploying to DEV environment.

This libary is implemented in Python using TDD⁠, and templates are expected in the Jinja2⁠ templating language. All particular templates and value files can be written in JSON⁠ and YAML⁠ format. All contributions are welcomed!

The library is available as docker image⁠ and GitHub Action⁠.

⁠Example

Example directory structure available in a separate GitHub repository⁠.

├── complex-task-definition
│   ├── app.yaml
│   ├── db.yaml
│   └── task_properties.yaml
├── simple-task-definition.json
└── values
    ├── DEV.json
    └── PROD
        ├── environment.yaml
        └── extra.yml
# docker run --rm -v $PWD:/src -e INPUT_TASK-DEFINITION=simple-task-definition.json lejmr/amazon-ecs-render-task-definition
::set-output name=task-definition::task-definition-rendered.json
# cat task-definition-rendered.json
{
    "family": "test",
    "image": "latest"
}

Remember: The particular configuration files should only contain item which are compatible with --cli-input-json aws ecs register-task-definition command, as the generated file is expected to be used as follows:

aws ecs register-task-definition --cli-input-json file://XXXXXX.json
⁠Jenkins

WIP TODO: Extend the entrypoint, so the GitHub Actions are enforced.

⁠GitHub Actions

Look at examples⁠. The most prominent example uses complex-task-definition which is actually an directory containing fragments of configuration for the task definition and values/PROD for values which are used for interpolation.

This is how template can be constructed from two directories containing particular json/yaml files

  - name: Example of simple template
    uses: lejmr/amazon-ecs-render-task-definition@v1
    with:
      task-definition: complex-task-definition
      values: values/PROD

  - name: Deploy to Amazon ECS service
    uses: aws-actions/amazon-ecs-deploy-task-definition@v1
    with:
      task-definition: ${{ steps.render-web-container.outputs.task-definition }}
      service: my-service
      cluster: my-cluster

Tag summary

Content type

Image

Digest

Size

87.3 MB

Last updated

over 5 years ago

docker pull lejmr/amazon-ecs-render-task-definition