2021-01-29 01:28:49 +00:00
|
|
|
#########################################################################################
|
|
|
|
echo ""
|
|
|
|
echo "Creating production deployment packages for Saleor Dashboard..."
|
|
|
|
echo ""
|
|
|
|
#########################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#########################################################################################
|
|
|
|
# Collect input from the user to assign required installation parameters
|
|
|
|
#########################################################################################
|
2021-02-05 02:11:19 +00:00
|
|
|
echo "Please provide details for your Saleor Dashboard installation..."
|
2021-01-29 01:28:49 +00:00
|
|
|
echo ""
|
|
|
|
# Get the Dashboard & GraphQL host domain
|
2021-02-05 02:11:19 +00:00
|
|
|
while [ "$SAME_HOST" = "" ]
|
2021-01-29 01:28:49 +00:00
|
|
|
do
|
2021-02-05 02:11:19 +00:00
|
|
|
echo -n "Are you hosting the Dashboard on the same host domain as the API (yes|no)?"
|
|
|
|
read SAME_HOST
|
2021-01-29 01:28:49 +00:00
|
|
|
done
|
|
|
|
# Get the API host IP or domain
|
2021-02-05 02:51:51 +00:00
|
|
|
if [ "$SAME_HOST" = "no" ]; then
|
2021-02-05 02:11:19 +00:00
|
|
|
while [ "$APP_HOST" = "" ]
|
|
|
|
do
|
|
|
|
echo ""
|
|
|
|
echo -n "Enter the Dashboard host domain:"
|
|
|
|
read APP_HOST
|
|
|
|
done
|
|
|
|
fi
|
2021-01-29 01:28:49 +00:00
|
|
|
# Get the APP Mount (Dashboard) URI
|
|
|
|
while [ "$APP_MOUNT_URI" = "" ]
|
|
|
|
do
|
|
|
|
echo ""
|
|
|
|
echo -n "Enter the APP Mount (Dashboard) URI:"
|
|
|
|
read APP_MOUNT_URI
|
|
|
|
done
|
|
|
|
#########################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#########################################################################################
|
2021-02-05 06:08:14 +00:00
|
|
|
# Clone the git and setup the environment variables for Saleor API & Dashboard install
|
2021-01-29 01:28:49 +00:00
|
|
|
#########################################################################################
|
2021-02-05 06:08:14 +00:00
|
|
|
# Make sure we're in the user's home directory
|
|
|
|
cd $HD
|
|
|
|
# Clone the Saleor Dashboard Git repository
|
2021-02-05 06:34:10 +00:00
|
|
|
if [ -d "$HD/saleor-dashboard" ]; then
|
2021-02-05 06:08:14 +00:00
|
|
|
sudo rm -R $HD/saleor-dashboard
|
|
|
|
fi
|
2021-02-05 06:29:08 +00:00
|
|
|
sudo -u $UN git clone https://github.com/mirumee/saleor-dashboard.git
|
2021-02-05 06:08:14 +00:00
|
|
|
wait
|
2021-01-29 01:28:49 +00:00
|
|
|
# Build the API URL
|
2021-02-10 05:18:08 +00:00
|
|
|
API_URL="https://$HOST/$APIURI/"
|
2021-01-29 01:28:49 +00:00
|
|
|
# Write the production .env file from template.env
|
2021-02-05 02:51:51 +00:00
|
|
|
if [ "$SAME_HOST" = "no" ]; then
|
2021-02-05 02:11:19 +00:00
|
|
|
sudo sed "s|{api_url}|$API_URL|
|
|
|
|
s|{app_mount_uri}|$APP_MOUNT_URI|
|
2021-02-06 02:47:14 +00:00
|
|
|
s|{app_host}|$APP_HOST/$APP_MOUNT_URI|" $HD/Deploy_Saleor/resources/saleor-dashboard/template.env > $HD/saleor-dashboard/.env
|
2021-02-05 02:11:19 +00:00
|
|
|
wait
|
|
|
|
else
|
|
|
|
sudo sed "s|{api_url}|$API_URL|
|
|
|
|
s|{app_mount_uri}|$APP_MOUNT_URI|
|
2021-02-06 02:47:14 +00:00
|
|
|
s|{app_host}|$HOST/$APP_MOUNT_URI|" $HD/Deploy_Saleor/resources/saleor-dashboard/template.env > $HD/saleor-dashboard/.env
|
2021-02-05 02:11:19 +00:00
|
|
|
wait
|
|
|
|
fi
|
2021-01-29 01:28:49 +00:00
|
|
|
#########################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#########################################################################################
|
|
|
|
# Build Saleor Dashboard for production
|
|
|
|
#########################################################################################
|
|
|
|
# Make sure we're in the project root directory
|
|
|
|
cd saleor-dashboard
|
|
|
|
# Was the -v (version) option used?
|
2021-02-10 04:24:49 +00:00
|
|
|
if [ "vOPT" = "true" ] || [ "$VERSION" != "" ]; then
|
2021-02-10 01:16:42 +00:00
|
|
|
sudo -u $UN git checkout $VERSION
|
2021-01-29 01:28:49 +00:00
|
|
|
fi
|
2021-02-11 06:58:24 +00:00
|
|
|
# Update npm
|
|
|
|
npm install -g npm@next
|
|
|
|
wait
|
2021-01-29 01:28:49 +00:00
|
|
|
# Install dependancies
|
2021-02-05 06:29:08 +00:00
|
|
|
sudo -u $UN npm i
|
2021-01-29 01:28:49 +00:00
|
|
|
wait
|
2021-02-05 06:29:08 +00:00
|
|
|
sudo -u $UN npm run build
|
2021-01-29 01:28:49 +00:00
|
|
|
wait
|
|
|
|
#########################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
#########################################################################################
|
2021-02-05 02:11:19 +00:00
|
|
|
# Setup the nginx block and move the static build files
|
2021-01-29 01:28:49 +00:00
|
|
|
#########################################################################################
|
2021-02-05 02:11:19 +00:00
|
|
|
echo "Moving static files for the Dashboard..."
|
|
|
|
echo ""
|
|
|
|
if [ "$SAME_HOST" = "no" ]; then
|
|
|
|
# Move static files for the Dashboard
|
2021-02-10 04:32:54 +00:00
|
|
|
sudo mv $HD/saleor-dashboard/build/$APP_MOUNT_URI /var/www/$APP_HOST/
|
2021-02-05 02:11:19 +00:00
|
|
|
# Make an empry variable
|
|
|
|
DASHBOARD_LOCATION=""
|
|
|
|
# Clean the saleor server block
|
2021-02-06 02:47:14 +00:00
|
|
|
sudo sed -i "s#{dl}#$DASHBOARD_LOCATION#" /etc/nginx/sites-available/saleor
|
2021-02-05 02:11:19 +00:00
|
|
|
# Create the saleor-dashboard server block
|
|
|
|
sudo sed "s|{hd}|$HD|g
|
|
|
|
s/{app_mount_uri}/$APP_MOUNT_URI/g
|
|
|
|
s/{host}/$APP_HOST/g" $HD/Deploy_Saleor/resources/saleor-dashboard/server_block > /etc/nginx/sites-available/saleor-dashboard
|
|
|
|
wait
|
2021-02-07 00:44:29 +00:00
|
|
|
sudo chown -R www-data /var/www/$APP_HOST
|
2021-02-05 02:11:19 +00:00
|
|
|
echo "Enabling server block and Restarting nginx..."
|
|
|
|
sudo ln -s /etc/nginx/sites-available/saleor-dashboard /etc/nginx/sites-enabled/
|
|
|
|
else
|
|
|
|
# Move static files for the Dashboard
|
2021-02-10 04:32:54 +00:00
|
|
|
sudo mv $HD/saleor-dashboard/build/$APP_MOUNT_URI /var/www/$HOST/
|
2021-02-05 02:11:19 +00:00
|
|
|
# Populate the DASHBOARD_LOCATION variable
|
|
|
|
DASHBOARD_LOCATION=$(<$HD/Deploy_Saleor/resources/saleor-dashboard/dashboard-location)
|
|
|
|
# Modify the new server block
|
2021-02-06 02:47:14 +00:00
|
|
|
sudo sed -i "s#{dl}#$DASHBOARD_LOCATION#" /etc/nginx/sites-available/saleor
|
2021-02-05 02:11:19 +00:00
|
|
|
wait
|
|
|
|
# Modify the new server block again
|
|
|
|
sudo sed -i "s|{hd}|$HD|g
|
2021-02-05 17:36:43 +00:00
|
|
|
s|{app_mount_uri}|$APP_MOUNT_URI|g
|
2021-02-06 04:47:52 +00:00
|
|
|
s|{host}|$HOST|g" /etc/nginx/sites-available/saleor
|
2021-02-05 02:11:19 +00:00
|
|
|
wait
|
|
|
|
echo "Enabling server block and Restarting nginx..."
|
2021-02-07 00:44:29 +00:00
|
|
|
if [ ! -f "/etc/nginx/sites-enabled/saleor" ]; then
|
|
|
|
sudo ln -s /etc/nginx/sites-available/saleor /etc/nginx/sites-enabled/
|
|
|
|
fi
|
2021-02-05 02:11:19 +00:00
|
|
|
fi
|
2021-02-10 04:27:45 +00:00
|
|
|
sudo systemctl restart nginx
|
2021-02-10 04:50:12 +00:00
|
|
|
#########################################################################################
|