GitLab依存プロキシの管理
- プラン: Free、Premium、Ultimate
- 提供形態: GitLab Self-Managed
GitLabを、コンテナイメージやパッケージなど、頻繁にアクセスされるアップストリームアーティファクトの依存プロキシとして使用できます。
これは管理者向けのドキュメントです。依存プロキシの使用方法については、以下を参照してください:
GitLab依存プロキシ:
- デフォルトでオンになっています。
- 管理者がオフにすることができます。
依存プロキシをオフにする
依存プロキシはデフォルトで有効になっています。管理者の場合、依存プロキシをオフにすることができます。依存プロキシをオフにするには、GitLabインスタンスに対応する手順に従ってください。
/etc/gitlab/gitlab.rbを編集して、次の行を追加します:gitlab_rails['dependency_proxy_enabled'] = falseファイルを保存して、GitLabを再設定し、変更を有効にします。
インストールが完了したら、グローバルのappConfigを更新して、依存プロキシをオフにします:
global:
appConfig:
dependencyProxy:
enabled: false
bucket: gitlab-dependency-proxy
connection:
secret:
key:詳細については、グローバルを使用したチャートの設定を参照してください。
インストールが完了したら、
config/gitlab.ymlのdependency_proxyセクションを設定します。依存プロキシをオフにするには、enabledをfalseに設定します:dependency_proxy: enabled: false変更を反映させるため、GitLabを再起動します。
マルチノードGitLabインストール
各ウェブとSidekiqノードのLinuxパッケージインストールの手順に従ってください。
依存プロキシをオンにする
依存プロキシはデフォルトでオンになっていますが、管理者がオフにすることができます。手動でオフにするには、Dependency Proxyをオフにするの手順に従ってください。
ストレージパスの変更
デフォルトでは、依存プロキシファイルはローカルに保存されますが、デフォルトのローカルの場所を変更したり、オブジェクトストレージを使用したりすることもできます。
ローカルストレージパスの変更
Linuxパッケージインストールの依存プロキシファイルは/var/opt/gitlab/gitlab-rails/shared/dependency_proxy/に、ソースインストールの場合はshared/dependency_proxy/(Gitホームディレクトリからの相対パス)に保存されます。
/etc/gitlab/gitlab.rbを編集して、次の行を追加します:gitlab_rails['dependency_proxy_storage_path'] = "/mnt/dependency_proxy"ファイルを保存して、GitLabを再設定し、変更を有効にします。
config/gitlab.ymlのdependency_proxyセクションを編集します:dependency_proxy: enabled: true storage_path: shared/dependency_proxy変更を反映させるため、GitLabを再起動します。
オブジェクトストレージを使用する
ローカルストレージに頼る代わりに、統合されたオブジェクトストレージ設定を使用できます。このセクションでは、以前の設定形式について説明します。移行手順は引き続き適用されます。
GitLabにおけるオブジェクトストレージの使用の詳細については、こちらをご覧ください。
/etc/gitlab/gitlab.rbを編集し、次の行を追加します(必要に応じてコメントを解除):gitlab_rails['dependency_proxy_enabled'] = true gitlab_rails['dependency_proxy_storage_path'] = "/var/opt/gitlab/gitlab-rails/shared/dependency_proxy" gitlab_rails['dependency_proxy_object_store_enabled'] = true gitlab_rails['dependency_proxy_object_store_remote_directory'] = "dependency_proxy" # The bucket name. gitlab_rails['dependency_proxy_object_store_proxy_download'] = false # Passthrough all downloads via GitLab instead of using Redirects to Object Storage. gitlab_rails['dependency_proxy_object_store_connection'] = { ## ## If the provider is AWS S3, uncomment the following ## #'provider' => 'AWS', #'region' => 'eu-west-1', #'aws_access_key_id' => 'AWS_ACCESS_KEY_ID', #'aws_secret_access_key' => 'AWS_SECRET_ACCESS_KEY', ## ## If the provider is other than AWS (an S3-compatible one), uncomment the following ## #'host' => 's3.amazonaws.com', #'aws_signature_version' => 4 # For creation of signed URLs. Set to 2 if provider does not support v4. #'endpoint' => 'https://s3.amazonaws.com' # Useful for S3-compliant services such as DigitalOcean Spaces. #'path_style' => false # If true, use 'host/bucket_name/object' instead of 'bucket_name.host/object'. }ファイルを保存して、GitLabを再設定し、変更を有効にします。
config/gitlab.ymlのdependency_proxyセクションを編集します(必要に応じてコメントを解除):dependency_proxy: enabled: true ## ## The location where build dependency_proxy are stored (default: shared/dependency_proxy). ## # storage_path: shared/dependency_proxy object_store: enabled: false remote_directory: dependency_proxy # The bucket name. # proxy_download: false # Passthrough all downloads via GitLab instead of using Redirects to Object Storage. connection: ## ## If the provider is AWS S3, use the following ## provider: AWS region: us-east-1 aws_access_key_id: AWS_ACCESS_KEY_ID aws_secret_access_key: AWS_SECRET_ACCESS_KEY ## ## If the provider is other than AWS (an S3-compatible one), comment out the previous 4 lines and use the following instead: ## # host: 's3.amazonaws.com' # default: s3.amazonaws.com. # aws_signature_version: 4 # For creation of signed URLs. Set to 2 if provider does not support v4. # endpoint: 'https://s3.amazonaws.com' # Useful for S3-compliant services such as DigitalOcean Spaces. # path_style: false # If true, use 'host/bucket_name/object' instead of 'bucket_name.host/object'.変更を反映させるため、GitLabを再起動します。
ローカル依存プロキシのblobとマニフェストをオブジェクトストレージに移行する
オブジェクトストレージを設定した後、次のタスクを使用して、既存の依存プロキシのblobとマニフェストをローカルストレージからリモートストレージに移行します。この処理はバックグラウンドワーカーで実行され、ダウンタイムは不要です。
Linuxパッケージインストールの場合:
sudo gitlab-rake "gitlab:dependency_proxy:migrate"自己コンパイルによるインストールの場合:
RAILS_ENV=production sudo -u git -H bundle exec rake gitlab:dependency_proxy:migrate
オプションで、PostgreSQLコンソールを使用して、すべての依存プロキシのblobとマニフェストが正常に移行されたことを追跡し、検証できます:
- バージョン14.1以前のLinuxパッケージインストールを実行している場合は
sudo gitlab-rails dbconsole。 - バージョン14.2以降のLinuxパッケージインストールを実行している場合は
sudo gitlab-rails dbconsole --database main。 - 自己コンパイルインスタンスの場合は
sudo -u git -H psql -d gitlabhq_production。
objectstg(file_store = '2'の場合)に、それぞれのクエリに対するすべての依存プロキシのblobとマニフェストのカウントがあることを確認します:
gitlabhq_production=# SELECT count(*) AS total, sum(case when file_store = '1' then 1 else 0 end) AS filesystem, sum(case when file_store = '2' then 1 else 0 end) AS objectstg FROM dependency_proxy_blobs;
total | filesystem | objectstg
------+------------+-----------
22 | 0 | 22
gitlabhq_production=# SELECT count(*) AS total, sum(case when file_store = '1' then 1 else 0 end) AS filesystem, sum(case when file_store = '2' then 1 else 0 end) AS objectstg FROM dependency_proxy_manifests;
total | filesystem | objectstg
------+------------+-----------
10 | 0 | 10ディスク上のdependency_proxyフォルダーにファイルがないことを確認します:
sudo find /var/opt/gitlab/gitlab-rails/shared/dependency_proxy -type f | grep -v tmp | wc -lJWT有効期限の変更
依存プロキシはDocker v2トークン認証フローに従い、プルリクエストに使用するJSON Webトークンをクライアントに発行します。トークン有効期限は、アプリケーション設定container_registry_token_expire_delayを使用して設定可能です。これは、Railsコンソールから変更できます:
# update the JWT expiration to 30 minutes
ApplicationSetting.update(container_registry_token_expire_delay: 30)デフォルトの有効期限とGitLab.comの有効期限は15分です。
プロキシの背後で依存プロキシを使用する
/etc/gitlab/gitlab.rbを編集し、次の行を追加します:gitlab_workhorse['env'] = { "http_proxy" => "http://USERNAME:PASSWORD@example.com:8080", "https_proxy" => "http://USERNAME:PASSWORD@example.com:8080" }ファイルを保存して、GitLabを再設定し、変更を有効にします。