Skip to content

Added Windows deployment method (deploy.ps1) #81

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ cdk.out
work/
aggregated_results.txt
.vscode
.idea
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ The calculator has two main components:
![Architecture](frontend/public/img/fig2_arc.png?raw=true "Architecture")

## Pre-requisites
* A linux-based OS (no Windows deployment script yet)
* NodeJS (version 18 or later) and NPM.
* A Windows or Linux based OS (use `.\deploy.ps1` for Windows and `./deploy.sh` for Linux)
* NodeJS (version 18 or later) and NPM (version 7.2 or later)
[Node](http://nodejs.org/) and [NPM](https://npmjs.org/) are really easy to install.
To make sure you have them available on your machine,
try running the following command.

```sh
$ npm -v && node -v
7.24.2
v18.16.1
10.5.0
v18.18.2
```
* The AWS CDK installed (you can install with `npm install -g aws-cdk`).
```sh
$ cdk --version
2.124.0 (build 4b6724c)
2.162.1 (build 10aa526)
```
* If you have never used the AWS CDK in the current account and Region, run bootstrapping with npx cdk bootstrap.
```sh
Expand All @@ -51,13 +51,20 @@ $ aws sts get-caller-identity
}
```

## How to deploy
## How to deploy - Linux OS (Bash)
Run the deployment script from the project's root directory:

```sh
$ ./deploy.sh
```

## How to deploy - Windows OS (PowerShell)
Run the deployment PowerShell script from the project's root directory:

```powershell
$ .\deploy.ps1
```

## How to destroy

```sh
Expand Down
51 changes: 51 additions & 0 deletions deploy.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Navigate to the backend directory and deploy the backend stack
Set-Location -Path "backend"
npm install
New-Item -Path "../frontend/build" -ItemType Directory -Force
cdk deploy NetCalcBackendStack --require-approval never

# Retrieve the outputs from the CloudFormation stack
$NETCALC_API_URL = (aws cloudformation describe-stacks --stack-name NetCalcBackendStack --query "Stacks[0].Outputs[?OutputKey=='apiUrl'].OutputValue" --output text)
$NETCALC_CIDP_ID = (aws cloudformation describe-stacks --stack-name NetCalcBackendStack --query "Stacks[0].Outputs[?OutputKey=='identityPoolId'].OutputValue" --output text)
$NETCALC_SCRAPER_LAMBDA = (aws cloudformation describe-stacks --stack-name NetCalcBackendStack --query "Stacks[0].Outputs[?OutputKey=='pricingScraperLambda'].OutputValue" --output text)
$NETCALC_REGION = $NETCALC_CIDP_ID.Split(":")[0]

# Invoke the scraper Lambda function to populate pricing data
Write-Host "`n`n****************************************************************************"
Write-Host "Invoking the pricing scraper Lambda function for the first time, this may take a few minutes, please wait..."
aws lambda invoke --function-name $NETCALC_SCRAPER_LAMBDA --cli-read-timeout 0 --cli-binary-format raw-in-base64-out tmpresponse.json
Remove-Item tmpresponse.json

# Generate the aws-exports.js file for the frontend
@"
const awsconfig = {
"aws_project_region": "$NETCALC_REGION",
"aws_cognito_identity_pool_id": "$NETCALC_CIDP_ID",
"aws_cognito_region": "$NETCALC_REGION",
"aws_appsync_graphqlEndpoint": "$NETCALC_API_URL",
"aws_appsync_region": "$NETCALC_REGION",
"aws_appsync_authenticationType": "AWS_IAM",
"API": {
"NetCalcAPI": {
"endpoint": "$NETCALC_API_URL",
"authMode": "iam"
}
}
};

export default awsconfig;
"@ | Out-File -FilePath "../frontend/src/aws-exports.js" -Encoding UTF8

# Navigate to the frontend directory, install dependencies, and build the app
Set-Location -Path "../frontend"
npm install
npm run build

# Deploy the frontend stack
Set-Location -Path "../backend"
Remove-Item -Recurse -Force cdk.out
cdk deploy NetCalcFrontendStack --require-approval never
$NETCALC_FRONTEND_URL = (aws cloudformation describe-stacks --stack-name NetCalcFrontendStack --query "Stacks[0].Outputs[?OutputKey=='frontendUrl'].OutputValue" --output text)

Write-Host "**********************************************************************************************************"
Write-Host "The NetCalc app is deployed and the frontend URL can be accessed from $NETCALC_FRONTEND_URL"