diff --git a/.travis.yml b/.travis.yml index 1f55f50..a0c7b60 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,9 @@ python: - "2.7" - "3.5" - "3.6" - - "3.7-dev" + - "3.7" + - "3.8" + - "3.9" install: pip install tox-travis script: tox after_script: diff --git a/Dockerfile b/Dockerfile index 64e8fbc..a282db7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.6-alpine3.8 +FROM python:3.8-alpine3.13 ADD . /usr/src/app WORKDIR /usr/src/app diff --git a/README.rst b/README.rst index 2af1f93..7ae552c 100644 --- a/README.rst +++ b/README.rst @@ -1,13 +1,13 @@ ECS Deploy ---------- -.. image:: https://travis-ci.org/fabfuel/ecs-deploy.svg?branch=develop - :target: https://travis-ci.org/fabfuel/ecs-deploy +.. image:: https://badge.fury.io/py/ecs-deploy.svg + :target: https://badge.fury.io/py/ecs-deploy -.. image:: https://scrutinizer-ci.com/g/fabfuel/ecs-deploy/badges/coverage.png?b=develop - :target: https://scrutinizer-ci.com/g/fabfuel/ecs-deploy +.. image:: https://travis-ci.com/fabfuel/ecs-deploy.svg?branch=develop + :target: https://travis-ci.com/github/fabfuel/ecs-deploy -.. image:: https://scrutinizer-ci.com/g/fabfuel/ecs-deploy/badges/quality-score.png?b=develop +.. image:: https://scrutinizer-ci.com/g/fabfuel/ecs-deploy/badges/coverage.png?b=develop :target: https://scrutinizer-ci.com/g/fabfuel/ecs-deploy `ecs-deploy` simplifies deployments on Amazon ECS by providing a convinience CLI tool for complex actions, which are executed pretty often. @@ -42,7 +42,7 @@ Updating a cron job:: Update a task definition (without running or deploying):: - $ ecs update my-cluster my-task + $ ecs update my-task Installation @@ -85,7 +85,7 @@ Currently the following actions are supported: deploy ====== -Redeploy a service either without any modifications or with a new image, environment variable and/or command definition. +Redeploy a service either without any modifications or with a new image, environment variable, docker label, and/or command definition. scale ===== @@ -93,12 +93,12 @@ Scale a service up or down and change the number of running tasks. run === -Run a one-off task based on an existing task-definition and optionally override command and/or environment variables. +Run a one-off task based on an existing task-definition and optionally override command, environment variables and/or docker labels. update ====== Update a task definition by creating a new revision to set a new image, -environment variable and/or command definition, etc. +environment variable, docker label, and/or command definition, etc. cron (scheduled task) ===================== @@ -230,6 +230,45 @@ To reset all existing secrets (secret environment variables) of a task definitio This will remove **all other** existing secret environment variables of **all containers** of the task definition, except for the new secret variable `NEW_SECRET` with the value coming from the AWS Parameter Store with the name "KEY_OF_SECRET_IN_PARAMETER_STORE" in the webserver container. + +Set environment via .env files +============================== +Instead of setting environment variables separately, you can pass a .env file per container to set the whole environment at once. You can either point to a local file or a file stored on S3, via:: + + $ ecs deploy my-cluster my-service --env-file my-app env/my-app.env + + $ ecs deploy my-cluster my-service --s3-env-file my-app arn:aws:s3:::my-ecs-environment/my-app.env + + +Set a docker label +=================== +To add a new or adjust an existing docker labels of a specific container, run the following command:: + + $ ecs deploy my-cluster my-service -d webserver somelabel somevalue + +This will modify the **webserver** container definition and add or overwrite the docker label "somelabel" with the value "somevalue". This way you can add new or adjust already existing docker labels. + + +Adjust multiple docker labels +============================= +You can add or change multiple docker labels at once, by adding the `-d` (or `--docker-label`) options several times:: + + $ ecs deploy my-cluster my-service -d webserver somelabel somevalue -d webserver otherlabel othervalue -d app applabel appvalue + +This will modify the definition **of two containers**. +The **webserver**'s docker label "somelabel" will be set to "somevalue" and the label "otherlabel" to "othervalue". +The **app**'s docker label "applabel" will be set to "appvalue". + + +Set docker labels exclusively, remove all other pre-existing docker labels +========================================================================== +To reset all existing docker labels of a task definition, use the flag ``--exclusive-docker-labels`` :: + + $ ecs deploy my-cluster my-service -d webserver somelabel somevalue --exclusive-docker-labels + +This will remove **all other** existing docker labels of **all containers** of the task definition, except for the label "somelabel" with the value "somevalue" in the webserver container. + + Modify a command ================ To change the command of a specific container, run the following command:: @@ -260,6 +299,82 @@ To change or set the role, the service's task should run as, use the following c This will set the task role to "MySpecialEcsTaskRole". + +Set CPU and memory reservation +============================== +- Set the `cpu` value for a task definition: :code:`--cpu 0`. +- Set the `memory` value (`hard limit`) for a task definition: :code:`--memory 256`. +- Set the `memoryreservation` value (`soft limit`) for a task definition: :code:`--memoryreservation 256`. + +Set privileged or essential flags +================================= +- Set the `privliged` value for a task definition: :code:`--privileged True|False`. +- Set the `essential` value for a task definition: :code:`--essential True|False`. + +Set logging configuration +========================= +Set the `logConfiguration` values for a task definition:: + + --log awslogs awslogs-group + --log awslogs awslogs-region + --log awslogs awslogs-stream-prefix + + +Set port mapping +================ +- Set the `port mappings` values for a task definition: :code:`--port `. + + - Supports :code:`--exclusive-ports`. + - The `protocol` is fixed to `tcp`. + +Set volumes & mount points +========================== +- Set the `volumes` values for a task definition :code:`--volume /host/path`. + + - :code:`` can then be used with :code:`--mount`. +- Set the `mount points` values for a task definition: :code:`--mount /container/path`. + + - Supports :code:`--exclusive-mounts`. + + - :code:`` is the one set by :code:`--volume`. +- Set the `ulimits` values for a task definition: :code:`--ulimit memlock 67108864 67108864`. + + - Supports :code:`--exclusive-ulimits`. +- Set the `systemControls` values for a task definition: :code:`--system-control net.core.somaxconn 511`. + + - Supports :code:`--exclusive-system-controls`. +- Set the `healthCheck` values for a task definition: :code:`--health-check `. + + +Set Health Checks +================= + - Example :code:`--health-check webserver "curl -f http://localhost/alive/" 30 5 3 0` + + +Placeholder Container +===================== +- Add placeholder containers: :code:`--add-container `. +- To comply with the minimum requirements for a task definition, a placeholder container is set like this: + + The contaienr name is :code:``. + + The container image is :code:`PLACEHOLDER`. + + The container soft limit is :code:`128`. +- The idea is to set sensible values with the deployment. + +It is possible to add and define a new container with the same deployment:: + + --add-container redis --image redis redis:6 --port redis 6379 6379 + +Remove containers +================= +- Containers can be removed: :code:`--remove-container `. + + - Leaves the original containers, if all containers would be removed. + + +All but the container flags can be used with `ecs deploy` and `ecs cron`. +The container flags are used with `ecs deploy` only. + + Ignore capacity issues ====================== If your cluster is undersized or the service's deployment options are not optimally set, the cluster diff --git a/ecs_deploy/__init__.py b/ecs_deploy/__init__.py index 99b1e99..342b3ec 100644 --- a/ecs_deploy/__init__.py +++ b/ecs_deploy/__init__.py @@ -1 +1 @@ -VERSION = '1.11.3' +VERSION = '1.12.0' diff --git a/ecs_deploy/cli.py b/ecs_deploy/cli.py index 3990715..d60a24a 100644 --- a/ecs_deploy/cli.py +++ b/ecs_deploy/cli.py @@ -30,9 +30,22 @@ def get_client(access_key_id, secret_access_key, region, profile): @click.option('-t', '--tag', help='Changes the tag for ALL container images') @click.option('-i', '--image', type=(str, str), multiple=True, help='Overwrites the image for a container: ') @click.option('-c', '--command', type=(str, str), multiple=True, help='Overwrites the command in a container: ') +@click.option('-h', '--health-check', type=(str, str, int, int, int, int), multiple=True, help='Overwrites the healthcheck in a container: ') +@click.option('--cpu', type=(str, int), multiple=True, help='Overwrites the cpu value for a container: ') +@click.option('--memory', type=(str, int), multiple=True, help='Overwrites the memory value for a container: ') +@click.option('--memoryreservation', type=(str, int), multiple=True, help='Overwrites the memory reservation value for a container: ') +@click.option('--privileged', type=(str, bool), multiple=True, help='Overwrites the privileged value for a container: ') +@click.option('--essential', type=(str, bool), multiple=True, help='Overwrites the essential value for a container: ') @click.option('-e', '--env', type=(str, str, str), multiple=True, help='Adds or changes an environment variable: ') -@click.option('--env-file', type=(str, str), default=((None, None),), multiple=True, required=False, help='Load environment variables from .env-file') +@click.option('--env-file', type=(str, str), default=((None, None),), multiple=True, required=False, help='Load environment variables from .env-file: ') +@click.option('--s3-env-file', type=(str, str), multiple=True, required=False, help='Location of .env-file in S3 in ARN format (eg arn:aws:s3:::/bucket_name/object_name): ') @click.option('-s', '--secret', type=(str, str, str), multiple=True, help='Adds or changes a secret environment variable from the AWS Parameter Store (Not available for Fargate): ') +@click.option('-d', '--docker-label', type=(str, str, str), multiple=True, help='Adds or changes a docker label: ') +@click.option('-u', '--ulimit', type=(str, str, int, int), multiple=True, help='Adds or changes a ulimit variable in the container description (Not available for Fargate): ') +@click.option('--system-control', type=(str, str, str), multiple=True, help='Adds or changes a system control variable in the container description (Not available for Fargate): ') +@click.option('-p', '--port', type=(str, int, int), multiple=True, help='Adds or changes a port mappings in the container description (Not available for Fargate): ') +@click.option('-m', '--mount', type=(str, str, str), multiple=True, help='Adds or changes a mount points in the container description (Not available for Fargate): ') +@click.option('-l', '--log', type=(str, str, str, str), multiple=True, help='Adds or changes a log configuration in the container description (Not available for Fargate):