hugo/content/en/hosting-and-deployment/deployment-with-rsync.md
Bjørn Erik Pedersen 83bef6955e Squashed 'docs/' changes from 896bad9f4..e161ea09d
e161ea09d Add one more Chinese file to workaround reflect: Zero(nil)
b595b3a21 Add more Chinese translation
56e4e95d9 Use lang.Merge to "fill in the gaps" for untranslated pages
ef079406c Merge commit '650fac3a4e7d256f4505402ab44cfc3c804b8dea'
650fac3a4 Squashed 'themes/gohugoioTheme/' changes from a1768ebb..f31a3dc8
322eff899 Add Chinese language for menus
d90b886e0 Fix Markdown table syntax in previous commit
737f3dfca Update the leaf bundle vs branch bundle table
09fa1bc4e Clarify that `.Now` is obsolete
879ea3f6a Make release notes somewhat more consistent
0113e2051 Move 0.40.2-relnotes into content/en/news
77578f5bf Move content/ into new contentDir content/en/
4dcf7c709 Fix "reflect: Zero(nil)" error in showcase
63dd25505 Release 0.40.2
2076c0d56 releaser: Prepare repository for 0.41-DEV
070fe565e releaser: Add release notes to /docs for release of 0.40.2
4ce52e913 releaser: Bump versions for release of 0.40.2
41907c487 Fix typos in syntax-highlighting.md
91753ef3d Add missing backtick
b77274301 Remove duplicate release notes (0.27, 0.27.1, 0.35)
6e00da316 Remove obsolete content/release-notes/ directory
00a6d8c02 Change en dash back to `--` in 0.38.2-relnotes
51b32dc00 Update archetypes.md
d0e5c2307 Release 0.40.1
4538a6d5b releaser: Prepare repository for 0.41-DEV
91b391d70 releaser: Add release notes to /docs for release of 0.40.1
e0979d143 releaser: Bump versions for release of 0.40.1
7983967c2 Clean images
fe3fdd77d Polish showcase for Flesland Flis
e6dde3989 Showcase - Flesland Flis AS by Absoluttweb
73aa62290 Revive @spf13's special Hugo font
add67b335 Release Hugo 0.40
c0a26e5a6 Merge branch 'temp40'
beeabaaae releaser: Prepare repository for 0.41-DEV
e67d5e985 releaser: Add release notes to /docs for release of 0.40
6cdd95273 releaser: Bump versions for release of 0.40
bee21fb9b Revive the other Hugo logos too
4f45e8fe1 Fix the link type attribute for RSS in examples
8c67dc89a Fix example in delimit doc
e7f6c00d5 Revive the logo used on the forum
82b0cd26e Merge commit 'a215abf70e018f4bf40d6c09d8bd148d8684b33d'
119c8ca58 Merge commit 'd2ec1a06df8ab6b17ad05cb008d5701b40327d47'
db4683bd2 Improve .Get docs
05260b886 .Get function: fix syntax signature

git-subtree-dir: docs
git-subtree-split: e161ea09d33e3199f4998e4d2e9068d5a850f042
2018-05-04 09:44:21 +02:00

3.4 KiB

title linktitle description date publishdate lastmod categories keywords authors menu weight sections_weight draft aliases toc notesforauthors
Deployment with Rsync Deployment with Rsync If you have access to your web host with SSH, you can use a simple rsync one-liner to incrementally deploy your entire Hugo website. 2017-02-01 2017-02-01 2017-02-01
hosting and deployment
rsync
deployment
Adrien Poupin
docs
parent weight
hosting-and-deployment 70
70 70 false
/tutorials/deployment-with-rsync/
true

Assumptions

  • Access to your web host with SSH
  • A functional static website built with Hugo

The spoiler is that you can deploy your entire website with a command that looks like the following:

hugo && rsync -avz --delete public/ www-data@ftp.topologix.fr:~/www/

As you will see, we put it in a shell script file, which makes building and deployment as easy as executing ./deploy.

Install SSH Key

If it is not done yet, we will make an automated way to SSH to your server. If you have already installed an SSH key, switch to the next section.

First, install the ssh client. On Debian/Ubuntu/derivates, use the following command:

{{< code file="install-openssh.sh" >}} sudo apt-get install openssh-client {{< /code >}}

Then generate your ssh key by entering the following commands:

~$ cd && mkdir .ssh & cd .ssh
~/.ssh/$ ssh-keygen -t rsa -q -C "For SSH" -f rsa_id
~/.ssh/$ cat >> config <<EOF
Host HOST
     Hostname HOST
     Port 22
     User USER
     IdentityFile ~/.ssh/rsa_id
EOF

Don't forget to replace the HOST and USER values with your own ones. Then copy your ssh public key to the remote server:

~/.ssh/$ ssh-copy-id -i rsa_id.pub USER@HOST.com

Now you can easily connect to the remote server:

~$ ssh user@host
Enter passphrase for key '/home/mylogin/.ssh/rsa_id':

And you've done it!

Shell Script

We will put the first command in a script at the root of your Hugo tree:

~/websites/topologix.fr$ editor deploy

Here you put the following content. Replace the USER, HOST, and DIR values with your own:

#!/bin/sh
USER=my-user
HOST=my-server.com
DIR=my/directory/to/topologix.fr/   # might sometimes be empty!

hugo && rsync -avz --delete public/ ${USER}@${HOST}:~/${DIR}

exit 0

Note that DIR is the relative path from the remote user's home. If you have to specify a full path (for instance /var/www/mysite/) you must change ~/${DIR} to ${DIR} inside the command line. For most cases you should not have to.

Save and close, and make the deploy file executable:

~/websites/topologix.fr$ chmod +x deploy

Now you only have to enter the following command to deploy and update your website:

~/websites/topologix.fr$ ./deploy
Started building sites ...
Built site for language en:
0 draft content
0 future content
0 expired content
5 pages created
0 non-page files copied
0 paginator pages created
0 tags created
0 categories created
total in 56 ms
sending incremental file list
404.html
index.html
index.xml
sitemap.xml
cours-versailles/index.html
exercices/index.html
exercices/index.xml
exercices/barycentre-et-carres-des-distances/index.html
post/
post/index.html
sujets/index.html
sujets/index.xml
sujets/2016-09_supelec-jp/index.html
tarifs-contact/index.html

sent 9,550 bytes  received 1,708 bytes  7,505.33 bytes/sec
total size is 966,557  speedup is 85.86