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

[Tools] Add scripts to facilitate 1-click deployment of PCUI in personal environment #291

Merged

Conversation

gmarciani
Copy link
Collaborator

@gmarciani gmarciani commented Nov 22, 2023

Changes

  1. Add script 'deploy.sh' to deploy (created or update) the local PCUI to a personal environment.
  2. Add script 'setup-env.sh' to create the configuration files to deploy PCUI to personal environments
  3. Documented how to use the above scripts.

Command to create files for the personal environment (this must be done just the first time):

bash scripts/setup-env.sh giacomo-env

Command to deploy (create or update) PCUI into the environment:

bash scripts/deploy.sh giacomo-env

Example of execution:

(pcluster-ui) ➜  aws-parallelcluster-ui git:(wip/mgiacomo/2023120/fix-urlib-cve) ✗ bash scripts/deploy.sh mgiacomo                            
[INFO] Selected environment: mgiacomo
[INFO] Retrieving infrastructure bucket
[INFO] Using infrastructure bucket mgiacomo-aws-parallelcluster-ui
[INFO] Uploading templates to infrastructure bucket mgiacomo-aws-parallelcluster-ui
upload: infrastructure/parallelcluster-ui-cognito.yaml to s3://mgiacomo-aws-parallelcluster-ui/parallelcluster-ui-cognito.yaml
upload: infrastructure/parallelcluster-ui.yaml to s3://mgiacomo-aws-parallelcluster-ui/parallelcluster-ui.yaml
[INFO] Settings up private ECR repository parallelcluster-ui
[INFO] The private ECR repository parallelcluster-ui already exists
[INFO] Using private ECR repository arn:aws:ecr:us-east-1:REDACTED:repository/parallelcluster-ui at ECR endpoint REDACTED.dkr.ecr.us-east-1.amazonaws.com
[INFO] Building image locally and publishing it to private ECR repository
[INFO] Logging in REDACTED.dkr.ecr.us-east-1.amazonaws.com
Login Succeeded
[INFO] Building frontend
~/workplace/aws-parallelcluster-ui/frontend ~/workplace/aws-parallelcluster-ui
[INFO] Building image
...DOCKER LOGS...
[INFO] Pushing image REDACTED.dkr.ecr.us-east-1.amazonaws.com/parallelcluster-ui:2023.11.21 in repository parallelcluster-ui
...DOCKER LOGS...
[INFO] Uploaded: REDACTED.dkr.ecr.us-east-1.amazonaws.com/parallelcluster-ui:2023.11.21, REDACTED.dkr.ecr.us-east-1.amazonaws.com/parallelcluster-ui:latest
[INFO] Image built with tag '2023.11.21' and 'latest'
[INFO] Deploying stack pcui-test
[INFO] The stack pcui-test does not exist, creating ...
{
    "StackId": "arn:aws:cloudformation:us-east-1:REDACTED:stack/pcui-test/REDACTED"
}
[INFO] Deployment completed!
[INFO] PCUI endpoint is https://REDACTED.execute-api.us-east-1.amazonaws.com/pcui

How Has This Been Tested?

Used both script to deploy PCUI in personal account.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@gmarciani gmarciani marked this pull request as ready for review November 22, 2023 16:05
# Usage: ./scripts/deploy.sh [ENVIRONMENT]
# Example: ./scripts/deploy.sh demo

CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

Choose a reason for hiding this comment

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

minor: extra space after $( and before )


info "Selected environment: $ENVIRONMENT"

source "$INFRASTRUCTURE_DIR/environments/$ENVIRONMENT-variables.sh"

Choose a reason for hiding this comment

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

minor: it's useful to use {} when variables are used to compose a string

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

AFAIK it's useful only when you're putting variables isde by side, e.g. "$VAR_1$VAR_2" => "${VAR_1}${VAR_2}". In this case what's the advantage?

Choose a reason for hiding this comment

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

In your case there are no differences because after $ENVIRONMENT you have a -, but in general it's worth using curly braces. Let's think to this simple example:

$ test=one
$ echo "$test1"

$ echo "${test}1"
one1

The result of the first echo is an empty string, because $test1 would expand the variable identified by test1 rather than test. This kind of issues are hard to discover, so as a best practice is better to use curly braces everywhere.

--logical-resource-id InfrastructureBucket \
--output json \
--query 'StackResources[0].PhysicalResourceId'\
| tr -d '"' )

Choose a reason for hiding this comment

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

info: tr -d '"' can be replaced with xargs

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

is there any advantage of using xargs instead of tr?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

you know what:i think in this case none of the two are required, but simply use "--output text"

if [[ -n $INFRA_BUCKET_NAME ]]; then
BUCKET=$INFRA_BUCKET_NAME
else
BUCKET=$(aws cloudformation describe-stack-resources \

Choose a reason for hiding this comment

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

useful to add region parameter in every aws call.


CLI_INPUT_YAML=$(sed "s#BUCKET_URL_PLACEHOLDER#$BUCKET_URL#g" "$CFN_CLI_INPUT_YAML_FILE")

AWS_PAGER="cat" aws cloudformation $CFN_DEPLOY_COMMAND \

Choose a reason for hiding this comment

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

do we need to pass cat or can we use AWS_PAGER=""?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I suggest to keep cat at least for the time being because I took that from a script used to update the demo environment from github.
The idea is to have a unique 1click deployment script that works for both personal env and demo env, so I suggest to keep it as is for the time being.

…nd script 'setup-env.sh' to create config files for personal environments.
@gmarciani gmarciani force-pushed the wip/mgiacomo/2023120/scripts-one-click-deploy branch from f2e7ba5 to 7a2c21f Compare November 23, 2023 13:46
@gmarciani gmarciani merged commit aad8b88 into aws:main Nov 23, 2023
2 checks passed
@gmarciani gmarciani deleted the wip/mgiacomo/2023120/scripts-one-click-deploy branch November 23, 2023 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants