Skip to content

Commit

Permalink
Added region to DeploymentPipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
gitwater committed May 4, 2021
1 parent 4eb205c commit b3c4d14
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/paco/application/reseng_deploymentpipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,8 @@ def __init__(self, app_engine, grp_id, res_id, resource, stack_tags):
self.github_role_name = 'github_role'
self.source_stage = None
self.codebuild_ecs_release_phase_cache_id = RELEASE_PHASE_SCRIPT
if resource.configuration.region != None:
self.aws_region = resource.configuration.region

def init_stage(self, stage_config):
"Initialize an Action in a Stage: for source/build/deploy-style"
Expand Down Expand Up @@ -744,9 +746,10 @@ def init_stage_action_codecommit_source(self, action_config):
}]
codecommit_account_ref = self.paco_ctx.get_ref(action_config.codecommit_repository + '.account')
codecommit_account_ctx = self.paco_ctx.get_account_context(codecommit_account_ref)
repo_region = self.paco_ctx.get_ref(action_config.codecommit_repository+'.region')
iam_ctl.add_role(
account_ctx=codecommit_account_ctx,
region=self.aws_region,
region=repo_region,
resource=self.resource,
role=codecommit_iam_role_config,
iam_role_id=codecommit_iam_role_id,
Expand Down
6 changes: 5 additions & 1 deletion src/paco/application/reseng_s3bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ def init_resource(self):
account_ctx = self.account_ctx
else:
account_ctx = self.paco_ctx.get_account_context(account_ref=self.resource.account)
if self.resource.region:
bucket_region = self.resource.region
else:
bucket_region = self.aws_region
s3_ctl.init_context(
account_ctx,
self.aws_region,
bucket_region,
self.resource.paco_ref_parts,
self.stack_group,
self.stack_tags,
Expand Down
48 changes: 48 additions & 0 deletions src/paco/cftemplates/ecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
echo " ssh <service name> [task id]"
echo " docker-exec <service name> <command> [task id]"
echo " restart-services <service name | all >"
echo " list-ecr-containers <repo name>"
exit 0
}}
Expand Down Expand Up @@ -284,6 +285,50 @@
ssh -t ${SSH_IP} "${SSH_COMMAND}"
}
function list_ecr_image_tags()
{
REPOSITORY_NAME="$1"
OUTPUT=$(aws ecr describe-images --repository-name ${REPOSITORY_NAME} --query 'reverse(sort_by(imageDetails,& imagePushedAt))[:10].{tags: imageTags, date:imagePushedAt}' 2>/tmp/paco-ecs-list-images.stderr)
RET=$?
if [ $RET -ne 0 ] ; then
STDERR_OUTPUT="$(cat /tmp/paco-ecs-list-images.stderr)"
if [[] "$STDERR_OUTPUT" == *"does not exist in the registry"* ]]; then
echo "ERROR: The repository '${REPOSITORY_NAME}' does not exist."
echo
fi
echo $STDERR_OUTPUT
exit $RET
fi
IMAGE_TAGS=$(echo "$OUTPUT" | jq '.[].tags[0]' --raw-output | tr '\n' ' ' )
PUSHED_AT=$(echo "$OUTPUT" | jq '.[].date' --raw-output | tr '\n' ' ')
declare -a IMAGE_TAGS_LIST=(${IMAGE_TAGS})
IMAGE_TAGS_LIST_LEN=${#IMAGE_TAGS_LIST[@]}
declare -a PUSHED_AT_LIST=(${PUSHED_AT})
echo "Last ${IMAGE_TAGS_LIST_LEN} stored container images for ${REPOSITORY_NAME}"
IDX=0
for (( IDX=0; IDX<${IMAGE_TAGS_LIST_LEN}; IDX++ ))
do
JQ_STR=".[$IDX].tags"
TAGS_VALUE=$(echo $OUTPUT | jq "$JQ_STR" --raw-output)
CURRENT_DEPLOY=""
if [ "$TAGS_VALUE" != "null" ] ; then
JQ_STR=".[$IDX].tags[]"
ALL_TAGS=$(echo $OUTPUT | jq "$JQ_STR" --raw-output)
echo "${ALL_TAGS}" | grep 'ecs-deploy' >/dev/null 2>&1
if [ $? -eq 0 ] ; then
CURRENT_DEPLOY="< currently deployed"
fi
IMAGE_TAG=${IMAGE_TAGS_LIST[$IDX]}
else
IMAGE_TAG="null"
fi
FORMATTED_DATE=$(date -d "${PUSHED_AT_LIST[$IDX]}" +"%d %b %Y %T")
echo -e "${IMAGE_TAG}\t\t${FORMATTED_DATE} ${CURRENT_DEPLOY}"
done
}
case ${COMMAND} in
list-services)
list_services $1
Expand All @@ -303,6 +348,9 @@
docker-exec)
docker_exec $1 "$2" $3
;;
list-ecr-containers)
list_ecr_image_tags $1
;;
*)
usage
;;
Expand Down
2 changes: 2 additions & 0 deletions src/paco/controllers/ctl_codecommit.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ def resolve_ref(self, ref):
return account_ctx.get_id()
elif ref.last_part == 'account':
return repo_config.account
elif ref.last_part == 'region':
return repo_config.region
else:
if ref.ref == 'resource.codecommit.{}.{}'.format(group_id, repo_id):
return repo_config
Expand Down

0 comments on commit b3c4d14

Please sign in to comment.