-
Notifications
You must be signed in to change notification settings - Fork 20
[Tools] Add scripts to facilitate 1-click deployment of PCUI in personal environment #291
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
|
||
function info() { | ||
echo "[INFO] $1" | ||
} | ||
|
||
function warn() { | ||
echo "[WARN] $1" | ||
} | ||
|
||
function fail() { | ||
echo "[ERROR] $1" && exit 1 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
#!/bin/bash | ||
set -e | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance | ||
# with the License. A copy of the License is located at | ||
# | ||
# http://aws.amazon.com/apache2.0/ | ||
# | ||
# or in the "LICENSE.txt" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES | ||
# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# This script is used to update the infrastructure of a given PCM environment. | ||
# An environment is composed of a list of variables with the entrypoints of the environment | ||
# and a CloudFormation request file where the stack update can be customized, | ||
# for example by changing the parameters provided to the previous version of the stack | ||
# | ||
# Usage: ./scripts/deploy.sh [ENVIRONMENT] | ||
# Example: ./scripts/deploy.sh demo | ||
|
||
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)" | ||
|
||
INFRASTRUCTURE_DIR="$CURRENT_DIR/../infrastructure" | ||
|
||
source "$CURRENT_DIR/common.sh" | ||
|
||
ENVIRONMENT=$1 | ||
|
||
[[ -z $ENVIRONMENT ]] && fail "Missing required argument: ENVIRONMENT" | ||
|
||
info "Selected environment: $ENVIRONMENT" | ||
|
||
source "$INFRASTRUCTURE_DIR/environments/$ENVIRONMENT-variables.sh" | ||
|
||
# STEP: Upload templates | ||
info "Retrieving infrastructure bucket" | ||
if [[ -n $INFRA_BUCKET_NAME ]]; then | ||
BUCKET=$INFRA_BUCKET_NAME | ||
else | ||
BUCKET=$(aws cloudformation describe-stack-resources \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. useful to add region parameter in every aws call. |
||
--region "$REGION" \ | ||
--stack-name "$INFRA_BUCKET_STACK_NAME" \ | ||
--logical-resource-id InfrastructureBucket \ | ||
--output text \ | ||
--query 'StackResources[0].PhysicalResourceId') | ||
fi | ||
info "Using infrastructure bucket $BUCKET" | ||
|
||
info "Uploading templates to infrastructure bucket $BUCKET" | ||
FILES=(parallelcluster-ui-cognito.yaml parallelcluster-ui.yaml) | ||
for FILE in "${FILES[@]}"; do | ||
aws s3 cp --region "$REGION" "$INFRASTRUCTURE_DIR/$FILE" "s3://$BUCKET/$FILE" | ||
done | ||
# ----------------------------- | ||
|
||
# STEP: Setup private ECR repository | ||
ECR_REPOSITORY_NAME="parallelcluster-ui" | ||
info "Settings up private ECR repository $ECR_REPOSITORY_NAME" | ||
if [[ ! $(aws ecr describe-repositories --repository-name $ECR_REPOSITORY_NAME --region "$REGION" 2>/dev/null) ]]; then | ||
info "The private ECR repository $ECR_REPOSITORY_NAME does not exist, creating ..." | ||
aws ecr create-repository \ | ||
--region "$REGION" \ | ||
--repository-name $ECR_REPOSITORY_NAME \ | ||
--image-tag-mutability MUTABLE | ||
|
||
else | ||
info "The private ECR repository $ECR_REPOSITORY_NAME already exists" | ||
fi | ||
REPOSITORY_INFO=$(aws ecr describe-repositories \ | ||
--region "$REGION" \ | ||
--repository-name $ECR_REPOSITORY_NAME \ | ||
--query "repositories[0].{arn:repositoryArn,uri:repositoryUri}" \ | ||
--output json) | ||
REPOSITORY_ARN=$(echo "$REPOSITORY_INFO" | jq -cr '.arn') | ||
REPOSITORY_ENDPOINT=$(echo "$REPOSITORY_INFO" | jq -cr '.uri' | cut -d '/' -f 1) | ||
info "Using private ECR repository $REPOSITORY_ARN at ECR endpoint $REPOSITORY_ENDPOINT" | ||
# ----------------------------- | ||
|
||
# STEP: Build image locally and publish to private ECR repository | ||
info "Building image locally and publishing it to private ECR repository" | ||
ECR_IMAGE_TAG=$(date +%Y.%m.%d) | ||
bash "$CURRENT_DIR/build_and_release_image.sh" --ecr-region "$REGION" --ecr-endpoint "$REPOSITORY_ENDPOINT" --tag "$ECR_IMAGE_TAG" | ||
info "Image built with tag '$ECR_IMAGE_TAG' and 'latest'" | ||
# ----------------------------- | ||
|
||
# STEP: Deploy stack | ||
info "Deploying stack $STACK_NAME" | ||
BUCKET_URL="https://$BUCKET.s3.$REGION.amazonaws.com" | ||
|
||
if [[ ! $(aws cloudformation describe-stacks --stack-name "$STACK_NAME" --region "$REGION" 2>/dev/null) ]]; then | ||
info "The stack $STACK_NAME does not exist, creating ..." | ||
CFN_DEPLOY_COMMAND="create-stack" | ||
CFN_WAIT_COMMAND="stack-create-complete" | ||
CFN_CLI_INPUT_YAML_FILE="$INFRASTRUCTURE_DIR/environments/$ENVIRONMENT-cfn-create-args.yaml" | ||
|
||
else | ||
info "The stack $STACK_NAME exists, updating ..." | ||
CFN_DEPLOY_COMMAND="update-stack" | ||
CFN_WAIT_COMMAND="stack-update-complete" | ||
CFN_CLI_INPUT_YAML_FILE="$INFRASTRUCTURE_DIR/environments/$ENVIRONMENT-cfn-update-args.yaml" | ||
fi | ||
|
||
CLI_INPUT_YAML=$(sed "s#BUCKET_URL_PLACEHOLDER#$BUCKET_URL#g" "$CFN_CLI_INPUT_YAML_FILE") | ||
|
||
AWS_PAGER="cat" aws cloudformation $CFN_DEPLOY_COMMAND \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need to pass There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
--cli-input-yaml "$CLI_INPUT_YAML" \ | ||
--stack-name "$STACK_NAME" \ | ||
--region "$REGION" | ||
|
||
aws cloudformation wait $CFN_WAIT_COMMAND \ | ||
--stack-name "$STACK_NAME" \ | ||
--region "$REGION" | ||
|
||
info "Deployment completed!" | ||
# ----------------------------- | ||
|
||
# STEP: Retrieve stack details | ||
PCUI_ENDPOINT=$(aws cloudformation describe-stacks \ | ||
--stack-name "$STACK_NAME" \ | ||
--region "$REGION" \ | ||
--query "Stacks[0].Outputs[?OutputKey == 'ParallelClusterUIUrl'].OutputValue" \ | ||
--output text) | ||
|
||
info "PCUI endpoint is $PCUI_ENDPOINT" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/bash | ||
set -e | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance | ||
# with the License. A copy of the License is located at | ||
# | ||
# http://aws.amazon.com/apache2.0/ | ||
# | ||
# or in the "LICENSE.txt" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES | ||
# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# This script is used to update the infrastructure of a given PCM environment. | ||
# An environment is composed of a list of variables with the entrypoints of the environment | ||
# and a CloudFormation request file where the stack update can be customized, | ||
# for example by changing the parameters provided to the previous version of the stack | ||
# | ||
# Usage: ./scripts/setup-env.sh [ENVIRONMENT] | ||
# Example: ./scripts/setup-env.sh demo | ||
|
||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" | ||
|
||
ENVIRONMENTS_DIR=$(realpath "$CURRENT_DIR/../infrastructure/environments") | ||
|
||
source "$CURRENT_DIR/common.sh" | ||
|
||
ENVIRONMENT=$1 | ||
|
||
[[ -z $ENVIRONMENT ]] && fail "Missing required argument: ENVIRONMENT" | ||
|
||
info "Selected environment: $ENVIRONMENT" | ||
|
||
if [[ $(ls $ENVIRONMENTS_DIR/$ENVIRONMENT-*) ]]; then | ||
warn "Configuration files for the environment $ENVIRONMENT already exist. Nothing to do." | ||
exit 0 | ||
fi | ||
|
||
info "Creating environment files" | ||
cp "$ENVIRONMENTS_DIR/demo-variables.sh" "$ENVIRONMENTS_DIR/$ENVIRONMENT-variables.sh" | ||
chmod +x "$ENVIRONMENTS_DIR/$ENVIRONMENT-variables.sh" | ||
cp "$ENVIRONMENTS_DIR/demo-cfn-update-args.yaml" "$ENVIRONMENTS_DIR/$ENVIRONMENT-cfn-create-args.sh" | ||
cp "$ENVIRONMENTS_DIR/demo-cfn-update-args.yaml" "$ENVIRONMENTS_DIR/$ENVIRONMENT-cfn-update-args.sh" | ||
|
||
info "Environment files created! Check out $ENVIRONMENTS_DIR" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:The result of the first echo is an empty string, because
$test1
would expand the variable identified bytest1
rather thantest
. This kind of issues are hard to discover, so as a best practice is better to use curly braces everywhere.