To preface this post, I am very angry. And yes, I’m sure it’s my fault, but please let me explain my pain. I am stuck in pre-production hell and I carved some time today to finally post my website, but I simply lack the skill. Despite a background in computer science, I can’t cope. And to be fair, at uni we didn’t use git (or any version control system), nor did we work on hosted apps.
I thought I can use Hugo to build my website and keep it on GitLab, using GitLab Pages to host the website. For someone who is just trying to use git for one-man-show, it’s painful enough to just push the repo, but I did it. But GitLab, despite having a template for Hugo websites, does not build the website. It does something, the CI/CD pipeline is set up, but I know it can’t work, as it doesn’t create Public folder. As I’m just trying to have a website, I am enraged how difficult it is to set this up. I am reaching out here to see whether there is an easier service to use. In my rage I thought, as Hugo is a static site generator, I can just use old-school FTP web hosting (I was doing that in the past, is this much harder in 2024 as well? → The Hugo docs look quite complicated…).
What doesn’t help is that on top of regular IT evolution there is “inclusive language”, so a lot of guides are confusing to follow, because there is no master branch anymore… That’s one of the reasons I am asking whether there is a more recent guide to host. For GitLab specifically, it seems to be under heavy development → a lot of the things moved around, so again, it is difficult to follow any guides. And the template does NOT work out-of-the-box.
Is GitHub any better? Or Bitbucket? I have the website running on localhost just fine. What is the easiest way to host it (and preferably free)?
I host a large number of Hugo sites with GitHub pages. I wrote a bit about it on my blog: Automatically deploy Hugo site to GitHub pages with actions – xdeb.org
When you run the hugo
command locally a public
directory is generated. The files inside that directory is your complete site.
Uploading that to a web server the old fashion way works well.
I do that for some private sites that I host on my own servers. To make publishing quicker I use this one liner.
hugo --cleanDestinationDir && rsync -e 'ssh -ax' --archive --delete --verbose --compress --human-readable public/ host.example.org:/path/to/site
This first build the site with hugo and then uploads it with rsync over ssh.
See Hosting and deployment | Hugo. Specifically Host on GitLab Pages | Hugo (I personally removed the Dart Sass part since I don’t use SASS).
Came here to say: I am using GitHub and recommend it. To my understanding, you get a free host per account. Perfect for portfolios or personal blogs.
Also yea, I do think source control (even with a nice UI like GitHub) has a pretty steep learning curve. Unfortunately you’ll make plenty of mistakes, lose data and probably annoy others when you first start using it ahahah, but it all builds up your experience. Just like most things in ComSci.
To use git efficiently, you have to have a decent understanding of git. Following a guide using git without any understanding is difficult, since everyone would have a little differences in the configuration of the repository – you need to adapt any command or configurations accordingly. For this matter, I would recommend reading at least the first 3 chapters of Pro Git in the long term. It would take you one day upfront, but your productivity would boost significantly in the future.
To use a git-free platform, consider Netlify. You can simply drag and drop your locally built site and Netlify will deploy it. While deploying this way for now (which is manual and error-prune), you can take the time to learn git properly and use any of the platforms in the Hugo tutorial with no issue.
I appreaciate all your answers. For some reason, I didn’t look at the official docs how to use HUGO with GitLab. The script is different to the one provided in the template. But when I used the script from official docs, I ended up with the same result. The Public directory was not generated and the website doesn’t exist. Can the Public directory even be created, if it’s ignored in .gitignore?
Anyway, I think I found an output to the script and it seems like it does create the pages, it’s just that the service GitLab Pages doesn’t work. Any idea what I might be doing wrong?
I have used our GitLab Pages workflow file example on several sites and it works flawlessly.
The Public directory was not generated
I don’t know what that means. The CI/CD process doesn’t add a public directory to your repository. It builds the site and serves your files.
Okay, I had multiple problems and I’m not sure which one was the one that made me enraged. But I finally have the website up and running. Thanks to everyone, who responded to my post here. Few issues I remember:
- When you push the script in .gitlab-ci.yml, you have to also make sure GitLab knows you want to use it: Namespace/repo/Settings/“CI/CD”/General pipelines (expand)/CI/CD configuration file - “.gitlab-ci.yml”
- I used a theme, that was originally hosted on GitHub. The final reason I fixed was that I copied the Theme folder into my repo, but it was git initialized, so it didn’t get pushed to the repo. The solution was to delete .git folder (deinitialize git in the Theme folder). Yes, I had to get a crash course in git, just like @xuhdev suggested. Thank you again.
- Finally, I was not able to set a custom domain. As I was trying to make things work, I repeatedly deletd the repo and recreated it. At some stage I thought setting up the custom domain will make things easier. It didn’t and I didn’t read the docs properly, so I didn’t know you have to make it work first on the GitLab domain regardless. But it didn’t help me, and when I made everything work in a new repo, the place where you’d set up a custom domain said “Domain has already been taken”. I was not able to resolve it and free users don’t get any support. I found two people with similar problem: Unable to add custom domains to new repository after deleting previous one - #2 by BlueSoul - GitLab CI/CD - GitLab Forum I don’t know how to fix it.
- With git working as expected, I used Cloudflare Pages, that worked like a charm.
Thanks again to everybody responding, I appreciate all of you.
Guess it’s not enough to remove the pages custom domain.
When creating it you had to configure your hosting webserver, too. Ther is some handshake between gutlab and webserver.
New repo/ new gitlab pages. New handshake
You will have to clean up your webservers config, too