Deploy Jekyll site
Sat, Aug 27, 2016 · 3 minute readwebhow to
Assuming that you have
- SSH installed
Password-less connection setup between your local machine and the remote server.
Setup is as simple as:$ ssh-keygen -f ~/.ssh/id_rsa -q -P "" # Create RSA key without passphase $ cat ~/.ssh/id_rsa.pub # copy contents of ~/.ssh/id_rsa.pub # append to ~/.ssh/authorized_keys on remote server # test the connection, date should be displayed, should not be promoted for password $ ssh user@remote date
Jekyll _config.yml containing this section (change source and destination as appropriate)
Note: Our setup assumes that the local and remote servers have very similar directory structures.destination: /var/www/vhosts/bespoke-it.solutions ... # Deploy settings deploy: command: rsync # protect the .well-known directory from being deleted on remote server settings: -avvz --progress --delete --exclude '.well-known' # source folder, probably same as build destination source: /var/www/vhosts/bespoke-it.solutions # destination SSH user@server ssh: user@vps.host.com # rsync destination folder on remote server destination: /home/user/sites/bespoke-it.solutions
A rakefile containing a deploy task, e.g.:
# rake deploy desc "Deploy the site (remote server or a local git repo)" task :deploy do command = CONFIG["deploy"]["command"] source = CONFIG["deploy"]["source"] ssh = CONFIG["deploy"]["ssh"] destination = CONFIG["deploy"]["destination"] # remote source destination are reverse of local remote_source = destination remote_destination = source settings = CONFIG["deploy"]["settings"] if command.nil? or command.empty? raise "Please choose a file deploy command." elsif command == "robocopy" Rake::Task[:build].invoke execute("robocopy #{source} #{destination} #{settings}") puts "Your site was transfered." elsif command == "rsync" Rake::Task[:build].invoke puts "Source: #{source}" puts "SSH: #{ssh}" puts "Dest : #{destination}" puts "Settings: #{settings}" puts "Local rsync ..." execute("rsync #{settings} #{source}/ #{ssh}:#{destination}") # Source: /var/www/vhosts/county.show # Dest : user@vps.host.com:/home/user/sites # Settings: -avvz --progress --delete puts "Remote rsync ..." # source and destination are reversed on remote server # ssh user@remote rsync -avz /home/user/sites/bespoke-it.solutions /var/www/vhosts execute("ssh #{ssh} rsync #{settings} #{remote_source}/ #{remote_destination}") puts "Your site was deployed." else raise "#{command} isn't a valid file transfer command." end end
Then the site can be deployed as follows:
$ rake deploy
Configuration file: /home/alan/sites/bespoke-it.solutions/_config.yml
Source: /home/alan/sites/bespoke-it.solutions
Destination: /var/www/vhosts/bespoke-it.solutions
Incremental build: disabled. Enable with --incremental
Generating...
done in 0.086 seconds.
Auto-regeneration: disabled. Use --watch to enable.
Source: /var/www/vhosts/bespoke-it.solutions
SSH: user@vps.host.com
Dest : /home/user/sites/bespoke-it.solutions
Settings: -avvz --progress --delete --exclude '.well-known'
Local rsync ...
opening connection using: ssh -l user vps.host.com rsync --server -vvlogDtprze.iLsfx --delete . /home/user/sites/bespoke-it.solutions (10 args)
sending incremental file list
delta-transmission enabled
robots.txt is uptodate
./
feed.xml
455 100% 0.00kB/s 0:00:00 (xfr#1, to-chk=4/6)
index.html
3,252 100% 3.10MB/s 0:00:00 (xfr#2, to-chk=3/6)
css/main.css
8,797 100% 8.39MB/s 0:00:00 (xfr#3, to-chk=0/6)
total: matches=18 hash_hits=18 false_alarms=0 data=455
sent 605 bytes received 255 bytes 573.33 bytes/sec
total size is 12,530 speedup is 14.57
Remote rsync ...
sending incremental file list
delta-transmission disabled for local transfer or --whole-file
[generator] protecting directory .well-known because of pattern .well-known
deleting screen.png
deleting README.md
./
feed.xml
455 100% 0.00kB/s 0:00:00 (xfr#1, to-chk=4/6)
index.html
3,252 100% 3.10MB/s 0:00:00 (xfr#2, to-chk=3/6)
robots.txt
26 100% 25.39kB/s 0:00:00 (xfr#3, to-chk=2/6)
css/
css/main.css
8,797 100% 8.39MB/s 0:00:00 (xfr#4, to-chk=0/6)
total: matches=0 hash_hits=0 false_alarms=0 data=12530
sent 3,849 bytes received 273 bytes 8,244.00 bytes/sec
total size is 12,530 speedup is 3.04
Your site was deployed.