Mengotomatiskan promosi rilis dan peningkatan peluncuran di Cloud Deploy

Halaman ini menunjukkan cara menggunakan Cloud Deploy untuk secara otomatis mempromosikan rilis ke target dan memajukan peluncuran ke fase berikutnya.

Dalam panduan memulai ini, Anda akan melakukan hal berikut:

  1. Buat dua cluster GKE atau dua layanan Cloud Run.

  2. Buat konfigurasi Skaffold dan manifes Kubernetes atau definisi layanan Cloud Run.

  3. Tentukan target deployment dan pipeline pengiriman Cloud Deploy Anda.

    Pipeline akan di-deploy ke dua target: dev dan staging. Target staging menggunakan strategi deployment canary.

  4. Tentukan dua aturan otomatisasi:

    • Otomatisasi untuk mempromosikan rilis ke target staging saat peluncuran berhasil ke dev.

    • Otomatisasi untuk memajukan peluncuran ke fase stable setelah berhasil menyelesaikan fase canary-25`.

  5. Buat instance pipeline pengiriman dengan membuat rilis, yang otomatis di-deploy ke target dev.

  6. Lihat pipeline pengiriman dan rilis di konsol Google Cloud .

    Karena promosi otomatis, rilis ini dipromosikan ke staging secara otomatis.

    Karena target staging menggunakan strategi deployment canary, dan ini adalah deployment pertama ke runtime tersebut, fase canary-25 dilewati. Lihat Mengapa fase terkadang dilewati untuk memahami lebih lanjut alasan fase uji coba dilewati untuk pertama kalinya.

    Karena percepatan fase otomatis, peluncuran akan dipercepat ke fase stable.

Sebelum memulai

  1. Login ke akun Google Cloud Anda. Jika Anda baru menggunakan Google Cloud, buat akun untuk mengevaluasi performa produk kami dalam skenario dunia nyata. Pelanggan baru juga mendapatkan kredit gratis senilai $300 untuk menjalankan, menguji, dan men-deploy workload.
  2. 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Cloud Deploy, Cloud Build, GKE, Cloud Run, and Cloud Storage APIs.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. 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.

    Enable the APIs

  5. Instal Google Cloud CLI.

  6. Jika Anda menggunakan penyedia identitas (IdP) eksternal, Anda harus login ke gcloud CLI dengan identitas gabungan Anda terlebih dahulu.

  7. Untuk melakukan inisialisasi gcloud CLI, jalankan perintah berikut:

    gcloud init
  8. 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  9. Verify that billing is enabled for your Google Cloud project.

  10. Enable the Cloud Deploy, Cloud Build, GKE, Cloud Run, and Cloud Storage APIs.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. 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.

    Enable the APIs

  11. Instal Google Cloud CLI.

  12. Jika Anda menggunakan penyedia identitas (IdP) eksternal, Anda harus login ke gcloud CLI dengan identitas gabungan Anda terlebih dahulu.

  13. Untuk melakukan inisialisasi gcloud CLI, jalankan perintah berikut:

    gcloud init
  14. Jika Anda sudah menginstal CLI, pastikan Anda menjalankan versi terbaru:

    gcloud components update
    
  15. Pastikan akun layanan Compute Engine default memiliki izin yang memadai.

    Akun layanan mungkin sudah memiliki izin yang diperlukan. Langkah-langkah ini disertakan untuk project yang menonaktifkan pemberian peran otomatis untuk akun layanan default.

    1. Pertama, tambahkan peran clouddeploy.jobRunner:
      gcloud projects add-iam-policy-binding PROJECT_ID \
          --member=serviceAccount:$(gcloud projects describe PROJECT_ID \
          --format="value(projectNumber)")-compute@developer.gserviceaccount.com \
          --role="roles/clouddeploy.jobRunner"
      
    2. Tambahkan peran clouddeploy.releaser:
      gcloud projects add-iam-policy-binding PROJECT_ID \
          --member=serviceAccount:$(gcloud projects describe PROJECT_ID \
          --format="value(projectNumber)")-compute@developer.gserviceaccount.com \
          --role="roles/clouddeploy.releaser"
      
    3. Tambahkan peran developer untuk runtime tertentu Anda.
      • Untuk GKE:
        gcloud projects add-iam-policy-binding PROJECT_ID \
            --member=serviceAccount:$(gcloud projects describe PROJECT_ID \
            --format="value(projectNumber)")-compute@developer.gserviceaccount.com \
            --role="roles/container.developer"
        
      • Untuk Cloud Run:
        gcloud projects add-iam-policy-binding PROJECT_ID \
            --member=serviceAccount:$(gcloud projects describe PROJECT_ID \
            --format="value(projectNumber)")-compute@developer.gserviceaccount.com \
            --role="roles/run.developer"
        
    4. Tambahkan peran iam.serviceAccountUser, yang mencakup izin actAs untuk akun layanan default agar dapat men-deploy ke runtime:
      gcloud iam service-accounts add-iam-policy-binding $(gcloud projects describe PROJECT_ID \
          --format="value(projectNumber)")-compute@developer.gserviceaccount.com \
          --member=serviceAccount:$(gcloud projects describe PROJECT_ID \
          --format="value(projectNumber)")-compute@developer.gserviceaccount.com \
          --role="roles/iam.serviceAccountUser" \
          --project=PROJECT_ID
      
    5. Tambahkan peran iam.serviceAccountUser, termasuk izin actAs untuk diri Anda, guna menggunakan akun layanan default:
      gcloud iam service-accounts add-iam-policy-binding $(gcloud projects describe PROJECT_ID \
          --format="value(projectNumber)")-compute@developer.gserviceaccount.com \
          --member=user:YOUR_EMAIL_ADDRESS \
          --role="roles/iam.serviceAccountUser" \
          --project=PROJECT_ID
      

      Dalam hal ini, YOUR_EMAIL_ADDRESS adalah alamat email yang Anda gunakan untuk mengakses Google Cloud.

Membuat lingkungan runtime

Jika men-deploy ke Cloud Run, Anda dapat melewati perintah ini.

Untuk GKE, buat dua cluster: automation-quickstart-cluster-dev dan automation-quickstart-cluster-staging, dengan setelan default. Endpoint Kubernetes API cluster harus dapat dijangkau melalui jaringan dari internet publik. Cluster GKE dapat diakses secara eksternal secara default.