Use pages root directory from API
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 hardcodeddirPrefix
was removed. Rather than passing the dynamic value all the way down to the archive resolver, I believe the cleaner approach is to considerarchive.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, thevfs.Root
is now being wrapped by a newprojectroot.Root
which implements thevfs.Root
interface, but will automatically prepend the rootDirectory to file requests inside a zip archive.
TODO
-
Feature flag -
Added feature flag: -
This feature does not require a feature flag
-
-
I added the Changelog
trailer to the commits that need to be included in the changelog (e.g.Changelog: added
) -
I added unit tests or they are not required -
I added acceptance tests or they are not required -
I added documentation (or it's not required) -
I followed code review guidelines -
I followed Go Style guidelines
Closes #1056 (closed)