Skip to content
Open
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
49 changes: 49 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"version": "0.2.0",
"configurations": [{
"name": "cfecs-update",
"type": "python",
"pythonPath": "${config.python.pythonPath}",
"request": "launch",
"stopOnEntry": true,
"console": "none",
//"program": "${file}",
"program": "${workspaceRoot}/cfecs-update",
"args": [
"us-west-1",
"default",
"pdf_service",
"--debug",
"--kill-tasks"
],
"cwd": "${workspaceRoot}",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
],
"env": {
//"name": "value"
}
},
{
"name": "Current File",
"type": "python",
"pythonPath": "${config.python.pythonPath}",
"request": "launch",
"stopOnEntry": true,
"console": "none",
"program": "${file}",
"args": [],
"cwd": "${workspaceRoot}",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
],
"env": {
//"name": "value"
}
}
]
}
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ steps:
### Usage with docker

```bash
docker run --rm -it -e AWS_ACCESS_KEY_ID=**** -e AWS_SECRET_ACCESS_KEY=**** codefresh/cf-ecs-deploy cfecs-update [options] <aws-region> <ecs-cluster-name> <ecs-service-name>
docker run --rm -it -e AWS_ACCESS_KEY_ID=**** -e AWS_SECRET_ACCESS_KEY=**** codefresh/cf-ecs-deploy \
cfecs-update [options] <aws-region> <ecs-cluster-name> <ecs-service-name>
```

### cfecs-update -h
Expand All @@ -101,6 +102,8 @@ optional arguments:
-h, --help show this help message and exit
--wait Wait for deployment to complete (default)
--no-wait No Wait for deployment to complete
--kill-tasks De-register current task definition & stop all running tasks related to service
--no-kill-tasks Leave current running taks alone, they will need to be manually killed. On by default
--timeout TIMEOUT deployment wait timeout (default 900s)
--max-failed MAX_FAILED
max failed tasks to consider deployment as failed
Expand Down
75 changes: 49 additions & 26 deletions cfecs-update
Original file line number Diff line number Diff line change
@@ -1,49 +1,72 @@
#!/usr/bin/env python
#
import sys, argparse, cfecs, logging, pprint
# -*- coding: utf-8 -*-
"""Fill in Google style docstrings here
"""

import sys
import argparse
import pprint
import logging
import cfecs

def print_usage():
print ("Usage: \n"
" cfecs-update aws-region ecs_cluster ecs_service")

if __name__ == '__main__':

parser = argparse.ArgumentParser(description='Codefresh ECS Deploy')
PARSER = argparse.ArgumentParser(description='Codefresh ECS Deploy')

parser.add_argument('region_name', help="AWS Region, ex. us-east-1")
parser.add_argument('cluster_name', help="ECS Cluster Name")
parser.add_argument('service_name', help="ECS Service Name")
PARSER.add_argument('region_name', help="AWS Region, ex. us-east-1")
PARSER.add_argument('cluster_name', help="ECS Cluster Name")
PARSER.add_argument('service_name', help="ECS Service Name")

image_group = parser.add_argument_group()
image_group.add_argument('-i', '--image-name', action = 'store', dest = 'image_name', help='Image Name in ECS Task Definition to set new tag')
image_group.add_argument('-t', '--image-tag', action = 'store', dest = 'image_tag', help='Tag for the image')
IMAGE_GROUP = PARSER.add_argument_group()
IMAGE_GROUP.add_argument('-i', '--image-name', action='store', dest='image_name', \
help='Image Name in ECS Task Definition to set new tag')
IMAGE_GROUP.add_argument('-t', '--image-tag', action='store', dest='image_tag', \
help='Tag for the image')

args_wait_group = parser.add_mutually_exclusive_group()
args_wait_group.add_argument('--wait', action = 'store_true', dest = 'wait', default=True, help='Wait for deployment to complete (default)')
args_wait_group.add_argument('--no-wait', action = 'store_false', dest = 'wait', help='No Wait for deployment to complete')
ARGS_WAIT_GROUP = PARSER.add_mutually_exclusive_group()
ARGS_WAIT_GROUP.add_argument('--wait', action='store_true', dest='wait', default=True, \
help='Wait for deployment to complete (default)')
ARGS_WAIT_GROUP.add_argument('--no-wait', action='store_false', dest='wait', \
help='No Wait for deployment to complete')

parser.add_argument('--timeout', action = 'store', dest = 'timeout', default = cfecs.DEPLOY_TIMEOUT, help='deployment wait timeout (default 900s)')
parser.add_argument('--max-failed', action = 'store', dest = 'max_failed', default = cfecs.MAX_FAILED_TASKS, help='max failed tasks to consider deployment as failed (default 4)')
parser.add_argument('--debug', action = 'store_true', dest = 'debug', help='show debug messages')
ARGS_KILL_GROUP = PARSER.add_mutually_exclusive_group()
ARGS_KILL_GROUP.add_argument('--no-kill-tasks', action='store_false', dest='kill_tasks', \
default=False, \
help='Leave current running taks alone, they will need to be manually killed')
ARGS_KILL_GROUP.add_argument('--kill-tasks', action='store_true', dest='kill_tasks', \
default=True, \
help='De-register current task definition & stop all running tasks related to service')

PARSER.add_argument('--timeout', action='store', dest='timeout', default=cfecs.DEPLOY_TIMEOUT, \
help='deployment wait timeout (default 900s)')
PARSER.add_argument( \
'--max-failed', action='store', dest='max_failed', default=cfecs.MAX_FAILED_TASKS, \
help='max failed tasks to consider deployment as failed (default 4)')
PARSER.add_argument('--debug', action='store_true', dest='debug', \
help='show debug messages')

args = parser.parse_args()
ARGS = PARSER.parse_args()
try:
if args.debug:
if ARGS.debug:
cfecs.init_log(logging.DEBUG)
response = cfecs.update_service(args.cluster_name, args.service_name, region_name=args.region_name,
wait=args.wait, deploy_timeout=args.timeout, max_failed=args.max_failed,
image_name=args.image_name, image_tag=args.image_tag)
RESPONSE = cfecs.update_service(ARGS.cluster_name, ARGS.service_name, \
region_name=ARGS.region_name, wait=ARGS.wait, deploy_timeout=ARGS.timeout, \
max_failed=ARGS.max_failed, image_name=ARGS.image_name, image_tag=ARGS.image_tag, \
kill_tasks=ARGS.kill_tasks)

if not response.get("status") or response["status"] in (cfecs.C_FAIL, cfecs.C_TIMEOUT):
cfecs.log.error("ERROR: {}".format(pprint.pformat(response)))
if not RESPONSE.get("status") or RESPONSE["status"] in (cfecs.C_FAIL, cfecs.C_TIMEOUT):
cfecs.log.error("ERROR: %s", pprint.pformat(RESPONSE))
sys.exit(1)

cfecs.log.debug(pprint.pformat(response))
cfecs.log.info("ECS Deploy completed with status {}".format(response.get("status")))
cfecs.log.debug(pprint.pformat(RESPONSE))
cfecs.log.info("ECS Deploy completed with status %s", RESPONSE.get("status"))

except Exception as e:
cfecs.log.error("ERROR: {}".format(e.message))
except Exception as err:
cfecs.log.error("ERROR: %s", err.message)
sys.exit(1)


Expand Down
Loading