Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add profile-name option to update-service orb #60

Closed

Conversation

lucasnad27
Copy link

@lucasnad27 lucasnad27 commented Oct 11, 2019

Checklist

  • All new jobs, commands, executors, parameters have descriptions
  • Examples have been added for any significant new features
  • README has been updated, if necessary

Motivation, issues

Please see #41 for detailed information on this patch

Description

add optional profile-name parameter to deploy-service-update

Add newline escapes

Use `default` profile instead of env var
description:
AWS profile used for calls to aws api.
type: string
default: default
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we make it "" by default? Ideally, I would like --profile to not be set when the value of profile-name is "", to avoid conflicts with existing usage of the orb.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you update .circleci/config.yml to add profile-name: default to the aws-ecs/deploy-service-update job at

- aws-ecs/deploy-service-update:
and
- aws-ecs/deploy-service-update:
to include the new parameter in our integration tests?

@@ -564,17 +570,20 @@ commands:
--cluster << parameters.cluster-name >> \
--services ${SERVICE_NAME} \
--output text \
--query 'services[0].deployments[].[taskDefinition, status]')
--query 'services[0].deployments[].[taskDefinition, status]' \
--profile << parameters.profile-name >>)
Copy link
Contributor

@lokst lokst Oct 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this will work as expected as the profile-name parameter should also be defined in the command and the job should pass the parameter to the command. Additionally, I would like it if --profile were not set if the value of profile-name is "".

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aws-cli-orb creates the default profile. Couldn't we follow the same pattern ? @lokst can you explain your concern about having a profile name empty please ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sylwit I'd like to avoid the chance of unintended effects on users as the orb's commands may not necessarily be used with the aws-cli orb. Hence, I'd rather --profile not be set if the user did not specify a non-empty value.

NUM_DEPLOYMENTS=$(aws ecs describe-services \
--cluster << parameters.cluster-name >> \
--services ${SERVICE_NAME} \
--output text \
--query 'length(services[0].deployments)')
--query 'length(services[0].deployments)' \
--profile << parameters.profile-name >>)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be updated such that --profile will not be set if the value of profile-name is ""?

TARGET_REVISION=$(aws ecs describe-services \
--cluster << parameters.cluster-name >> \
--services ${SERVICE_NAME} \
--output text \
--query "services[0].deployments[?taskDefinition==\`<< parameters.task-definition-arn >>\` && runningCount == desiredCount && (status == \`PRIMARY\` || status == \`ACTIVE\`)][taskDefinition]")
--query "services[0].deployments[?taskDefinition==\`<< parameters.task-definition-arn >>\` && runningCount == desiredCount && (status == \`PRIMARY\` || status == \`ACTIVE\`)][taskDefinition]" \
--profile << parameters.profile-name >>)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be updated such that --profile will not be set if the value of profile-name is ""?

@@ -619,7 +628,7 @@ commands:
- run:
name: Retrieve previous task definition and prepare new task definition values
command: |
PREVIOUS_TASK_DEFINITION=$(aws ecs describe-task-definition --task-definition << parameters.family >> --include TAGS)
PREVIOUS_TASK_DEFINITION=$(aws ecs describe-task-definition --task-definition << parameters.family >> --profile << parameters.profile-name >> --include TAGS)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this will work as expected as the profile-name parameter should also be defined in the command and the job should pass the parameter to the command. Additionally, I would like it if --profile were not set if the value of profile-name is "".

@@ -716,7 +725,9 @@ commands:
--container-definitions "${CCI_ORB_AWS_ECS_CONTAINER_DEFS}" \
"$@" \
--output text \
--query 'taskDefinition.taskDefinitionArn')
--query 'taskDefinition.taskDefinitionArn' \
--profile << parameters.profile-name >>)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be updated such that --profile will not be set if the value of profile-name is ""?

Copy link
Contributor

@lokst lokst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lucasnad27 Thank you for your awesome work! I left some comments and would love if you could review them!

@lucasnad27
Copy link
Author

I had similar reservations about making default the....default :)

You can expect a follow up commit this weekend. Thanks for the quick turnaround on the review!

@lucasnad27
Copy link
Author

Not quite "next weekend" Primarily due to social obligations and some re-prioritization at work, but...

@lokst I wanted to get your take on this before I spend any more time getting the arguments to parse correctly. The most elegant way I could find to do this in bash (disclaimer: my bash skills are decidedly NOT elegant) was to build up an array with conditionals...

params=(
    "--cluster staging"
    "--services public"
    "--output text"
    "--query 'services[0].deployments[].[taskDefinition, status]'")
if [ "$PROFILE" ]; then
    params+=("--profile ${PROFILE}")
fi

$(aws ecs describe-services "${params[@]}")

This almost works but I'm getting a jmespath error (Bad jmespath expression: Unclosed ' delimiter, hence my hesitance to debug this any further until I have a sanity check on the best way to accomplish this. As you've noted in your comments above, I'll have to change a pretty good chunk of the aws-cli commands with this tactic so getting some buy-in would be ideal :) Thanks again!

@lokst
Copy link
Contributor

lokst commented Oct 29, 2019

@lucasnad27 No worries and thanks so much for taking the time! 🙂

Regarding the approach, for consistency, I think we could use something similar to what is done in other parts of the orb, for optional parameters:

aws-ecs-orb/src/orb.yml.hbs

Lines 680 to 682 in bff006f

if [ -n "${CCI_ORB_AWS_ECS_TASK_ROLE}" ]; then
set -- "$@" --task-role-arn "${CCI_ORB_AWS_ECS_TASK_ROLE}"
fi
and

(If there are cases where "$@" is used for more than one AWS command within a step, the positional arguments can be cleared with set -- before being set for the next AWS command)

@sylwit
Copy link

sylwit commented Nov 5, 2019

I was working on the same "feature" when I found that you already have this PR. I'll be happy to help if you need @lucasnad27

@lucasnad27
Copy link
Author

Thanks for the guidance @lokst on preferred way to implement this the feature. I spoke with @sylwit offline and one of us will get this PR fixed up soon :)

@lucasnad27 lucasnad27 closed this Aug 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants