-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathdeploy-nrrd.sh
More file actions
executable file
·124 lines (106 loc) · 3.44 KB
/
deploy-nrrd.sh
File metadata and controls
executable file
·124 lines (106 loc) · 3.44 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/bash
# Function to display spinner
show_spinner() {
local pid=$1
local delay=0.1
local spin='|/-\'
while kill -0 $pid 2>/dev/null; do
for ((i=0; i<${#spin}; i++)); do
echo -ne "\r${spin:$i:1} " > /dev/tty # Ensure spinner only appears in terminal
sleep $delay
done
done
echo -ne "\r✔ \n" > /dev/tty # Ensure completion message only appears in terminal
}
# Redirect all output to a log file (silent in terminal)
exec > deploy-nrrd.log 2>&1
# handle preview deployments
echo -n "Is this deployment for preview? (y/n) " > /dev/tty
read is_preview < /dev/tty
if [ "$is_preview" = "y" ]; then
echo -n "Enter your Github branch to deploy to: " > /dev/tty
read circle_branch < /dev/tty
hasura_uri="https://hasura-sandbox.app.cloud.gov/v1/graphql"
stage="nrrd-preview"
else
echo -n "Enter the cloud.gov space you are targeting: " > /dev/tty
read space < /dev/tty
# Check if cf is logged in
echo "Checking to see if you're logged in to cf..." > /dev/tty
cf apps > /dev/null 2>&1 &
pid=$!
show_spinner $pid
wait $pid
if [ $? -ne 0 ]; then
echo -n "Enter a temporary authentication code ( Get one at https://login.fr.cloud.gov/passcode ): " > /dev/tty
read -s sso_passcode < /dev/tty
echo > /dev/tty
echo "Logging in to cf..." > /dev/tty
cf login -a api.fr.cloud.gov -o doi-onrr -s $space --sso-passcode $sso_passcode &
pid=$!
show_spinner $pid
wait $pid || { echo "cf login failed. Check the log file. Exiting..." > /dev/tty; exit 1; }
else
echo "Targeting cf space..." > /dev/tty
cf target -s $space &
pid=$!
show_spinner $pid
wait $pid || { echo "cf target failed. Check the log file. Exiting..." > /dev/tty; exit 1; }
fi
# Validate space and set branch
if [ "$space" = "prod" ]; then
circle_branch="master"
app="nrrd"
elif [ "$space" = "dev" ]; then
circle_branch="dev"
app="dev-nrrd"
else
echo "Unknown space: $space"
exit 1
fi
hasura_uri="https://hasura-${space}.app.cloud.gov/v1/graphql"
stage="${space}"
fi
export CIRCLE_BRANCH="${circle_branch}"
export CIRCLE_STAGE="${stage}"
export GATSBY_HASURA_URI="${hasura_uri}"
# Install npm deps if they aren't installed
if [ ! -d "node_modules" ]; then
echo "npm deps not installed. Installing now..." > /dev/tty
npm install --legacy-peer-deps &
pid=$!
show_spinner $pid
wait $pid || { echo "npm install failed. Exiting..."; exit 1; }
fi
# Sync downloads from AWS
echo "Syncing downloads..." > /dev/tty
aws s3 sync "s3://${AWS_BUCKET_NAME}/downloads/" ./static/downloads &
pid=$!
show_spinner $pid
wait $pid || { echo "AWS sync failed. Check the log file. Exiting..." > /dev/tty; exit 1; }
# Cleaning
echo "Cleaning..." > /dev/tty
npm run clean &
pid=$!
show_spinner $pid
wait $pid || { echo "clean failed. Check the log file. Exiting..." > /dev/tty; exit 1; }
# Building
echo "Building..." > /dev/tty
npm run build &
pid=$!
show_spinner $pid
wait $pid || { echo "build failed. Check the log file. Exiting..." > /dev/tty; exit 1; }
cp Staticfile ./public
mv ./public/~partytown ./public/_partytown
# Deploying
echo "Deploying..." > /dev/tty
if [ "$is_preview" = "n" ]; then
cf push $app -f manifest.yml &
else
aws s3 sync public "s3://${AWS_BUCKET_NAME}/sites/${CIRCLE_BRANCH}/" &
fi
pid=$!
show_spinner $pid
wait $pid || { echo "Deployment failed. Check the log file. Exiting..." > /dev/tty; exit 1; }
echo "NRRD build and deploy to ${space} completed successfully." > /dev/tty
exit 0