This repository has been archived by the owner on Nov 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.sh
88 lines (77 loc) · 2.88 KB
/
start.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env source
# -*- coding: utf-8 -*-
# This wrapper script is mainly for local development purpose only.
#
# Sourcing this script will perform:
# 1. get required config values from SSM Parameter Store
# 2. export them as REACT_x environment variables
#
# REQUIRED CLI:
# aws, jq
#
# USAGE:
#
# Otherwise source it standalone itself by:
# source start.sh
# source start.sh unset
#
# CAVEATS:
# If your Portal Django backend is not running on :8000, then before start
# you can override by, e.g. export DATA_PORTAL_API_URL=localhost:5000
#
# Try to be POSIX-y. Only tested on macOS! Contrib welcome for other OSs.
if [ "$(ps -p $$ -ocomm=)" = 'zsh' ] || [ "${BASH_SOURCE[0]}" -ef "$0" ]
then
ps -p $$ -oargs=
echo "YOU SHOULD SOURCE THIS SCRIPT, NOT EXECUTE IT!"
exit 1
fi
command -v aws >/dev/null 2>&1 || {
echo >&2 "AWS CLI COMMAND NOT FOUND. ABORTING..."
return 1
}
command -v jq >/dev/null 2>&1 || {
echo >&2 "JQ COMMAND NOT FOUND. ABORTING..."
return 1
}
if [ -n "$1" ] && [ "$1" = "unset" ]; then
unset VITE_BUCKET_NAME
unset VITE_DATA_PORTAL_API_DOMAIN
unset VITE_REGION
unset VITE_COG_USER_POOL_ID
unset VITE_COG_APP_CLIENT_ID
unset VITE_OAUTH_DOMAIN
unset VITE_OAUTH_REDIRECT_IN
unset VITE_OAUTH_REDIRECT_OUT
echo "UNSET REACT ENV VAR"
return 0
fi
# Parameter is taken from data-portal-client
# Reference: https://github.com/umccr/data-portal-client
cog_user_pool_id=$(aws ssm get-parameter --name '/data_portal/client/cog_user_pool_id' | jq -r .Parameter.Value)
if [[ "$cog_user_pool_id" == "" ]]; then
echo "Halt, No valid AWS login session found. Please 'aws sso login --profile dev && export AWS_PROFILE=dev'"
return 1
fi
cog_app_client_id_local=$(aws ssm get-parameter --name '/data_portal/client/cog_app_client_id_local' | jq -r .Parameter.Value)
data_portal_client_domain=$(aws ssm get-parameter --name '/hosted_zone/umccr/name' | jq -r .Parameter.Value)
oauth_domain=$(aws ssm get-parameter --name '/data_portal/client/oauth_domain' | jq -r .Parameter.Value)
oauth_redirect_in_local=$(aws ssm get-parameter --name '/data_portal/client/oauth_redirect_in_local' | jq -r .Parameter.Value)
oauth_redirect_out_local=$(aws ssm get-parameter --name '/data_portal/client/oauth_redirect_out_local' | jq -r .Parameter.Value)
# Status page parameter
bucket_name=$(aws ssm get-parameter --name '/data_portal/status_page/bucket_name' | jq -r .Parameter.Value)
# App
export VITE_BUCKET_NAME=$bucket_name
export VITE_DATA_PORTAL_API_DOMAIN=localhost:8000
export VITE_REGION=ap-southeast-2
export VITE_UMCCR_DOMAIN_NAME=$data_portal_client_domain
# Cognito
export VITE_COG_USER_POOL_ID=$cog_user_pool_id
export VITE_COG_APP_CLIENT_ID=$cog_app_client_id_local
# Oauth
export VITE_OAUTH_DOMAIN=$oauth_domain
export VITE_OAUTH_REDIRECT_IN=$oauth_redirect_in_local
export VITE_OAUTH_REDIRECT_OUT=$oauth_redirect_out_local
env | grep VITE
# start the app
yarn run -B vite