debian-mirror-gitlab/doc/development/import_project.md

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

141 lines
5.8 KiB
Markdown
Raw Normal View History

2021-01-29 00:20:46 +05:30
---
stage: none
group: unassigned
2022-11-25 23:54:43 +05:30
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments
2021-01-29 00:20:46 +05:30
---
2023-05-27 22:25:52 +05:30
# Test import project
2020-03-13 15:44:24 +05:30
For testing, we can import our own [GitLab CE](https://gitlab.com/gitlab-org/gitlab-foss/) project (named `gitlabhq` in this case) under a group named `qa-perf-testing`. Project tarballs that can be used for testing can be found over on the [performance-data](https://gitlab.com/gitlab-org/quality/performance-data) project. A different project could be used if required.
2023-05-27 22:25:52 +05:30
You can import the project into your GitLab environment in a number of ways. They are detailed as follows with the
assumption that the recommended group `qa-perf-testing` and project `gitlabhq` are being set up.
2020-03-13 15:44:24 +05:30
## Importing the project
2023-05-27 22:25:52 +05:30
Use one of these methods to import the test project.
2020-03-13 15:44:24 +05:30
2023-05-27 22:25:52 +05:30
### Import by using the UI
2020-03-13 15:44:24 +05:30
2023-05-27 22:25:52 +05:30
The first option is to [import the project tarball file by using the GitLab UI](../user/project/settings/import_export.md#import-a-project-and-its-data):
2020-03-13 15:44:24 +05:30
2023-05-27 22:25:52 +05:30
1. Create the group `qa-perf-testing`.
1. Import the [GitLab FOSS project tarball](https://gitlab.com/gitlab-org/quality/performance-data/-/blob/master/projects_export/gitlabhq_export.tar.gz) into the group.
2020-03-13 15:44:24 +05:30
It should take up to 15 minutes for the project to fully import. You can head to the project's main page for the current status.
2021-02-22 17:27:13 +05:30
This method ignores all the errors silently (including the ones related to `GITALY_DISABLE_REQUEST_LIMITS`) and is used by GitLab users. For development and testing, check the other methods below.
2020-03-13 15:44:24 +05:30
2023-05-27 22:25:52 +05:30
### Import by using the `import-project` script
2020-03-13 15:44:24 +05:30
A convenient script, [`bin/import-project`](https://gitlab.com/gitlab-org/quality/performance/blob/master/bin/import-project), is provided with [performance](https://gitlab.com/gitlab-org/quality/performance) project to import the Project tarball into a GitLab environment via API from the terminal.
2021-02-22 17:27:13 +05:30
Note that to use the script, it requires some preparation if you haven't done so already:
2020-03-13 15:44:24 +05:30
1. First, set up [`Ruby`](https://www.ruby-lang.org/en/documentation/installation/) and [`Ruby Bundler`](https://bundler.io) if they aren't already available on the machine.
1. Next, install the required Ruby Gems via Bundler with `bundle install`.
For details how to use `bin/import-project`, run:
```shell
bin/import-project --help
```
2021-02-22 17:27:13 +05:30
The process should take up to 15 minutes for the project to import fully. The script checks the status periodically and exits after the import has completed.
2020-03-13 15:44:24 +05:30
2023-05-27 22:25:52 +05:30
### Import by using GitHub
2020-03-13 15:44:24 +05:30
There is also an option to [import the project via GitHub](../user/project/import/github.md):
1. Create the group `qa-perf-testing`
1. Import the GitLab FOSS repository that's [mirrored on GitHub](https://github.com/gitlabhq/gitlabhq) into the group via the UI.
2021-02-22 17:27:13 +05:30
This method takes longer to import than the other methods and depends on several factors. It's recommended to use the other methods.
2020-03-13 15:44:24 +05:30
2023-05-27 22:25:52 +05:30
### Import by using a Rake task
2022-08-13 15:12:31 +05:30
2023-05-27 22:25:52 +05:30
To import the test project by using a Rake task, see
[Import large projects](../administration/raketasks/project_import_export.md#import-large-projects).
2022-08-13 15:12:31 +05:30
2023-05-27 22:25:52 +05:30
### Import by using the Rails console
2020-03-13 15:44:24 +05:30
The last option is to import a project using a Rails console:
1. Start a Ruby on Rails console:
```shell
# Omnibus GitLab
gitlab-rails console
# For installations from source
2020-04-22 19:07:51 +05:30
sudo -u git -H bundle exec rails console -e production
2020-03-13 15:44:24 +05:30
```
2020-04-08 14:13:33 +05:30
1. Create a project and run `Project::TreeRestorer`:
2020-03-13 15:44:24 +05:30
```ruby
shared_class = Struct.new(:export_path) do
def error(message)
raise message
end
end
user = User.first
shared = shared_class.new(path)
project = Projects::CreateService.new(user, { name: name, namespace: user.namespace }).execute
begin
#Enable Request store
RequestStore.begin!
2020-04-08 14:13:33 +05:30
Gitlab::ImportExport::Project::TreeRestorer.new(user: user, shared: shared, project: project).restore
2020-03-13 15:44:24 +05:30
ensure
RequestStore.end!
RequestStore.clear!
end
```
1. In case you need the repository as well, you can restore it using:
```ruby
repo_path = File.join(shared.export_path, Gitlab::ImportExport.project_bundle_filename)
Gitlab::ImportExport::RepoRestorer.new(path_to_bundle: repo_path,
shared: shared,
2021-03-11 19:13:27 +05:30
importable: project).restore
2020-03-13 15:44:24 +05:30
```
2020-04-08 14:13:33 +05:30
We are storing all import failures in the `import_failures` data table.
2020-03-13 15:44:24 +05:30
2020-04-08 14:13:33 +05:30
To make sure that the project import finished without any issues, check:
2020-03-13 15:44:24 +05:30
2020-04-08 14:13:33 +05:30
```ruby
project.import_failures.all
```
2020-03-13 15:44:24 +05:30
## Performance testing
For Performance testing, we should:
- Import a quite large project, [`gitlabhq`](https://gitlab.com/gitlab-org/quality/performance-data#gitlab-performance-test-framework-data) should be a good example.
2020-04-08 14:13:33 +05:30
- Measure the execution time of `Project::TreeRestorer`.
2020-03-13 15:44:24 +05:30
- Count the number of executed SQL queries during the restore.
- Observe the number of GC cycles happening.
2021-02-22 17:27:13 +05:30
You can use this snippet: `https://gitlab.com/gitlab-org/gitlab/snippets/1924954` (must be logged in), which restores the project, and measures the execution time of `Project::TreeRestorer`, number of SQL queries and number of GC cycles happening.
2020-03-13 15:44:24 +05:30
You can execute the script from the `gdk/gitlab` directory like this:
```shell
2021-11-11 11:23:49 +05:30
bundle exec rails r /path_to_script/script.rb project_name /path_to_extracted_project request_store_enabled
2020-03-13 15:44:24 +05:30
```
## Access token setup
2023-05-27 22:25:52 +05:30
Many of the tests also require a GitLab personal access token because numerous endpoints require authentication themselves.
2020-03-13 15:44:24 +05:30
2023-05-27 22:25:52 +05:30
[The GitLab documentation details how to create this token](../user/profile/personal_access_tokens.md#create-a-personal-access-token).
The tests require that the token is generated by an administrator and that it has the `API` and `read_repository` permissions.
2020-03-13 15:44:24 +05:30
Details on how to use the Access Token with each type of test are found in their respective documentation.