Skip to content

Use pages root directory from API

Janis Altherr requested to merge 1056-use-pages-root-directory-from-api into master

What does this MR do?

Resolves Use pages root directory from API (#1056 - closed)

This MR adds the ability to configure the root directory inside an artifact.

Why is this change being made?

The full context: &10126

TL;DR: Currently the static files that GitLab Pages exposes need to be an artifact that contains a folder named public. Since artifacts are a generic pipeline feature (not specific to pages) they will happily accept any path. But Pages itself is more strict and will only expose files if they're in a root folder named public. This has always caused a lot of confusion.

But rather than simply adding a pipeline validation, this MR is the final step in removing the requirement altogether (with gitlab!115340 (merged) being the first and gitlab!115720 (merged) the second).

How is it implemented?

https://gitlab.com/gitlab-org/gitlab/-/merge_requests/11572 introduced the root_directory property as part of a Pages deployment's lookup_path inside Gitlab's internal API response.

(The value is a single string. It is being defined as part of the pages job inside the CI/CD Config. It is subsequently stored as a property of the pages_deployment and exposed via the internal Pages API.)

This MR now changes Pages in the following ways:

  • If the API has a value set for lookup_path.root_directory, it will serve the files from a directory with that name inside the artifact zip.
  • If the value is not set (e.g. in case the GitLab API is not on a current version), it will fall back to the legacy behaviour and look for files to deliver inside a folder named public

Implementation Detail

  • In archive.go the hardcoded dirPrefix was removed. Rather than passing the dynamic value all the way down to the archive resolver, I believe the cleaner approach is to consider archive.go a low-level resolver that will from now on always resolve any file from the archive directly.
  • Instead, the logic has been moved to reader.go, the actual place where the project configuration and file system resolution meet. In there, the vfs.Root is now being wrapped by a new projectroot.Root which implements the vfs.Root interface, but will automatically prepend the rootDirectory to file requests inside a zip archive.

TODO

Closes #1056 (closed)

Edited by Janis Altherr

Merge request reports

Loading