Deploy to Droplet

Deploy to Droplet

by John Vincent

Posted on March 1, 2017

This is part of a series of discussions regarding Deploying to a Digital Ocean Droplet. For more details, please see Overview of website

Deploy to Droplet

Install HTML-Minifier

sudo npm install html-minifier -g

Before deployment

On Mac, remove quarantine from all files going to the website.

cd /Users/jv/Desktop/MyDevelopment

Look for files with

xattr -r -l  github/website/demosite | grep -i
xattr -r -l  github/website/omnifood | grep -i
xattr -r -l  github/website/internet-resources | grep -i

xattr -r -l  github/thinkful/rijksmuseum | grep -i
xattr -r -l  github/thinkful/peg-solitaire | grep -i
xattr -r -l  github/repo-images | grep -i

To remove quarantine:

xattr -r -d github/website/demosite
xattr -r -d github/website/omnifood
xattr -r -d github/website/internet-resources

xattr -r -d  github/thinkful/rijksmuseum | grep -i
xattr -r -d  github/website/peg-solitaire | grep -i
xattr -r -d  github/repo-images | grep -i

Execute Deploy Script on Production Server

From Mac



chmod 744 deploy-apps

Execute the deploy


Restart Ghost

pm2 restart all

Restart Nginx Server

sudo nginx -t
sudo systemctl restart nginx

Deployment Script

Create script

#  script to get, build and deploy apps to nginx and ghost
cd tmp
echo "Removing Logfile"
rm /home/jv/tmp/logfile.txt
echo "Removing clones directory"
rm -rf $CLONES_DIR
echo "Creating clones directory"
echo "Git clone desired repositories"
git clone $CLONES_DIR/demosite
git clone $CLONES_DIR/internet-resources
git clone $CLONES_DIR/rijksmuseum
git clone $CLONES_DIR/peg-solitaire
git clone $CLONES_DIR/omnifood
git clone $CLONES_DIR/repo-images
echo "Build Production Jekyll"
rm -rf $CLONES_DIR/demosite/destination
cd $CLONES_DIR/demosite
# minify index.html
cp destination/index.html destination/
html-minifier destination/ --remove-comments --output destination/index.html
# Delete files in nginx docroot
echo "Delete files in Nginx Docroot"
rm -rf $DOCROOT_DIR/*
# Copy files to nginx docroot
echo "Copy files to Nginx Docroot"
cp -r /home/jv/clones/demosite/destination/*  /var/www/
cp -r /home/jv/clones/internet-resources /var/www/
cp -r /home/jv/clones/rijksmuseum/collection  /var/www/
cp -r /home/jv/clones/peg-solitaire /var/www/
cp -r /home/jv/clones/omnifood/Omnifood-After-Section-7  /var/www/
cp -r /home/jv/clones/repo-images  /var/www/
# echo "Create $DOCROOT_DIR/.well-known directory for SSL certs creation process"
# mkdir $DOCROOT_DIR/.well-known
# set permissions
echo "Setting permissions"
sudo chown -R jv:jv /var/www/
find . -type d -print0 | xargs -0 chmod 0755 # For directories
find . -type f -print0 | xargs -0 chmod 0644 # For files
echo "Restarting Ghost"
pm2 restart all
echo "Restarting Nginx"
sudo nginx -t
sudo systemctl restart nginx
echo "Mongo Status"
sudo systemctl status mongodb
echo "Completed"

Copy Deploy Script to Production Server

Be careful before doing this as your production server version of the deploy script is going to be replaced.

cd tmp