hugo/content/en/hosting-and-deployment/hosting-on-gitlab.md
Bjørn Erik Pedersen 7c62d6ef16 Squashed 'docs/' changes from c43daf45f..a7e1e9be8
a7e1e9be8 Clarify front matter date fields
69df4fc22 Clarify how to determine if .Inner is populated
9046bf424 Document strings.ContainsNonSpace
8dbe5df90 Fix indentation and broken image
48ad4124e Typo: functions/after.md
d4c01b57b Link to detailed descriptions of canonfiyURLs and relativeURLs
4d9597302 Explain behaviour when appending to a slice containing other slices
69e24e44e Standardize right arrow usage
01b378726 Remove references to Google's Universal Analytics and the async template
d415bae24 Use shared file to describe regex syntax
e75dee6b8 snap: How to enable or revoke access to SSH keys
feed2d1c0 Remove hasPrefix and hasSuffix in favor of namespaced versions
3c6d2cfe5 security: Use default execution settings
461b5fcaf netlify: Hugo 0.116.1
95fac27a5 configuration: correct cacheDir description
cd9f1f929 configuration: Fix broken link
605394de4 netlify: Upgrade to Hugo 0.116.0
baf2a0f7b Merge branch 'tempv0.116.0'
ee51a9323 Update requirements for building from source
40189956d Editor tools: Remove duplicate sentence
fb0ff2621 docs: Regenerate CLI docs
e8a5665c4 Update where.md
7bc5cf15d Update hosting instructions
018a04314 docs: Update where
d33ae91cf docs: Update where function operators
9a108a664 docs: Rework the cacheDir documentation

git-subtree-dir: docs
git-subtree-split: a7e1e9be851b95e636ab5360e5151156b4f89044
2023-08-07 10:35:12 +02:00

101 lines
3.7 KiB
Markdown

---
title: Host on GitLab Pages
description: GitLab makes it easy to build, deploy, and host your Hugo website via their free GitLab Pages service, which provides native support for Hugo.
categories: [hosting and deployment]
keywords: [hosting,deployment,git,gitlab]
menu:
docs:
parent: hosting-and-deployment
toc: true
aliases: [/tutorials/hosting-on-gitlab/]
---
## Assumptions
* Working familiarity with Git for version control
* Completion of the Hugo [Quick Start]
* A [GitLab account](https://gitlab.com/users/sign_in)
* A Hugo website on your local machine that you are ready to publish
## BaseURL
The `baseURL` in your [site configuration](/getting-started/configuration/) must reflect the full URL of your GitLab pages repository if you are using the default GitLab Pages URL (e.g., `https://<YourUsername>.gitlab.io/<your-hugo-site>/`) and not a custom domain.
## Configure GitLab CI/CD
Define your [CI/CD](https://docs.gitlab.com/ee/ci/quick_start/) jobs by creating a `.gitlab-ci.yml` file in the root of your project.
{{< code file=".gitlab-ci.yml" >}}
variables:
DART_SASS_VERSION: 1.64.1
HUGO_VERSION: 0.115.4
NODE_VERSION: 20.x
GIT_DEPTH: 0
GIT_STRATEGY: clone
GIT_SUBMODULE_STRATEGY: recursive
TZ: America/Los_Angeles
image:
name: golang:1.20.6-bookworm
pages:
script:
# Install brotli
- apt-get update
- apt-get install -y brotli
# Install Dart Sass
- curl -LJO https://github.com/sass/dart-sass/releases/download/${DART_SASS_VERSION}/dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz
- tar -xf dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz
- cp -r dart-sass/ /usr/local/bin
- rm -rf dart-sass*
- export PATH=/usr/local/bin/dart-sass:$PATH
# Install Hugo
- curl -LJO https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb
- apt-get install -y ./hugo_extended_${HUGO_VERSION}_linux-amd64.deb
- rm hugo_extended_${HUGO_VERSION}_linux-amd64.deb
# Install Node.js
- curl -fsSL https://deb.nodesource.com/setup_${NODE_VERSION} | bash -
- apt-get install -y nodejs
# Install Node.js dependencies
- "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true"
# Build
- hugo --gc --minify
# Compress
- find public -type f -regex '.*\.\(css\|html\|js\|txt\|xml\)$' -exec gzip -f -k {} \;
- find public -type f -regex '.*\.\(css\|html\|js\|txt\|xml\)$' -exec brotli -f -k {} \;
artifacts:
paths:
- public
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
{{% /code %}}
## Push your Hugo website to GitLab
Next, create a new repository on GitLab. It is *not* necessary to make the repository public. In addition, you might want to add `/public` to your .gitignore file, as there is no need to push compiled assets to GitLab or keep your output website in version control.
```bash
# initialize new git repository
git init
# add /public directory to our .gitignore file
echo "/public" >> .gitignore
# commit and push code to master branch
git add .
git commit -m "Initial commit"
git remote add origin https://gitlab.com/YourUsername/your-hugo-site.git
git push -u origin master
```
## Wait for your page to build
That's it! You can now follow the CI agent building your page at `https://gitlab.com/<YourUsername>/<your-hugo-site>/pipelines`.
After the build has passed, your new website is available at `https://<YourUsername>.gitlab.io/<your-hugo-site>/`.
## Next steps
GitLab supports using custom CNAME's and TLS certificates. For more details on GitLab Pages, see the [GitLab Pages setup documentation](https://about.gitlab.com/2016/04/07/gitlab-pages-setup/).
[Quick Start]: /getting-started/quick-start/