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 johnvincent.io 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 com.apple.quarantine

xattr -r -l  github/website/demosite | grep -i com.apple.quarantine
xattr -r -l  github/website/omnifood | grep -i com.apple.quarantine
xattr -r -l  github/website/internet-resources | grep -i com.apple.quarantine

xattr -r -l  github/thinkful/rijksmuseum | grep -i com.apple.quarantine
xattr -r -l  github/thinkful/peg-solitaire | grep -i com.apple.quarantine
xattr -r -l  github/repo-images | grep -i com.apple.quarantine

To remove quarantine:

xattr -r -d com.apple.quarantine github/website/demosite
xattr -r -d com.apple.quarantine github/website/omnifood
xattr -r -d com.apple.quarantine github/website/internet-resources

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

Execute Deploy Script on Production Server

From Mac

ssh-to-website

Ensure

chmod 744 deploy-apps

Execute the deploy

./deploy-apps

Restart Ghost

pm2 restart all

Restart Nginx Server

sudo nginx -t
sudo systemctl restart nginx

Deployment Script

Create script

deploy-apps
#!/bin/sh
#
#  script to get, build and deploy apps to nginx and ghost
#
cd tmp
#
echo "Removing Logfile"
rm /home/jv/tmp/logfile.txt
#
CLONES_DIR="/home/jv/clones"
DOCROOT_DIR="/var/www/johnvincent.io/html"
#
echo "Removing clones directory"
rm -rf $CLONES_DIR
#
echo "Creating clones directory"
mkdir $CLONES_DIR
cd $CLONES_DIR
#
echo "Git clone desired repositories"
git clone https://github.com/johnvincentio/demosite $CLONES_DIR/demosite
git clone https://github.com/johnvincentio/internet-resources $CLONES_DIR/internet-resources
git clone https://github.com/johnvincentio/rijksmuseum $CLONES_DIR/rijksmuseum
git clone https://github.com/johnvincentio/peg-solitaire $CLONES_DIR/peg-solitaire
git clone https://github.com/johnvincentio/omnifood $CLONES_DIR/omnifood
git clone https://github.com/johnvincentio/repo-images $CLONES_DIR/repo-images
#
echo "Build Production Jekyll"
rm -rf $CLONES_DIR/demosite/destination
cd $CLONES_DIR/demosite
./build-prod
#
# minify index.html
#
cp destination/index.html destination/index.work
html-minifier destination/index.work --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/johnvincent.io/html
cp -r /home/jv/clones/internet-resources /var/www/johnvincent.io/html/internet-resources
cp -r /home/jv/clones/rijksmuseum/collection  /var/www/johnvincent.io/html/rijksmuseum
cp -r /home/jv/clones/peg-solitaire /var/www/johnvincent.io/html/peg-solitaire
cp -r /home/jv/clones/omnifood/Omnifood-After-Section-7  /var/www/johnvincent.io/html/omnifood
cp -r /home/jv/clones/repo-images  /var/www/johnvincent.io/html/images
#
# 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/johnvincent.io/html
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
cd tmp
copy-config-to-website