Copied to Clipboard
((orange PiratePunkAI fox reading a book in a tree)), (piles of books), <lora:PiratePunkAIV4-000004:1>, <lora:blindbox_v1_mix:1>, caribbean sea background
Integrated features
The above code has below features:
-
main content is exposed on $CI_PAGES_URL and the path is configurable with $CURRENT_CONTENT_PATH
- Per-branch preview content is exposed on
$CI_PAGES_URL/preview, with a homepage to easily navigate to branches content
- Path to root preview folder is configurable with
$EPHEMERAL_BRANCHES_PATH variable to hide preview content by obfuscation
- Generated pages are associated with environments to take advantage of auto-cleaning on branch deletion
- To avoid disturbing already existing environments, pages environment are placed under a
pages folder
- If
main content has not been generated in current cache, or if the cache has been deleted, an error is triggered, to avoid accidental deletion
- Deletion job can be triggered manually with any cache path as input, to clean outdated data
- Code can safely be added to an existing project pipeline without causing trouble with already existing jobs
- The
workflow:rules can be deleted if you already have your own, or updated to match your flow
- The job must be named
pages and the artifact must be a public folder to be deployed to GitLab Pages (or you can use the pages:publish keyword)
Remove obsolete folders after concurrency problems
If you experience concurrency problems leading to obsolete folders from deleted branches, you have multiple choices:
- Manually launch
pages-clean-preview with a folder name
- Manually clear the GitLab cache, regenerate content for default branch, and let other branches be updated on their future pipelines
- Use the resource_group keyword
- This may slow down your pipelines, waiting to acquire the lock
pages:
[...]
resource_group: avoid-cache-racing-conditions
pages-clean-preview:
[...]
resource_group: avoid-cache-racing-conditions
-
Delete obsolete folders using git branch at the end of pages jobs:
variables:
GIT_DEPTH: 0 # all branches are fetched (and known)
script:
[...]
- apk add git
- git branch -r
- cd $EPHEMERAL_BRANCHES_PATH
- |
for folder in *; do
exists=$(git rev-parse -q --verify "origin/$folder") || true
if [ -z "$exists" ]; then
rm -rf $folder
echo "removed folder $folder, the branch does not exist anymore"
fi
done
[...]
Wrapping up
Given the piece of yaml provided, using it in your pipeline, you should be able to share your GitLab Pages on a per-branch basis, on the path you want, while serving the stable content from the root context.
For any question or remark, please use below comment section π€.
If you need information to choose better runner architecture, you can read GitLab Runners topologies: pros and cons.
((orange PiratePunkAI fox reading a book in a tree)), (piles of books), <lora:PiratePunkAIV4-000004:1>, <lora:blindbox_v1_mix:1>, caribbean sea background
Illustrations generated locally by Automatic1111 using RevAnimated model with PiratePunkAI and Blindbox LoRA
Further reading
This article was enhanced with the assistance of an AI language model to ensure clarity and accuracy in the content, as English is not my native language.