Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

docs: Add instructions for local development #107

Merged
merged 4 commits into from
Sep 21, 2020
Merged
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ coverage
serverless-output.yml
serverless-output.yaml
serverless_config.json

.yalc
yalc.lock
nguyen102 marked this conversation as resolved.
Show resolved Hide resolved
nguyen102 marked this conversation as resolved.
Show resolved Hide resolved

50 changes: 50 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# FHIR Works on AWS Development Instructions

In this guide we will go over how to develop and run the code locally. We will also go over how to deploy your local code packages to your AWS account.

## Prerequisites

- **Initial Install:** Please complete this [installation guide](./INSTALL.md) and get the initial `fhir-works-on-aws` code deployed to your AWS account.
- **Yalc**: We'll be using this to manage local packages, so please have [this package](https://github.com/whitecolor/yalc) installed on your system.

## Development

Please download all the `fhir-works-on-aws` package and place them inside one directory. Your parent directory should have these folders inside of them
```
./fhir-works-on-aws-deployment
./fhir-works-on-aws-interface
./fhir-works-on-aws-persistence-ddb
./fhir-works-on-aws-search-es
./fhir-works-on-aws-authz-rbac
./fhir-works-on-aws-routing
```

Copy these files to your parent directory
- [fhir-works-local-develop.sh](./scripts/fhir-works-deploy.sh)
- [fhir-works-deploy.sh](./scripts/fhir-works-deploy.sh)
- [fhir-works-deploy-one-time-setup.sh](./scripts/fhir-works-deploy-one-time-setup.sh)

Run `./fhir-works-local-develop.sh` from the parent directory. This script will use `yarn` to link your `persistence`, `search`, `authz`, and `routing` package to your `interface` package. It will then link all five of those packages to your `deployment` package.

Once the script has finished running, you can run `yarn watch` in the directory of each package that you're developing in. This will pick up live changes from the packages. Then you can run this command in the `deployment` package directory to spin up your local environment:

`AWS_ACCESS_KEY_ID=<Access-Key> AWS_SECRET_ACCESS_KEY=<Secret-Key> OFFLINE_BINARY_BUCKET=<FHIRBinaryBucket> OFFLINE_ELASTICSEARCH_DOMAIN_ENDPOINT=<ElasticSearchDomainEndpoint> serverless offline start`

If you don't know the `OFFLINE_BINARY_BUCKET` and `OFFLINE_ELASTICSEARCH_DOMAIN_ENDPOINT` value, you can run `serverless info --verbose` in the deployment package directory.

## Deploy Local Packages to AWS

If you have made changes to the `fhir-works-on-aws` packages, and you would like to deploy those changes to your AWS account, follow the instructions below.

