はじめに

Container Registryを使用しているプロジェクトがあり、Artifact Registryへ移行する旨の案内が来たために対応した内容となります。

Container Registryの廃止スケジュールについて

廃止スケジュールについては下記内容の案内となっておりました。

2025年3月18日:新しいイメージをContainer Registryにプッシュできなくなります。
2025年4月22日:Container Registry内の既存のイメージにアクセスできなくなります。アクセスを維持するには、この日付より前にArtifact Registryにコピーする必要があります。
2025年5月22日:gcr.ioドメインへのすべてのリクエストはArtifact Registryによって独占的に処理されます。Artifact Registry APIが有効になっていることを確認します。

やりたいこと

Container Registryから、Artifact Registryへの移行を行います。
https://cloud.google.com/artifact-registry/docs/transition/transition-from-gcr?hl=ja
こちらに概要含め手順など記載があるため、この内容に沿って対応していきます。
また、移行する際には2つの方法があり「標準リポジトリへの移行」と「Artifact Registryでデフォルトでホストされているgcr.ioリポジトリへの移行」があります。
現在のプロジェクトではContainer Registryを使用してdeployしているのみで、Artifact Registryの全ての機能を使用することはないため、今回はgcr.ioをサポートするArtifact Registryリポジトリに移行する手順にします。

移行方法について

https://cloud.google.com/artifact-registry/docs/transition/auto-migrate-gcr-ar?hl=ja
こちらに記載のある通り、自動移行ツールが用意されているためこの移行ツールを使用して移行を行います。

事前準備

ロールの付与

・Artifact RegistryのサービスアカウントにStorageオブジェクト管理者(roles/storage.objectAdmin)を付与します。
・移行を実施するユーザーにArtifact Registry管理者(roles/artifactregistry.admin)を付与します。

APIの有効化

・Artifact RegistryのAPI(artifactregistry.googleapis.com)を有効化します。
・Cloud AssetのAPI(cloudasset.googleapis.com)を有効化します。

実行

Google Cloud CLIで下記コマンドで実行します。projectsオプションは対象プロジェクト名を指定します。質問が表示されたら回答していきます。

$ gcloud artifacts docker upgrade migrate --projects=test-project
Repository report for test-project:

Container Registry Host  Location  Artifact Registry Repository
gcr.io                   us        None Found. Can create repo named "gcr.io"
us.gcr.io                us        None Found. Can create repo named "us.gcr.io"
asia.gcr.io              asia      None Found. Can create repo named "asia.gcr.io"
eu.gcr.io                europe    None Found. Can create repo named "eu.gcr.io"

gcloud can automatically create the 4 missing repos in Artifact Registry.
If you would like to setup CMEK for these repos, exit now and create them manually instead.

Create missing repos (recommended) (Y/n)?  y

Waiting for repo creation to complete......done.
Waiting for repo creation to complete......done.
Waiting for repo creation to complete......done.
Waiting for repo creation to complete......done.

Copying initial images (additional images will be copied later)...

Copying images for test-project... done.

test-project: Successfully copied 1 additional tags and 1 additional manifests. There were 0 failures.
Cannot generate a new IAM policy because you do not have permission to view existing policies. See
https://cloud.google.com/policy-intelligence/docs/analyze-iam-policies#required-permissions for required permissions. If you continue, users may lose access to
*gcr.io repositories.

Continue without updating IAM policy? (Y/n)?  y

The next step will redirect all *gcr.io traffic to Artifact Registry. Remaining Container Registry images will be copied. During migration, Artifact Registry will serve *gcr.io requests for images it doesn't have yet by copying them from Container Registry at request time. Deleting images from *gcr.io repos in the middle of migration might not be effective.

IMPORTANT: Make sure to update any relevant VPC-SC policies before migrating. Once *gcr.io is redirected to Artifact Registry, the artifactregistry.googleapis.com service will be checked for VPC-SC instead of containerregistry.googleapis.com.

Projects to redirect: ['test-project']

Do you want to continue (Y/n)?  y

*gcr.io traffic is now being served by Artifact Registry for test-project. Missing images are being copied from Container Registry
To send traffic back to Container Registry, run:
  gcloud artifacts settings disable-upgrade-redirection --project=test-project

Copying remaining images...

Copying images for test-project... done.

test-project: Successfully copied 10 additional tags and 15 additional manifests. There were 0 failures.

*gcr.io traffic is now being fully served by Artifact Registry for test-project. Images will no longer be copied from Container Registry for this project.

The following projects are fully migrated: ['test-project']
$

確認

コンソール画面でArtifact Registryにリポジトリがコピーされていることを確認します。コピーされていれば正常に移行ができた状態となります。実行後のコンソール画面では、Container Registryのページには遷移ができず、Artifact Registryのページへ遷移される状態になります。
自動移行ツールを使用することでコマンド一つで実施できるので移行対応は円滑に対応できました。


現在 Container Registry を使用している場合は、Artifact Registry への移行について学ぶことができます。