Skip to content
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

Prod Deployment - 20240709 #49

Merged
merged 2 commits into from
Jul 9, 2024
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
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,12 @@ yarn-debug.log*
yarn-error.log*

.idea

# https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
894 changes: 894 additions & 0 deletions .yarn/releases/yarn-4.3.0.cjs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.3.0.cjs
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ The directories:

See CDK readme at deploy directory. [CDK readme](deploy/README.md)

**React**
1. Install React dependancy
`npm i`
2. Fetch ENV variables from AWS Systems Manager Parameter Store. (This will store environment variable needed to the terminal)
**Run locally**

1. Install React dependency
`yarn install`
2. Set AWS Profile that has permission to get SSM Parameter variables
`export AWS_PROFILE=dev`
3. Run the script that sets variable from SSM Parameter
`source get_env.sh`
3. Start the project and will be running at *http://localhost:3000/*
`npm start`
4. Start the project and will be running at *http://localhost:3000/*
`yarn start`
6 changes: 3 additions & 3 deletions buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ phases:
runtime-versions:
nodejs: 18
commands:
- npm i react-scripts
- yarn install
build:
commands:
- set -eu
- env | grep REACT
- npm run build
- npm run deploy
- yarn run build
- yarn run deploy
39 changes: 23 additions & 16 deletions deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,50 @@ It is recommended to create a virtual environment for the app.
To do so please follow the instructions below.

Change your directory to the root of this readme file.

```sh
cd deploy
```
$ cd deploy
```

Create a virtual environment for the app.

```sh
virtualenv .venv --python=python3.11
```
$ virtualenv .venv --python=python3.11
```


After the init process completes and the virtualenv is created, you can use the following
step to activate your virtualenv.

```
$ source .venv/bin/activate
```sh
source .venv/bin/activate
```

Once the virtualenv is activated, you can install the required dependencies.

```sh
pip install -r requirements.txt
```
$ pip install -r requirements.txt
```


# Stack Deployment

