Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
blog
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nimrod
blog
Commits
a384af02
Commit
a384af02
authored
4 years ago
by
nimrod
Browse files
Options
Downloads
Patches
Plain Diff
Post on Hugo and gitreceive.
parent
69755fc0
No related branches found
No related tags found
Loading
Pipeline
#1419
passed
4 years ago
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
content/hugo-gitreceive.rst
+104
-0
104 additions, 0 deletions
content/hugo-gitreceive.rst
with
104 additions
and
0 deletions
content/hugo-gitreceive.rst
0 → 100644
+
104
−
0
View file @
a384af02
Deploying a Hugo blog with gitreceive
=====================================
:date: 2021-05-10
:summary: How to deploy a blog built with Hugo using gitreceive
This blog post is actually one I meant to write a long time ago, but always put
off. I'm going to describe how to use gitreceive to deploy a blog that's built
using Hugo. I find the Heroku-style of deploying using ``git push`` nice in
some cases and this is a nice example of using gitreceive as any. Obviously
other static blogging tools can be used.
First, setup the server
-----------------------
We need to create a user on the server, grant it access to deploy the blog and
add the SSH public keys.
.. code:: shell
sudo useradd -m hugo
sudo install -d -m 755 -o hugo -g hugo /var/www/html/blog
sudo install -d -m 700 -o hugo -g hugo ~hugo/.ssh
sudo install -m 600 -o hugo -g hugo /dev/null ~hugo/.ssh/authorized_keys
echo 'command="GITUSER=hugo gitreceive run %s %s" ssh-ed25519 AAAAC3....' | sudo tee ~hugo/.ssh/authorized_keys
Now we'll install git, gitreceive and Hugo.
.. code:: shell
sudo apt-get install -y git
cd /usr/local/bin
curl -L https://github.com/gohugoio/hugo/releases/download/v0.83.1/hugo_0.83.1_Linux-64bit.tar.gz | sudo tar -xz
sudo curl -L https://raw.github.com/progrium/gitreceive/master/gitreceive -O gitreceive
sudo chmod +x gitreceive
Create the receiver script with the following content at ``/home/hugo/receiver``
and mark it as executable:
.. code:: shell
#!/bin/sh
set -eu
repo="$1"
mkdir -p "/var/tmp/gitreceive/$repo"
echo '----> Unpacking'
tar -x
echo '----> Building blog'
hugo --cleanDestinationDir
echo '----> Deploying blog'
rm -rf /var/www/html/blog/*
cp -r public/* /var/www/html/blog/
echo '----> Done'
Second, the client side
-----------------------
Actually, this is quite simple, just adding a git remote.
.. code:: shell
git remote add deploy hugo@example.com:blog
And now let's give it a test.
.. code:: shell
$ git push deploy
Counting objects: 39, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (31/31), done.
Writing objects: 100% (39/39), 6.55 KiB | 2.18 MiB/s, done.
Total 39 (delta 9), reused 0 (delta 0)
----> Unpacking
----> Building blog
Start building sites …
| EN
-------------------+-----
Pages | 3
Paginator pages | 0
Non-page files | 0
Static files | 1
Processed images | 0
Aliases | 0
Sitemaps | 1
Cleaned | 0
Total in 10 ms
----> Deploying blog
----> Done
To blog:blog
* [new branch] master -> master
That's it, the blog is deployed. Obviously having the output from the script is
useful. We can change the ``receiver`` script to do a lot of other things.
Running ``docker-compose build && docker-compose pull && docker-compose up -d``
can produce a simple and straightforward dev environment. We can make it more
general by running a script inside the repo and build a makeshift CI tool.
Lastly, I have an Ansible role to do all of the server configuration for you in
`my GitLab instance <https://git.shore.co.il/ansible/gitreceive>`_.
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment