Document how to vendor Project Templates
In https://gitlab.com/gitlab-org/gitlab-ce/issues/36762 we updated Project Templates. It was also a good spot to solve some problem that affected the previous versions:
- the full history is cloned when you use a template to start a new project, this is unneeded and misleading for users
- the old commits are "real", and people wondered why someone pushed code on their (private!) projects
The solution is to improve the vendoring process to flatten the repo.
Example (for Spring):
git clone https://gitlab.com/gitlab-org/project-templates/spring
cd spring
rm -rf .git
git init
git add -A .
git commit --author "GitLab <root@localhost>" -m "Spring template"
git bundle create project.bundle --all
At this point, vendor/project_templates/spring.tar.gz
must be updated with the new project.bundle
file.
Better approach?
@leipert has also offered an expanded one that helps ensure the image is as small as possible. You may need to sudo ln -s /bin/tar /bin/gtar
depending on your OS. This completely replaces the option above.
To use this script, first export your project and rename the .tar.gz file to the final name. Place it in the local directory, and the script will expand it, grab the repo, clean everything up, and then replace the .tar.gz with a new combined and smaller one.
#!/bin/bash
function bundleRepo {
gtar --list --file="$2.tar.gz"
rm -rf tar-base project
mkdir -p "./tar-base"
tar xf "$2.tar.gz" -C "./tar-base"
git clone "$1" project
cd project
rm -rf .git
git init
git add -A .
git commit --author "GitLab <root@localhost>" -m "$3"
git bundle create project.bundle --all
mv -f project.bundle ../tar-base/
cd ../tar-base
rm -rf ./uploads ./lfs-objects
cat project.json | jq '.project_members = [] |.issues = [] | .releases = [] | .merge_requests = [] | .ci_pipelines =
[] | .pipeline_schedules = [] | .services = [] | .pipelines = [] | .protected_branches = [] | .labels = [] | del(.ci_cd
_settings)' -c > tmp.json
mv -f tmp.json project.json
ls -alth
tar cvfz "$2.tar.gz" --exclude="$2.tar.gz" ./
cd ..
rm -rf "$2.tar.gz"
mv tar-base/*.gz .
gtar --list --file="$2.tar.gz"
}
bundleRepo https://gitlab.com/gitlab-org/project-templates/$1 $1 "Initial template creation"
The basic workflow for creating a vendor template is:
- create working template like https://gitlab.com/gitlab-org/project-templates/dotnetcore, export
- add boilerplate to
lib/gitlab/project_template.rb
,spec/lib/gitlab/project_template.rb
, andapp/assets/javascripts/projects/project_new.js
. See an MR like https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/25486 for an example. - add exported project to
/vendor/project_templates
after running cleanup (see this issue above) - run
bin/rake gettext:regenerate
ingitlab-ce
project and commit new .pot file - add changelog (something like
bin/changelog -m 25486 "Add Project template for .NET"
) - add icon to https://gitlab.com/gitlab-org/gitlab-svgs (illustrations/logos)
- run
yarn run svgs
ongitlab-svgs
project and commit result - forward changes in svgs project to master
- rebase master to pick up new svgs
- test everything is working
What would really be ideal is some automated process that does this whenever the project templates are updated.