-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployReact.sh
executable file
·40 lines (34 loc) · 1.11 KB
/
deployReact.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
while getopts k:h:s: flag
do
case "${flag}" in
k) key=${OPTARG};;
h) hostname=${OPTARG};;
s) service=${OPTARG};;
esac
done
if [[ -z "$key" || -z "$hostname" || -z "$service" ]]; then
printf "\nMissing required parameter.\n"
printf " syntax: deployReact.sh -k <pem key file> -h <hostname> -s <service>\n\n"
exit 1
fi
printf "\n----> Deploying React bundle $service to $hostname with $key\n"
# Step 1
printf "\n----> Build the distribution package\n"
rm -rf build
mkdir build
npm install # make sure vite is installed so that we can bundle
npm run build # build the React front end
cp -rf dist/* build # move the React front end to the target distribution
# Step 2
printf "\n----> Clearing out previous distribution on the target\n"
ssh -i "$key" ubuntu@$hostname << ENDSSH
rm -rf services/${service}/public
mkdir -p services/${service}/public
ENDSSH
# Step 3
printf "\n----> Copy the distribution package to the target\n"
scp -r -i "$key" build/* ubuntu@$hostname:services/$service/public
# Step 5
printf "\n----> Removing local copy of the distribution package\n"
rm -rf build
rm -rf dist