Surprisingly simple
GitLab Pages
Nothing groundbreaking here, but something new to me at least. For many years, developers have been able to host static sites on either Github or GitLab, but I never took advantage until today. I was asked to setup an internal site for the engineering organization and investigated a number of options. Although it’s unlikely that we’ll move ahead with the GitLab option for a variety of reasons, I figured I would summarize my experience for future reference.
Setup
If you’re hosting the repo on GitLab, you need add a
.gitlab-ci.yml
file to the project. A simple example:
image: <whatever you need>
pages:
script:
- # Command to build your static files (e.g. hugo)
artifacts:
paths:
- # Whichever folder contains the generated files (e.g. public)
only:
- master
If you don’t know the first thing about GitLab and its features, I highly recommend you ingest the docs at your leisure. It’s actually a very pleasant platform.
As you can see, you can specify a Docker image to be used
in your CI/CD pipeline. In this case, the pipeline will
only be triggered on changes made to the master
branch.
This is likely sufficient if you’re working as a solo dev,
but if your org requires more control than that, it’s
entirely possible.
On the framework-side of things, you’ll obviously need to ensure that generated pages and links refer to the correct GitLab domain. Should you forget to make those changes, you’ll likely experience 404 errors when the pages try to load static assets. Don’t ask me why I know that.
Result
Assuming you followed those steps, your GitLab Page will
be available at https://<GitLab account>.gitlab.io/<repo name>
.
By default, the website will be private and restrict access
to repo members. If you want to open it up to the internet,
you need to adjust the privacy settings.
Final Thoughts
Using GitLab Pages, you can get your static site up and running literally in a matter of minutes. Out of the box, you’ll get an unbranded domain and URL, so if you want it branded and hosted differently, you’ll have to spend a bit more time on it.
Overall, I’m pleasantly surprised by the simplicity and will continue to explore GitLab’s offerings. Cheers!