Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
32 changes: 18 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,20 @@ Installation
Status
------

.. image:: https://readthedocs.org/projects/ecs-deplojo/badge/?version=latest
:target: https://readthedocs.org/projects/ecs-deplojo/
.. image:: <https://readthedocs.org/projects/ecs-deplojo/badge/?version=latest>
:target: <https://readthedocs.org/projects/ecs-deplojo/>

.. image:: https://github.com/labd/ecs-deplojo/workflows/Python%20Tests/badge.svg
:target: https://github.com/labd/ecs-deplojo/actions?query=workflow%3A%22Python+Tests%22
.. image:: <https://github.com/labd/ecs-deplojo/workflows/Python%20Tests/badge.svg>
:target: <https://github.com/labd/ecs-deplojo/actions?query=workflow%3A%22Python+Tests%22>

.. image:: http://codecov.io/github/LabD/ecs-deplojo/coverage.svg?branch=master
:target: http://codecov.io/github/LabD/ecs-deplojo?branch=master
.. image:: <http://codecov.io/github/LabD/ecs-deplojo/coverage.svg?branch=master>
:target: <http://codecov.io/github/LabD/ecs-deplojo?branch=master>

.. image:: https://img.shields.io/pypi/v/ecs-deplojo.svg
:target: https://pypi.python.org/pypi/ecs-deplojo/
.. image:: <https://img.shields.io/pypi/v/ecs-deplojo.svg>
:target: <https://pypi.python.org/pypi/ecs-deplojo/>

.. end-no-pypi


Usage
-----

Expand All @@ -43,7 +42,6 @@ Usage
--role-arn <optional arn>
--help Show this message and exit.


Example configuration
---------------------

Expand Down Expand Up @@ -72,6 +70,10 @@ Example configuration
web:
task_definition: web

scheduled_tasks:
cron-event:
task_definition: web

before_deploy:
- task_definition: manage
container: uwsgi
Expand All @@ -82,7 +84,6 @@ Example configuration
container: uwsgi
command: manage.py clearsessions


Using SSM secrets
-----------------

Expand Down Expand Up @@ -117,25 +118,28 @@ the startup of your Docker container.
web:
task_definition: web


When the container is started the secrets are available as environment variables and
hidden in the AWS ECS console, this is not recommended in production.


AWS Default VPC
---------------

When running your servers in the AWS default VPC you need ``networkMode="awsvpc"`` in
your task definition JSON file, this will ensure that no hostnames are set for the
containers, since this isn't supported by AWS.


AWS Fargate
-----------

Unlike EC2 based clusters AWS Fargate needs a ``execution_role_arn`` to work, this can be
set in your service definition in the YAML file.

AWS Scheduled tasks
-------------------

The configuration block 'scheduled_tasks' contains the name over the rule in EventBridge
as key, and a reference to the task_definition whose taskDefinitionArn will be used to
update the task definition on the scheduled target.

Example log output
------------------
Expand Down
1 change: 1 addition & 0 deletions src/ecs_deplojo/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ def __init__(self, role_arn=None):
)

self.ecs = boto3.client("ecs", config=config, **credentials)
self.events = boto3.client("events", config=config, **credentials)
10 changes: 9 additions & 1 deletion src/ecs_deplojo/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
from ecs_deplojo.connection import Connection
from ecs_deplojo.exceptions import DeploymentFailed
from ecs_deplojo.logger import logger
from ecs_deplojo.register import deregister_task_definitions, register_task_definitions
from ecs_deplojo.register import (
deregister_task_definitions,
register_task_definitions,
update_scheduled_tasks,
)
from ecs_deplojo.task_definitions import TaskDefinition


Expand Down Expand Up @@ -47,6 +51,10 @@ def start_deployment(
# Register the task definitions in ECS
register_task_definitions(connection, task_definitions)

# update the task-definition arns on scheduled tasks
scheduled_tasks = config.get("scheduled_tasks", {})
update_scheduled_tasks(connection, task_definitions, scheduled_tasks)

# Run tasks before deploying services
tasks_before_deploy = config.get("before_deploy", [])
run_tasks(connection, cluster_name, task_definitions, tasks_before_deploy)
Expand Down
18 changes: 18 additions & 0 deletions src/ecs_deplojo/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ def register_task_definitions(
logger.info("Registered new task definition %s", task_definition)


def update_scheduled_tasks(
connection: Connection,
task_definitions: dict[str, TaskDefinition],
scheduled_tasks: dict[str, typing.Any],
):
for rule_name, config in scheduled_tasks.items():
if not (task_definition := config.get("task_definition")):
continue
if not (task_definition := task_definitions.get(task_definition)):
continue

targets = connection.events.list_targets_by_rule(Rule=rule_name)
for target in targets["Targets"]:
target["EcsParameters"]["TaskDefinitionArn"] = task_definition.arn

connection.events.put_targets(Rule=rule_name, Targets=targets["Targets"])


def deregister_task_definitions(
connection: Connection, task_definitions: typing.Dict[str, TaskDefinition]
) -> None:
Expand Down
Loading