**Prerequisite**
- A valid SSL Certificate in `us-east-1` region at ACM for all the domain name needed. See [here](app.py#L39) (`alias_domain_name` on the props variable) on what domain need to be included, determined based on which account is deployed.

- A valid SSL Certificate in `us-east-1` region at ACM for all the domain names needed. See [here](app.py#L39) (`alias_domain_name` on the props variable) on what domain needs to be included, determined based on which account is deployed.
- SSM Parameter for the certificate ARN created above with the name of `/sscheck/ssl_certificate_arn`

_Deploying the stack without prerequisite above may result in a stack rollback._
_Deploying the _stack without _the _prerequisite__ above may_ result in a stack rollback._

There are 2 stacks in this application:
- *sscheck_front_end* - Contains the applications stack
- *pipeline* - Contains the pipeline for the stack to run and self update

To deploy the application stack, you will need to deploy the `pipeline` stack. The pipeline stack will take care of the `sscheck_front_end` stack deployment.
- *SSCheckFrontEndPipeline/SampleSheetCheckFrontEndStage/SampleSheetCheckFrontEnd* - Contains the applications stack
- *SSCheckFrontEndPipeline* - Contains the pipeline for the stack to run and self-update

To deploy the application stack, you will need to deploy the `pipeline` stack. The pipeline stack will take care of the
deployment stack.

Deploy pipeline stack
```
$ cdk deploy SSCheckFrontEndCdkPipeline --profile={AWS_PROFILE}

```sh
yarn cdk deploy SSCheckFrontEndCdkPipeline --profile={AWS_PROFILE}
```
15 changes: 8 additions & 7 deletions deploy/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,35 @@
account_id = os.environ.get('CDK_DEFAULT_ACCOUNT')
aws_region = os.environ.get('CDK_DEFAULT_REGION')

# Determine account stage (Identify if it is running on prod or dev)
if account_id == "472057503814": # Account number used for production environment
# Determine account stage (Identify if it is running on prod, stg, or dev)
if account_id == "472057503814": # Prod account
app_stage = "prod"
elif account_id == "455634345446": # Staging account
app_stage = "stg"
else:
app_stage = "dev"


props = {
"app_stack_name": "sscheck-front-end-stack",
"pipeline_name": {
"dev": "sscheck-frontend",
"prod": "sscheck-frontend"
},
"pipeline_artifact_bucket_name" :{
"dev": "sscheck-front-end-artifact-dev",
"stg": "sscheck-front-end-artifact-stg",
"prod": "sscheck-front-end-artifact-prod"
},
"client_bucket_name": {
"dev": "org.umccr.dev.sscheck",
"stg": "org.umccr.stg.sscheck",
"prod": "org.umccr.prod.sscheck"
},
"repository_source": "umccr/samplesheet-check-frontend",
"branch_source": {
"dev": "dev",
"stg": "stg",
"prod": "main"
},
"alias_domain_name":{
"dev": ["sscheck.dev.umccr.org"],
"stg": ["sscheck.stg.umccr.org"],
"prod": ["sscheck.umccr.org", "sscheck.prod.umccr.org"]
}
}
Expand Down
29 changes: 14 additions & 15 deletions deploy/stacks/pipeline_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
aws_codepipeline_actions as codepipeline_actions,
aws_iam as iam,
aws_codebuild as codebuild,
aws_sns as sns,
aws_codestarnotifications as codestarnotifications
aws_codestarnotifications as codestarnotifications,
aws_chatbot as chatbot
)
from stacks.sscheck_front_end_stack import SampleSheetCheckFrontEndStack

Expand Down Expand Up @@ -76,12 +76,12 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
artifact_bucket=pipeline_artifact_bucket,
restart_execution_on_update=True,
cross_account_keys=False,
pipeline_name=props["pipeline_name"][app_stage],
pipeline_name="sscheck-frontend",
)

# Create codestar connection fileset
code_pipeline_source = pipelines.CodePipelineSource.connection(
repo_string=props["repository_source"],
repo_string="umccr/samplesheet-check-frontend",
branch=props["branch_source"][app_stage],
connection_arn=codestar_arn,
trigger_on_push=True
Expand All @@ -102,11 +102,11 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
"CDKShellScript",
input=code_pipeline_source,
commands=[
"cdk synth",
"yarn cdk synth",
],
install_commands=[
"yarn install",
"cd deploy",
"npm install -g aws-cdk",
"pip install -r requirements.txt"
],
primary_output_directory="deploy/cdk.out"
Expand Down Expand Up @@ -289,24 +289,23 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
]
)

# SSM parameter for AWS SNS ARN
data_portal_notification_sns_arn = ssm.StringParameter.from_string_parameter_attributes(
# SSM parameter for AWS Slack Alerts Chatbot ARN
chatbot_alerts_arn = ssm.StringParameter.from_string_parameter_attributes(
self,
"DataPortalSNSArn",
parameter_name="/data_portal/backend/notification_sns_topic_arn"
"ChatbotAlertsARN",
parameter_name="/chatbot/slack/umccr/alerts-arn"
).string_value

# SNS chatbot
data_portal_sns_notification = sns.Topic.from_topic_arn(
chatbot_slack_alerts = chatbot.SlackChannelConfiguration.from_slack_channel_configuration_arn(
self,
"DataPortalSNS",
topic_arn=data_portal_notification_sns_arn
'SlackAlertsChannelConfiguration',
chatbot_alerts_arn
)

# Add Chatbot Notification
self_mutate_pipeline.pipeline.notify_on(
"SlackNotificationSSCheckFrontEnd",
target=data_portal_sns_notification,
target=chatbot_slack_alerts,
events=[
codepipeline.PipelineNotificationEvents.PIPELINE_EXECUTION_FAILED,
codepipeline.PipelineNotificationEvents.PIPELINE_EXECUTION_SUCCEEDED
Expand Down
Loading