diff --git a/README.rst b/README.rst index ce1eb96..a34cdfb 100644 --- a/README.rst +++ b/README.rst @@ -1,8 +1,8 @@ ECS Deploy ---------- -.. image:: https://travis-ci.org/fabfuel/ecs-deploy.svg?branch=develop - :target: https://travis-ci.org/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/coverage.png?b=develop :target: https://scrutinizer-ci.com/g/fabfuel/ecs-deploy @@ -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,36 @@ 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 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:: diff --git a/ecs_deploy/cli.py b/ecs_deploy/cli.py index 884fed3..6a3cdd9 100644 --- a/ecs_deploy/cli.py +++ b/ecs_deploy/cli.py @@ -38,7 +38,9 @@ def get_client(access_key_id, secret_access_key, region, profile): @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('--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): ') @@ -64,6 +66,8 @@ def get_client(access_key_id, secret_access_key, region, profile): @click.option('--rollback/--no-rollback', default=False, help='Rollback to previous revision, if deployment failed (default: --no-rollback)') @click.option('--exclusive-env', is_flag=True, default=False, help='Set the given environment variables exclusively and remove all other pre-existing env variables from all containers') @click.option('--exclusive-secrets', is_flag=True, default=False, help='Set the given secrets exclusively and remove all other pre-existing secrets from all containers') +@click.option('--exclusive-docker-labels', is_flag=True, default=False, help='Set the given docker labels exclusively and remove all other pre-existing docker-labels from all containers') +@click.option('--exclusive-s3-env-file', is_flag=True, default=False, help='Set the given s3 env files exclusively and remove all other pre-existing s3 env files from all containers') @click.option('--sleep-time', default=1, type=int, help='Amount of seconds to wait between each check of the service (default: 1)') @click.option('--slack-url', required=False, help='Webhook URL of the Slack integration. Can also be defined via environment variable SLACK_URL') @click.option('--slack-service-match', default=".*", required=False, help='A regular expression for defining, which services should be notified. (default: .* =all). Can also be defined via environment variable SLACK_SERVICE_MATCH') @@ -74,7 +78,7 @@ def get_client(access_key_id, secret_access_key, region, profile): @click.option('--volume', type=(str, str), multiple=True, required=False, help='Set volume mapping from host to container in the task definition.') @click.option('--add-container', type=str, multiple=True, required=False, help='Add a placeholder container in the task definition.') @click.option('--remove-container', type=str, multiple=True, required=False, help='Remove a container from the task definition.') -def deploy(cluster, service, tag, image, command, health_check, cpu, memory, memoryreservation, privileged, essential, env, env_file, secret, ulimit, system_control, port, mount, log, role, execution_role, task, region, access_key_id, secret_access_key, profile, timeout, newrelic_apikey, newrelic_appid, newrelic_region, newrelic_revision, comment, user, ignore_warnings, diff, deregister, rollback, exclusive_env, exclusive_secrets, sleep_time, exclusive_ulimits, exclusive_system_controls, exclusive_ports, exclusive_mounts, volume, add_container, remove_container, slack_url, slack_service_match='.*'): +def deploy(cluster, service, tag, image, command, health_check, cpu, memory, memoryreservation, privileged, essential, env, env_file, s3_env_file, secret, ulimit, system_control, port, mount, log, role, execution_role, task, region, access_key_id, secret_access_key, profile, timeout, newrelic_apikey, newrelic_appid, newrelic_region, newrelic_revision, comment, user, ignore_warnings, diff, deregister, rollback, exclusive_env, exclusive_secrets, exclusive_s3_env_file, sleep_time, exclusive_ulimits, exclusive_system_controls, exclusive_ports, exclusive_mounts, volume, add_container, remove_container, slack_url, docker_label, exclusive_docker_labels, slack_service_match='.*'): """ Redeploy or modify a service. @@ -104,6 +108,8 @@ def deploy(cluster, service, tag, image, command, health_check, cpu, memory, mem td.set_privileged(**{key: value for (key, value) in privileged}) td.set_essential(**{key: value for (key, value) in essential}) td.set_environment(env, exclusive_env, env_file) + td.set_docker_labels(docker_label, exclusive_docker_labels) + td.set_s3_env_file(s3_env_file, exclusive_s3_env_file) td.set_secrets(secret, exclusive_secrets) td.set_ulimits(ulimit, exclusive_ulimits) td.set_system_controls(system_control, exclusive_system_controls) @@ -172,12 +178,14 @@ def deploy(cluster, service, tag, image, command, health_check, cpu, memory, mem @click.option('--privileged', type=(str, bool), multiple=True, help='Overwrites the memory reservation value for a container: ') @click.option('-e', '--env', type=(str, str, str), multiple=True, help='Adds or changes an environment variable: ') @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):