GitLab Pages allows you to create and host GitLab project websites from a user account or group for free on GitLab.com or on your self-managed GitLab instance.

In this post, I will explain how the GitLab Pages daemon obtains a domain’s configuration using the GitLab API, specifically on GitLab.com.

How does GitLab Pages know where to find your website files?

GitLab Pages is moving to using object storage to store the contents of your web site. You can follow the development of this new feature here.

At the time of writing, GitLab Pages uses an NFS shared mount drive to store the contents of your website. You can define the value of this path by defining the [pages_path](https://docs.gitlab.com/ee/administration/pages/#change-storage-path) in your /etc/gitlab/gitlab.rb file.

When you deploy a website using the pages: keyword in your .gitlab-ci.yml file, a public path artifact must be defined, containing the files available for your website. This public artifact eventually makes its way into the NFS shared mount.

When you deploy a website to GitLab Pages a domain will be created based on the custom Pages domain you have configured. For GitLab.com, the pages domain is *.gitlab.io, if you create a project named myproject.gitlab.io and enable HTTPS, a wildcard SSL certificate will be used. You can also setup a custom domain for your project, for example myawesomedomain.com.

For every project (a.k.a. domain) that is served by the Pages daemon, there must exist a directory in the NFS shared mount that matches your domain name and holds its contents. For example, if we had a project named myproject.gitlab.io, the Pages daemon would look for your .html files under /path/to/shared/pages/myproject/myproject.gitlab.io/public directory. This is how GitLab Pages serves the content published by the pages: keyword in your CI configuration.

Before GitLab 12.10 was released on GitLab.com, the Pages daemon would rely on a file named config.json located in your project’s directory in the NFS shared mount, that is /path/to/shared/pages/myproject/myproject.gitlab.io/config.json. This file contains metadata related to your project and custom domain names you may have setup.

{
  "domains":[
    {
      "Domain":"myproject.gitlab.io"
    },
    {
      "Domain": "mycustomdomain.com",
      "Certificate": "--certificate contents--",
      "Key": "--key contents--"
    }
  ],
  "id":123,
  "access_control":true,
  "https_only":true
}

GitLab Pages has been a very popular addition to GitLab, and over time the number of hosted websites on GitLab.com has increased a lot. On start-up, the Pages daemon would traverse all directories in the NFS shared mount and load the configuration of all the deployed Pages projects into memory. At some point in time, the Pages daemon would take over 20 minutes to load per instance on GitLab.com!

#gitlab #gitlab api #gitlab pages #api

How GitLab Pages  Uses the GitLab API to Serve Content
4.30 GEEK