Skip to content
GitLab
Next
    • GitLab: the DevOps platform
    • Explore GitLab
    • Install GitLab
    • How GitLab compares
    • Get started
    • GitLab docs
    • GitLab Learn
  • Pricing
  • Talk to an expert
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
    Projects Groups Topics Snippets
  • Register
  • Sign in
  • GitLab FOSS GitLab FOSS
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
    • Locked files
  • Issues 22
    • Issues 22
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
    • Requirements
  • Merge requests 0
    • Merge requests 0
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Metrics
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • Code review
    • Insights
    • Issue
    • Repository
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • GitLab.orgGitLab.org
  • GitLab FOSSGitLab FOSS
  • Issues
  • #46043
Closed (moved) (moved)
Open
Issue created May 04, 2018 by Fabio Busatto@bikebillyContributor

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:

  1. create working template like https://gitlab.com/gitlab-org/project-templates/dotnetcore, export
  2. add boilerplate to lib/gitlab/project_template.rb, spec/lib/gitlab/project_template.rb, and app/assets/javascripts/projects/project_new.js. See an MR like https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/25486 for an example.
  3. add exported project to /vendor/project_templates after running cleanup (see this issue above)
  4. run bin/rake gettext:regenerate in gitlab-ce project and commit new .pot file
  5. add changelog (something like bin/changelog -m 25486 "Add Project template for .NET")
  6. add icon to https://gitlab.com/gitlab-org/gitlab-svgs (illustrations/logos)
  7. run yarn run svgs on gitlab-svgs project and commit result
  8. forward changes in svgs project to master
  9. rebase master to pick up new svgs
  10. test everything is working

What would really be ideal is some automated process that does this whenever the project templates are updated.

Edited Mar 06, 2019 by Jason Yavorska
Assignee
Assign to
Time tracking