Men-deploy tombol fitur dengan konsol Google Cloud
Sebelum memulai
-
Login ke Akun Google Anda.
Jika Anda belum memilikinya, Daftar untuk membuat akun baru.
-
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 role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the App Lifecycle Manager, SaaS Config, App Design Center, Artifact Registry, Cloud Storage, and Infrastructure Manager APIs, if any are not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init -
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 role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the App Lifecycle Manager, SaaS Config, App Design Center, Artifact Registry, Cloud Storage, and Infrastructure Manager APIs, if any are not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init -
Pastikan akun pengguna Anda memiliki peran Identity and Access Management berikut di project
Google Cloud Anda:
- Admin App Lifecycle Manager (
roles/saasservicemgmt.admin) - App Design Center Admin (
roles/designcenter.admin) - SaaS Config Viewer (
roles/saasconfig.viewer) - Service Account Admin (
roles/iam.serviceAccountAdmin) dan Project IAM Admin (roles/resourcemanager.projectIamAdmin)
- Admin App Lifecycle Manager (
-
Pastikan ruang App Design Center dan
akun layanan App Lifecycle Manager
telah dikonfigurasi, termasuk
akun layanan aktuasi
yang dikelola pengguna yang diberi peran Service Account Token Creator
(
roles/iam.serviceAccountTokenCreator), Infra Manager Admin (roles/config.admin), dan Storage Admin (roles/storage.admin) di project Anda. Untuk mengetahui informasi selengkapnya tentang akun layanan App Lifecycle Manager, lihat Akun layanan. -
Instal Python 3.10 atau yang lebih baru dan
pipdi komputer lokal Anda, lalu autentikasi Google Cloud CLI untuk Kredensial Default Aplikasi (ADC):gcloud auth application-default login
Membuat penawaran SaaS di konsol
Buat resource penawaran SaaS sebagai container tingkat teratas untuk model layanan dan tombol fitur Anda:
Di konsol Google Cloud , buka App Lifecycle Manager > SaaS offerings.
Klik Create.
Di kolom SaaS offering name, masukkan
flags-quickstart-offering.Dalam daftar Region, pilih
us-central1, lalu klik OK.Klik Create. Setelah pembuatan selesai, halaman Detail penawaran SaaS akan terbuka.
Membuat model layanan di App Design Center
Dalam alur kerja Berfokus pada Aplikasi, Anda menentukan jenis unit dengan membuat template aplikasi di App Design Center. Jika Anda ingin menggunakan tombol fitur tanpa menyediakan infrastruktur cloud melalui App Lifecycle Manager, Anda membuat template gabungan yang berisi template aplikasi standar kosong untuk setiap jenis layanan dalam arsitektur Anda (misalnya, aplikasi backend, aplikasi frontend, atau layanan gateway). Template standar kosong mendeklarasikan jenis layanan tanpa men-deploy resource cloud. Jika Anda siap mengelola deployment infrastruktur melalui App Lifecycle Manager, Anda dapat menambahkan komponen Terraform ke template standar.
Untuk membuat template standar kosong di dalam template gabungan dan membuat jenis unit, selesaikan langkah-langkah berikut:
- Di halaman SaaS offering details untuk
flags-quickstart-offering, klik Create new template. - Di kolom Template ID, masukkan
flags-composite-template, lalu klik Create template. - Di bagian Connected application template, klik menu Manage template, lalu klik Configure in canvas untuk membuka App Design Center.
- Di area Components pada kanvas desain, klik Embed template, lalu klik Create a new template.
- Di kolom Template ID, masukkan
backend-service-template, lalu klik Create template untuk membuka kanvas template standar. - Biarkan kanvas
backend-service-templatekosong tanpa menambahkan komponen, lalu klik Add to Catalog untuk memublikasikan template standar ke katalog ruang Anda. - Kembali ke kanvas desain
flags-composite-template, klik Embed template, pilihbackend-service-templatedari Templates, lalu klik Select. - Klik Add to Catalog untuk memublikasikan revisi template gabungan, lalu klik Continue > Deploy at scale with App Lifecycle Manager.
- Di bagian Connected application template pada halaman SaaS offering
details, klik Update template revision, pilih revisi terbaru
flags-composite-template, lalu klik Update (atau klik Connect existing template jika menghubungkan template yang dibuat langsung di App Design Center). - Buka tab Unit kinds di halaman SaaS offering details dan pastikan
App Lifecycle Manager telah membuat jenis unit untuk
backend-service-template.
Membuat dan menyediakan unit
Buat dan sediakan unit untuk mewakili instance regional layanan Anda yang menerima konfigurasi tombol fitur. Karena template standar Anda di
App Design Center kosong, penyediaan akan menjalankan aktuasi infrastruktur
tanpa operasi tanpa men-deploy resource cloud dan mentransisikan
unit ke status Ready sehingga saasconfig.googleapis.com dapat menyajikan
konfigurasi tombol fiturnya:
Di konsol Google Cloud , buka App Lifecycle Manager > Units.
Klik Create.
Di kolom Unit name, masukkan
backend-service-unit.Dalam daftar SaaS offering, pilih
flags-quickstart-offering.Di daftar Region, pilih
us-central1.Dalam daftar Unit kind, pilih jenis unit
backend-service-template-yang dihasilkan di bagian sebelumnya.Klik Create. Setelah pembuatan selesai, halaman Unit details akan terbuka.
Di halaman Unit details, klik Provision untuk membuka panel Provision unit.
Dalam daftar Release, pilih rilis yang dihasilkan untuk jenis unit
backend-service-template-Anda.Dalam daftar Service account, pilih akun layanan aktuasi Anda, lalu pilih Grant App Lifecycle Manager permission to act on behalf of the actuation service account.
Klik Add tenant project variables, lalu pilih project Anda untuk mengisi
tenant_project_iddantenant_project_number.Klik Provision, lalu tunggu hingga State unit di halaman Unit details mencapai Ready.
Membuat dan men-deploy tombol fitur di konsol
Tentukan tombol fitur boolean dan jalankan peluncuran untuk mengirimkan rilis tombol ke unit Anda:
- Di konsol Google Cloud , buka App Lifecycle Manager > Tombol fitur, lalu klik Buat tombol fitur.
- Di kolom Unit kind, pilih jenis unit
backend-service-template-Anda. - Di kolom Flag key, masukkan
enable-new-feature(Flag id akan otomatis diisi setelah Anda memasukkan kunci flag). - Tetapkan Flag value ke
enabled, lalu klik Create. - Buka App Lifecycle Manager > Flag releases, lalu klik Create.
- Masukkan
enable-new-feature-rel-1di kolom Flag release name, pilih jenis unitbackend-service-template-Anda di daftar Unit kind, pilih Feature flag di daftar Release type, pilih flagenable-new-featureAnda di daftar Select feature flags, lalu klik Create. App Lifecycle Manager membuat revisi flag yang mendasarinya secara otomatis. - Buka App Lifecycle Manager > Rollout kinds, lalu klik Create.
- Di kolom Rollout kind name, masukkan
flags-quickstart-rollout-kind. - Dalam daftar Unit Kind, pilih jenis unit
backend-service-template-Anda. - Dalam daftar Rollout Strategy, pilih All locations at once.
- Klik Create.
- Buka App Lifecycle Manager > Rollouts, lalu klik Create.
- Pilih Peluncuran tombol fitur.
- Di kolom Rollout name, masukkan
flags-quickstart-rollout. - Dalam daftar Unit Kind, pilih jenis unit
backend-service-template-Anda. - Dalam daftar rilis tombol fitur, pilih
enable-new-feature-rel-1, lalu klik Berikutnya. - Pilih Select existing rollout kind, lalu pilih
flags-quickstart-rollout-kinddi daftar Rollout Kind. - Klik Create untuk memulai peluncuran dan mengirimkan konfigurasi ke
backend-service-unit. - Tunggu hingga status peluncuran mencapai Succeeded.
Mengevaluasi tombol fitur
Evaluasi flag enable-new-feature secara lokal menggunakan OpenFeature SDK dan
penyedia flagd yang terhubung ke saasconfig.googleapis.com:443:
Instal paket Python yang diperlukan:
pip install --upgrade google-auth grpcio requests "openfeature-sdk>=0.8.2" "openfeature-provider-flagd>=0.6.1"Buat file bernama
evaluate_flag.pydengan kode berikut:import os import time import google.auth import google.auth.transport.grpc import google.auth.transport.requests import grpc from openfeature import api from openfeature.contrib.provider.flagd import FlagdProvider from openfeature.contrib.provider.flagd.config import ResolverType provider_id = os.environ["FLAGD_SOURCE_PROVIDER_ID"] credentials, _ = google.auth.default( scopes=["https://www.googleapis.com/auth/cloud-platform"] ) channel_creds = grpc.composite_channel_credentials( grpc.ssl_channel_credentials(), grpc.metadata_call_credentials( google.auth.transport.grpc.AuthMetadataPlugin( credentials, google.auth.transport.requests.Request() ) ), grpc.metadata_call_credentials( lambda ctx, cb: cb( [("x-goog-request-params", f"name={provider_id}")], None ) ), ) api.set_provider( FlagdProvider( resolver_type=ResolverType.IN_PROCESS, host="saasconfig.googleapis.com", port=443, sync_metadata_disabled=True, provider_id=provider_id, channel_credentials=channel_creds, ) ) time.sleep(5) value = api.get_client().get_boolean_value("enable-new-feature", False) print(f"Flag 'enable-new-feature' evaluated to: {value}")Tetapkan variabel lingkungan
FLAGD_SOURCE_PROVIDER_IDke jalur resource konfigurasi tombol fitur unit Anda dan jalankan skrip:export FLAGD_SOURCE_PROVIDER_ID="projects/PROJECT_ID/locations/us-central1/featureFlagsConfigs/backend-service-unit" python evaluate_flag.pyGanti
PROJECT_IDdengan project ID Google CloudAnda.Skrip akan menghasilkan
Flag 'enable-new-feature' evaluated to: True.
Pembersihan
Agar akun Google Cloud Anda tidak dikenai biaya untuk resource yang digunakan pada halaman ini, ikuti langkah-langkah berikut.
Agar tidak dikenai biaya berkelanjutan, hapus project pengujian Anda di
Manage resources,
atau hapus resource yang Anda buat dalam urutan dependensi terbalik. Menandai
tombol fitur untuk pembersihan (status CLEANUP) guna membatalkan tautannya dari jenis unit
memerlukan gcloud CLI atau App Lifecycle Manager API:
Tetapkan status flag ke
cleanup, buat rilis flag pembersihan, dan jalankan peluncuran pembersihan untuk membatalkan tautan flag dari jenis unit Anda:gcloud beta app-lifecycle-manager flags update FLAG_ID \ --project=PROJECT_ID \ --location=global \ --state=cleanup gcloud beta app-lifecycle-manager flags releases create enable-new-feature-cleanup-rel \ --project=PROJECT_ID \ --unit-kind=UNIT_KIND_ID \ --flags=FLAG_ID \ --location=global gcloud beta app-lifecycle-manager rollouts create enable-new-feature-cleanup-rollout \ --project=PROJECT_ID \ --flag-release=enable-new-feature-cleanup-rel \ --rollout-kind=flags-quickstart-rollout-kind \ --location=globalGanti kode berikut:
FLAG_ID: ID tombol fitur Anda (diisi otomatis sebagaiUNIT_KIND_ID-enable-new-feature).PROJECT_ID: Project ID Google Cloud Anda.UNIT_KIND_ID: ID jenis unitbackend-service-template-Anda.
Setelah peluncuran pembersihan mencapai Succeeded, hapus peluncuran, jenis peluncuran (
flags-quickstart-rollout-kind), dan rilis flag (enable-new-feature-rel-1danenable-new-feature-cleanup-rel) di konsolGoogle Cloud .Cari dan hapus revisi flag yang dibuat otomatis, lalu hapus flag fitur Anda:
gcloud beta app-lifecycle-manager flags revisions list \ --project=PROJECT_ID \ --location=global \ --filter="flag:FLAG_ID" gcloud beta app-lifecycle-manager flags revisions delete REVISION_ID \ --project=PROJECT_ID \ --location=globalGanti
REVISION_IDdengan setiap ID revisi yang ditampilkan oleh perintahlist, lalu hapus tombol fitur di Google Cloud console.Cabut akses
backend-service-unitdi halaman Unit details (klik Deprovision, konfirmasi dalam dialog, dan tunggu hingga statusnya mencapai Not provisioned), lalu hapus resource yang tersisa dalam urutan dependensi terbalik: unit (backend-service-unit), rilis default jenis unit dan rilis blueprint yang dihasilkan (hapus rilis default pada jenis unit sebelum menghapus rilis blueprint), jenis unit, dan penawaran SaaS (flags-quickstart-offering). Untuk aturan penghapusan App Lifecycle Manager, lihat Menghapus resource.Menghapus
flags-composite-templatedanbackend-service-templatedi App Design Center.
Langkah berikutnya
- Baca ringkasan tombol fitur App Lifecycle Manager.
- Coba panduan memulai Deploy tombol fitur untuk deployment yang dikelola infrastruktur.
- Konfigurasikan pemisahan traffic berbasis persentase di Menggunakan peluncuran fitur bertahap.
- Diagnosis masalah evaluasi atau peluncuran flag di Memecahkan masalah flag fitur.