-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Tools] Add script 'deploy.sh' to have a 1-click deployment of PCUI a…
…nd script 'setup-env.sh' to create config files for personal environments.
- Loading branch information
Showing
4 changed files
with
200 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 \ | ||
--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 \ | ||
--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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |