Skip to content

Commit

Permalink
feat: HS-169: AWS Prod Deployment Script (#55)
Browse files Browse the repository at this point in the history
Co-authored-by: arun.mishra <[email protected]>
  • Loading branch information
arun-mi and arun.mishra authored Dec 4, 2023
1 parent 6a110ef commit 7578307
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 4 deletions.
3 changes: 1 addition & 2 deletions Hyperswitch-React-Demo-App/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
"build": "webpack --config webpack.common.js",
"test": "react-scripts test",
"eject": "react-scripts eject",
"format": "prettier --write \"**/*.{js,jsx}\"",
"postinstall": "patch-package"
"format": "prettier --write \"**/*.{js,jsx}\""
},
"eslintConfig": {
"extends": [
Expand Down
100 changes: 100 additions & 0 deletions aws/hyperswitch_web_aws_production_deployment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/bin/bash

command_discovery() {
type $1 >/dev/null 2>/dev/null
if [[ $? != 0 ]]; then
echo "\`$1\` command not found"
exit 1
fi
}

command_discovery curl
command_discovery aws

echo "Installing Node Modules"

echo $( (npm install --force))
echo $( (npm run re:build))

echo "Starting AWS S3 Configurations"
echo "Please enter your AWS Region"
read AWS_REGION </dev/tty

if [ -z "$AWS_REGION" ]; then
echo "Using us-east-2 by default"
AWS_REGION="us-east-2"
fi
echo "Do you wish to crate a new bucket on AWS S3? Ensure you have CreateBucket access on AWS (Y/N)"
read CREATE_BUCKET_BOOL </dev/tty

if [[ "$CREATE_BUCKET_BOOL" == "Y" ]] || [[ "$CREATE_BUCKET_BOOL" == "y" ]]; then
echo "Creating a bucket on AWS"
echo "Please enter a name for your bucket:"
read MY_AWS_S3_BUCKET_NAME </dev/tty

echo "Creating Bucket on AWS S3"
export AWS_BUCKET_LOCATION=$(
aws s3api create-bucket \
--region $AWS_REGION \
--bucket $MY_AWS_S3_BUCKET_NAME \
--query 'Location' \
--output text \
--create-bucket-configuration LocationConstraint=$AWS_REGION
)
echo "Bucket created at the location: $AWS_BUCKET_LOCATION"
fi

echo "Building the distributable bundle for the application"
if [ -z "$AWS_BUCKET_LOCATION" ]; then
echo "Enter the AWS S3 bucket location where you wish to store the Hyperswitch Client (my-bucket.s3.us-east-2.amazonaws.com)"
read AWS_BUCKET_LOCATION </dev/tty
fi
echo "Setting bucket as public"
echo $( (
aws s3api put-public-access-block \
--bucket $MY_AWS_S3_BUCKET_NAME \
--public-access-block-configuration "BlockPublicAcls=false,IgnorePublicAcls=false,BlockPublicPolicy=false,RestrictPublicBuckets=false"
))

echo "Adding bucket policy to make it public"

AWS_BUCKET_POLICY='{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::'$MY_AWS_S3_BUCKET_NAME'/*"
}
]
}'

echo "Displaying the policy to be added $AWS_BUCKET_POLICY"

echo $( (aws s3api put-bucket-policy --bucket $MY_AWS_S3_BUCKET_NAME --policy "$AWS_BUCKET_POLICY"))

echo "Bucket configuration updated"

echo "Enter the backend endpoint your Hyperswitch Client will hit (hosted Hyperswitch Backend, https://sandbox.hyperswitch.io is taken by default):"
read AWS_BACKEND_URL </dev/tty

if [ -z $AWS_BACKEND_URL ]; then
echo "Setting backend URL value to https://sandbox.hyperswitch.io by default"
AWS_BACKEND_URL="https://sandbox.hyperswitch.io"

fi

export envSdkUrl="${AWS_BUCKET_LOCATION%?}"
export envBackendUrl=$AWS_BACKEND_URL
npm run build

echo "Inititating file upload to S3"
echo "Enter the folder name you want to push the assets to"
read AWS_DESTINATION_KEY </dev/tty

echo "Uploading files to S3"
echo $( (aws s3 cp "./dist" "s3://$MY_AWS_S3_BUCKET_NAME/$AWS_DESTINATION_KEY" --recursive))
echo "Uploaded files "

echo "Hurray! You now have hosted your Hyperswitch Web to S3! You can use this URL for your integrations : $AWS_BUCKET_LOCATION$AWS_DESTINATION_KEY/HyperLoader.js"
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"build:dev-integ": "sdkEnv=integ webpack --config webpack.dev.js",
"start": "sdkEnv=local webpack --config webpack.dev.js && webpack serve --config webpack.dev.js",
"build:prod": "sdkEnv=prod webpack --config webpack.common.js",
"build": "webpack --config webpack.common.js",
"build:sandbox": "sdkEnv=sandbox webpack --config webpack.common.js",
"build:integ": "sdkEnv=integ webpack --config webpack.common.js",
"test": "react-scripts test",
Expand Down
4 changes: 2 additions & 2 deletions webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ let repoName = require("./package.json").name;
let repoPublicPath = `/${repoVersion}/${majorVersion}`;

const sdkEnv = process.env.sdkEnv;
const envSdkUrl = process.env.envSdkUrl;
const envBackendUrl = process.env.envBackendUrl;
const envSdkUrl = JSON.stringify(process.env.envSdkUrl);
const envBackendUrl = JSON.stringify(process.env.envBackendUrl);

let sdkUrl;

Expand Down

0 comments on commit 7578307

Please sign in to comment.