POST
GitPages Hugo Investigation
Author: Alan Richardson
As an experiment I decided to move my website and apps to github, with a view to hosting them completely on github pages.
But, after getting the basic functionality working I read in the terms and conditions that GitPages should not be used to host commercial sites.
So I will create an ‘organisation’ site on GitPages that is a ‘summary’ site describing the open source projects hosted on Github and I will use the lessons learned here to do that.
And I am experimenting with automated ftp from a private repo, so I might still be able to gain value from hosting the generated content on GitHub, even if I don’t serve it from GitHub.
HuGo
I primarily use hugo as my website generator and the instructions for configuring Hugo with github pages are here:
It is very important, and I didn’t understand this at first is that we create two repositories for our main site.
- One for the code of the site
- One for the public html of the site
The public html site repo is always username.github.io
e.g. talotics.github.io
The code for the site can be anything e.g. taloticswebsite
Summary of Steps
https://gohugo.io/hosting-and-deployment/hosting-on-github/#step-by-step-instructions
- create username.github.io on github
- create a repo for the website hugo code and config e.g.
website
- clone the
website
repo - create and build the hugo project
- delete the
public
folder - commit the hugo project repo
- add the
username.github.io
repo as a submmodule
git submodule add -b master https://github.com/<USERNAME>/<USERNAME>.github.io.git public
i.e.
git submodule add -b master https://github.com/talotics/talotics.github.io.git public
GitHub Desktop
I found that I had to manually add the submodule folder as a repo in github desktop.
And make sure that I ignore the public
folder in my main project.
I primarily try to work with the desktop tool.
But I managed to confuse git slightly by adding files to the public repo before fetching.
But a git rebase
from the command line in the public folder fixed everything.
The benefit is that all the content here is generated so a git rebase
doesn’t really matter because I can just regenerate.
Users
Since I already have a main github account.
I created the Talotics user with my Talotics.com email address.
Then added my normal github account as a collaborator to the talotics github projects.
Backup
At the moment, this is a ‘backup site’ because…
“GitHub Pages is not intended for or allowed to be used as a free web hosting service to run your online business,…”
https://help.github.com/en/github/working-with-github-pages/about-github-pages
Pros
If this works, and if it is reliable then it would potentially cut down on:
- hosting costs
- the need to manage SSL certificates (because this would be applied from github)
Cons
You need a root level site then you need to have an organisation repo e.g. username.github.io
rather than a project repo, so you would need to create new organisations for every site, which is unsustainable.
You lose access to the ability to use .htaccess:
i.e.
- redirect from .htaccess files
- configure site access via .htaccess.
The major downside is that you can’t use this as an http server host for commercial organisations. And there doesn’t seem to be a pricing level that allows this.
Actions
GitHub comes with free actions.
So I will experiment with an FTP action from a private repo, to see if I can automatically push changes live to my web host when I push the generated site changes to GitHub.
- experiment
https://github.com/SamKirkland/FTP-Deploy-Action
I created a .github/workflows/main.yml
file:
on: push
name: Publish Website
jobs:
FTP-Deploy-Action:
name: FTP-Deploy-Action
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.1.0
with:
fetch-depth: 2
- name: FTP-Deploy-Action
uses: SamKirkland/FTP-Deploy-Action@3.1.1
with:
ftp-server: ${{ secrets.FTP_SERVER }}
ftp-username: ${{ secrets.FTP_USERNAME }}
ftp-password: ${{ secrets.FTP_PASSWORD }}
And setup the secrets through the Github console to see what happens.
Successful Experiment
This worked really well.
I generate the site and test it locally.
Commit and push the site source.
Then I can generate the live version.
Commit and push that from the github explorer, and it automatically deploys via FTP to the hosting site.
This seemed faster than doing it locally via FTP. And if anything does go wrong, then I can always do a patch via an FTP locally.
I will certainly be investigating more Actions on Github to see what else I can automate.