Menyimpan format lain di Artifact Registry
Pelajari cara menyiapkan repositori format generik Artifact Registry dan mengupload file YAML.
Sebelum memulai
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Artifact Registry API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles. -
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Artifact Registry API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles. Untuk membuat repositori format generik bernama
quickstart-generic-repo
di lokasius-central1
dengan deskripsiGeneric repository
, jalankan perintah berikut:gcloud artifacts repositories create quickstart-generic-repo \ --repository-format=generic \ --location=us-central1 \ --description="Generic repository"
Untuk memverifikasi bahwa repositori Anda telah dibuat, jalankan perintah berikut:
gcloud artifacts repositories list
Untuk menyederhanakan perintah
gcloud
, jalankan perintah berikut untuk menetapkan repositori default kequickstart-generic-repo
dan lokasi default keus-central1
.Untuk menyetel repositori default ke
quickstart-generic-repo
, jalankan perintah berikut:gcloud config set artifacts/repository quickstart-generic-repo
Untuk menyetel lokasi default ke
us-central1
, jalankan perintah berikut:gcloud config set artifacts/location us-central1
Setelah nilai ditetapkan, Anda tidak perlu menentukannya dalam perintah
gcloud
yang memerlukan repositori atau lokasi.Di direktori utama, buat file untuk diupload ke repositori Anda:
echo "hello world" > hello.yaml
Untuk mengupload file sebagai artefak ke repositori, jalankan perintah berikut:
gcloud artifacts generic upload \ --source=hello.yaml \ --package=my-package \ --version=1.0.0
Dengan:
hello.yaml
adalah jalur file yang akan diupload.my-package
adalah paket yang akan diupload.1.0.0
adalah versi artefak. Anda tidak dapat menimpa versi yang ada di repositori.
hello.yaml
adalah nama file yang akan didownload.my-package
adalah paket yang akan didownload.1.0.0
adalah versi artefak.- In the Google Cloud console, go to the Manage resources page.
- In the project list, select the project that you want to delete, and then click Delete.
- In the dialog, type the project ID, and then click Shut down to delete the project.
Untuk menghapus repositori
quickstart-generic-repo
, jalankan perintah berikut:gcloud artifacts repositories delete quickstart-generic-repo
Jika Anda ingin menghapus setelan repositori dan lokasi default yang Anda konfigurasi untuk konfigurasi
gcloud
aktif, jalankan perintah berikut:gcloud config unset artifacts/repository gcloud config unset artifacts/location
Meluncurkan Cloud Shell
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
Dalam panduan memulai ini, Anda akan menggunakan Cloud Shell untuk menjalankan perintah gcloud
.
Membuat repositori generik
Mengupload artefak ke repositori
Melihat artefak di repositori
Untuk memverifikasi bahwa artefak Anda telah ditambahkan ke repositori, Anda dapat mencantumkan semua artefak dengan menjalankan perintah berikut:
gcloud artifacts files list
Respons mencakup detail file dalam format
PACKAGE:VERSION:FILE_NAME
.
Dalam contoh berikut, hello.yaml
adalah FILE_NAME
:
FILE: my-package:1.0.0:hello.yaml
CREATE_TIME: 2023-03-09T20:55:07
UPDATE_TIME: 2023-03-09T20:55:07
SIZE (MB): 0.000
OWNER: projects/my-project/locations/us-central1/repositories/quickstart-generic-repo/packages/my-package/versions/1.0.0
Mendownload artefak generik
Untuk mendownload artefak generik dari repositori Anda, jalankan perintah berikut:
gcloud artifacts generic download \
--name=hello.yaml \
--package=my-package \
--version=1.0.0 \
--destination=DESTINATION
Dengan:
Ganti DESTINATION
dengan direktori di sistem file lokal tempat Anda ingin menyimpan hasil download. Folder tujuan harus sudah ada atau perintah akan gagal.
Pembersihan
Agar tidak dikenai biaya pada akun Google Cloud Anda untuk resource yang digunakan dalam tutorial ini, hapus project yang berisi resource tersebut, atau simpan project dan hapus repositori.
Menghapus project
Hapus repositori
Sebelum menghapus repositori, pastikan semua paket yang ingin Anda simpan tersedia di lokasi lain.