Before continuing with the rest of this section, be sure that you have followed the steps in the [**Development section**](#development) to set up your folder structure.

If this is your first time deploying your local changes to AWS, we will need to set up `yalc` to publish your packages to the local package registry. You can do that by running this command from the parent directory: `./fhir-works-deploy-one-time-setup.sh`

Once your packages have been published to the local package registry, run this command to package your code for deployment: `./fhir-works-deploy.sh`.

**Note:** Before running the deploy script, remember to add the latest version of the `deployment` package's `package.json` file into Git. The deploy script will make changes to the `deployment` package's `package.json` file.

The deploy script will push all of your packages, except for the `deployment` package to the local package registry. It will then go into your `deployment` folder, and add those local packages as dependencies. It then pulls those local packages into the `deployment` package so that you are ready to run `serverless deploy`

Run this command to deploy your code to AWS:
`serverless deploy --aws-profile <PROFILE> --stage <STAGE>`
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ git clone https://github.com/awslabs/fhir-works-on-aws-deployment.git
- [Windows](./INSTALL.md#windows-installation)
- [Docker](./INSTALL.md#docker-installation)


### Development

[Instructions for making local code changes](./DEVELOPMENT.md)

## Architecture

The system architecture consists of multiple layers of AWS serverless services. The endpoint is hosted using API Gateway. The database and storage layer consists of Amazon DynamoDB and S3, with Elasticsearch as the search index for the data written to DynamoDB. The endpoint is secured by API keys and Cognito for user-level authentication and user-group authorization. The diagram below shows the FHIR server’s system architecture components and how they are related.
Expand Down
26 changes: 26 additions & 0 deletions scripts/fhir-works-deploy-one-time-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

yalc
# Yalc is used as a local package registry to allow your packages to be packages together and compiled. This allows serverless to correctly package everything together and deploy to AWS
if [ $? -ne 0 ]
then
printf "\nPlease install yalc. You can run this command to install yalc: 'npm i yalc -g'"
exit 1
fi

packages=(
"fhir-works-on-aws-authz-rbac"
"fhir-works-on-aws-persistence-ddb"
"fhir-works-on-aws-routing"
"fhir-works-on-aws-search-es"
"fhir-works-on-aws-interface"
)

printf "\nPublish packages to yalc local package registry"
for i in "${packages[@]}"
do
cd $i
yarn install
yalc publish
cd ..
done
54 changes: 54 additions & 0 deletions scripts/fhir-works-deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash -e
carvantes marked this conversation as resolved.
Show resolved Hide resolved

read -n 1 -p "This script adds local dependencies to your 'fhir-works-on-aws-deployment' package during build. It will then revert your 'package.json' to the last version of the package in Git. Have you committed the 'package.json' file in your 'fhir-works-on-aws-deployment' package to Git (y/n)?" answer
if [ $answer != "y" ]
then
printf "\nPlease commit the package.json file in your 'fhir-works-on-aws-deployment' package to Git"
exit
fi

packages=(
"fhir-works-on-aws-authz-rbac"
"fhir-works-on-aws-persistence-ddb"
"fhir-works-on-aws-routing"
"fhir-works-on-aws-search-es"
)

# Go into interface package, delete old pregenerated files, install all dependencies again, and then push the package to yalc
cd fhir-works-on-aws-interface
rm -rf node_modules build/* dist/*
yarn install
yalc push

cd ..

printf "\nFor each package except for deployment and interface package, add interface package as a dependency, remove old pregenerated files, install all dependencies again, and push new packages to yalc\n"
for i in "${packages[@]}"
do
cd $i
rm -rf node_modules build/* dist/*
carvantes marked this conversation as resolved.
Show resolved Hide resolved
yalc add fhir-works-on-aws-interface
yarn install
yalc push
yalc remove fhir-works-on-aws-interface
cd ..
done

printf "\nFor deployment package, remove old pregenerated files, add all other packages as dependencies, install all dependencies again"
cd fhir-works-on-aws-deployment
rm -rf node_modules build/* dist/*
yalc add fhir-works-on-aws-interface
for i in "${packages[@]}"
do
yalc add $i
done
yarn install


printf "\nReverting package.json changes. Serverless pack does not play well with local dependencies added by yalc\n"

git checkout package.json

printf "\nYou can now go to your deployment package and deploy using serverless. You can deploy using the command 'serverless deploy --aws-profile <PROFILE> --stage <STAGE>'"

cd ..
36 changes: 36 additions & 0 deletions scripts/fhir-works-local-develop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash -e
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried using yalc links to do local development, but this is a very tedious process. Every time you make a change to a local package:

  1. You have to do yalc push to push it to the local package manager.
  2. You have to remove all node modules in development package.
  3. You then relink the dependent packages in the deployment package.
  4. You then do yarn install.

Using yarn links is much faster.


packages=(
"fhir-works-on-aws-persistence-ddb"
"fhir-works-on-aws-routing"
"fhir-works-on-aws-search-es"
"fhir-works-on-aws-authz-rbac"
)

cd fhir-works-on-aws-interface
yarn link
yarn install
cd ..

for i in "${packages[@]}"
do
cd $i
yarn link
yarn link fhir-works-on-aws-interface
yarn install
cd ..
done

cd fhir-works-on-aws-deployment
yarn link fhir-works-on-aws-interface
for i in "${packages[@]}"
do
yarn link $i
done
yarn install

cd ..

printf "\nRun 'yarn watch' in the folder of each package that you're developing in. This will pick up live changes from the package. You can then run this command in the deployment package to run the code locally. 'AWS_ACCESS_KEY_ID=<Access-Key> AWS_SECRET_ACCESS_KEY=<Secret-Key> OFFLINE_BINARY_BUCKET=<FHIRBinaryBucket> OFFLINE_ELASTICSEARCH_DOMAIN_ENDPOINT=<ElasticSearchDomainEndpoint> sls offline start"

printf "\n\nIf you don't know the OFFLINE_BINARY_BUCKET and OFFLINE_ELASTICSEARCH_DOMAIN_ENDPOINT value, you can run 'sls info --verbose' in the deployment package"