Add log to stdout option to gitlab-ctl registry import command
What does this MR do?
Adds a new log to stdout option to the gitlab-ctl registry import command. This builds upon !7265 (merged). This new registry CLI option was introduced in container-registry!1519 (merged) and released in v3.88.0, which is the version used by Omnibus since !7311 (merged).
Syntax
$ gitlab-ctl registry-database import -h
Import filesystem metadata into the database
Usage:
gitlab-ctl registry-database import [options]
Options:
...
-l, --log-to-stdout Write detailed log to standard output instead of showing progress bars
Testing
Initial setup
-
Setup a development Omnibus environment
-
Provision a separate PostgreSQL instance and create a logical database, for example:
CREATE USER registry WITH PASSWORD 'registrypassword' CREATE DATABASE registry_omnibus WITH OWNER registry
Alternatively, you can use the provisioned PostgreSQL instance but you will need to allow the registry to connect to it via Unix socket (sample)
-
Edit
/etc/gitlab/gitlab.rb
and enable the registry service:registry['enable'] = true
-
Also configure the database section under the registry configuration (update accordingly):
registry['database'] = { 'enabled' => true, 'host' => '172.17.0.1', 'port' => 5432, 'user' => 'registry', 'password' => 'registrypassword', 'dbname' => 'registry_omnibus', 'sslmode' => 'disable' }
-
Finally, update/add a
storage
section:registry['storage'] = { 'filesystem' => { 'rootdirectory' => "/var/opt/gitlab/gitlab-rails/shared/registry" } }
-
To be able to test the actual import we need some sample data that the registry tool will scan and record on the database. To make it easier we're going to use test fixtures from the registry codebase:
git clone --depth 1 -b master https://gitlab.com/gitlab-org/container-registry.git /tmp/fixtures cp -r /tmp/fixtures/registry/datastore/testdata/fixtures/importer/happy-path/docker /var/opt/gitlab/gitlab-rails/shared/registry
By doing the above we're populating the default storage location for the registry with a few sample repositories.
-
Reconfigure:
gitlab-ctl reconfigure
-
To test the newly added command, you need to replace/symlink the changed files in the right directory under your Omnibus installation. For example
ln -s /home/dev/files/gitlab-ctl-commands/registry_database.rb /opt/gitlab/embedded/service/omnibus-ctl/ ln -s /home/dev/files/gitlab-ctl-commands/lib/ /opt/gitlab/embedded/service/omnibus-ctl/
-
Now let's run all schema migrations to initialize our registry database:
$ gitlab-ctl registry-database migrate up
Command test
-
First we can test the import without the new flag:
$ gitlab-ctl registry-database import Running import Executing command: /opt/gitlab/embedded/bin/registry database import /var/opt/gitlab/registry/config.yml | [0s] registry import starting, detailed log written to: /root/omnibus-gitlab/container-registry/2024-01-04T14:55:35Z-registry-import.log | [0s] step one: import manifests | [2s] step two: import tags / [2s] step three: import blobs / [2s] registry import complete
-
Then, we can test the command with the new flag, and the output should be a plain log:
$ gitlab-ctl registry-database import -l Running import Executing command: /opt/gitlab/embedded/bin/registry database import --log-to-stdout /var/opt/gitlab/registry/config.yml INFO[0000] starting metadata import common_blobs=true dry_run=false environment=production go_version=go1.21.0 instance_id=834080f2-007d-48c7-8f5a-47011243f3a1 pre_import=true repository_import=true service=registry version=015c499 ... INFO[0002] metadata import complete common_blobs=true dry_run=false duration_s=2.526979383 environment=production go_version=go1.21.0 instance_id=834080f2-007d-48c7-8f5a-47011243f3a1 pre_import=true repository_import=true service=registry version=015c499
Related issues
Related to #8343 (closed).
Checklist
See Definition of done.
For anything in this list which will not be completed, please provide a reason in the MR discussion.
Required
-
MR title and description are up to date, accurate, and descriptive. -
MR targeting the appropriate branch. -
Latest Merge Result pipeline is green. -
When ready for review, MR is labeled "~workflow::ready for review" per the Distribution MR workflow.
For GitLab team members
If you don't have access to this, the reviewer should trigger these jobs for you during the review process.
-
The manual Trigger:ee-package
jobs have a green pipeline running against latest commit. -
If config/software
orconfig/patches
directories are changed, make sure thebuild-package-on-all-os
job within theTrigger:ee-package
downstream pipeline succeeded. -
If you are changing anything SSL related, then the Trigger:package:fips
manual job within theTrigger:ee-package
downstream pipeline must succeed. -
If CI configuration is changed, the branch must be pushed to dev.gitlab.org
to confirm regular branch builds aren't broken.
Expected (please provide an explanation if not completing)
-
Test plan indicating conditions for success has been posted and passes. -
Documentation created/updated. -
Tests added. -
Integration tests added to GitLab QA. -
Equivalent MR/issue for the GitLab Chart opened. -
Validate potential values for new configuration settings. Formats such as integer 10
, duration10s
, URIscheme://user:passwd@host:port
may require quotation or other special handling when rendered in a template and written to a configuration file.