Subscribe Us

header ads

Cara Setup CI/CD GitHub ke GCP (Google Cloud Platform) – Panduan Lengkap 2025

Berikut ini adalah panduan lengkap tentang Setup CI/CD GitHub ke GCP (Google Cloud Platform), cocok untuk kamu yang ingin mengotomatisasi deployment dari GitHub ke server cloud,



🔁 Cara Setup CI/CD GitHub ke GCP (Google Cloud Platform) – Panduan Lengkap 2025

Otomatisasi deployment atau Continuous Integration & Continuous Deployment (CI/CD) sangat penting untuk pengembangan aplikasi modern. Dalam artikel ini, kita akan belajar cara menghubungkan GitHub ke GCP agar setiap kali kamu push kode ke GitHub, sistem otomatis melakukan deploy ke server Google Cloud.


🎯 Apa Itu CI/CD?

  • CI (Continuous Integration): Otomatisasi build dan testing saat ada update kode.

  • CD (Continuous Deployment): Otomatisasi proses deploy setelah build sukses.

Dengan CI/CD, kamu bisa:

  • Mengurangi error manual

  • Deploy lebih cepat

  • Kolaborasi tim jadi lebih efisien


🛠️ Tools yang Akan Digunakan

Tool Fungsi
GitHub Menyimpan dan mengelola kode
GitHub Actions Layanan CI/CD dari GitHub
GCP (Google Cloud) Tempat aplikasi dideploy
Docker (opsional) Containerisasi aplikasi
Cloud Run / App Engine Tempat deploy otomatis

🌐 Arsitektur Dasar

  1. Kamu push kode ke GitHub

  2. GitHub Actions dijalankan otomatis

  3. Kode dibuild, dites, dan dideploy ke GCP (Cloud Run / App Engine / GKE)


✅ Prasyarat

  • Akun GitHub

  • Akun Google Cloud Platform (https://console.cloud.google.com/)

  • Sudah setup project GCP

  • Sudah aktifkan salah satu layanan: Cloud Run, App Engine, atau GKE

  • Sudah install gcloud CLI di lokal jika ingin testing


🔑 1. Setup Service Account & Credentials GCP

a. Buat Service Account

  1. Masuk ke Google Cloud Console

  2. Navigate ke: IAM & Admin → Service Accounts

  3. Klik Create Service Account

  4. Beri nama: github-cicd

  5. Assign Role:

    • Cloud Run Admin

    • Storage Admin

    • Service Account User

b. Buat JSON Key

  1. Setelah membuat akun, klik “Create Key”

  2. Pilih format JSON

  3. Simpan file key tersebut → jangan dibagikan!


🔧 2. Simpan Credential di GitHub Secrets

  1. Buka repository GitHub kamu

  2. Klik Settings → Secrets → Actions

  3. Tambahkan:

    • GCP_PROJECT_ID = ID proyek GCP kamu

    • GCP_SA_KEY = isi JSON key dari step sebelumnya (salin sebagai teks base64 atau string mentah)

    • GCP_REGION = misal asia-southeast2

    • GCP_APP_NAME = nama aplikasi di Cloud Run/App Engine


📄 3. Buat File GitHub Actions Workflow

Letakkan di:
.github/workflows/deploy.yml

Contoh CI/CD ke Cloud Run:

name: Deploy to Cloud Run

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout Repository
      uses: actions/checkout@v3

    - name: Authenticate to Google Cloud
      uses: google-github-actions/auth@v1
      with:
        credentials_json: ${{ secrets.GCP_SA_KEY }}

    - name: Setup Google Cloud SDK
      uses: google-github-actions/setup-gcloud@v1
      with:
        project_id: ${{ secrets.GCP_PROJECT_ID }}
        install_components: 'beta'

    - name: Deploy to Cloud Run
      run: |
        gcloud run deploy ${{ secrets.GCP_APP_NAME }} \
          --source . \
          --region ${{ secrets.GCP_REGION }} \
          --platform managed \
          --allow-unauthenticated

💡 Pastikan:

  • Folder root proyek sudah punya Dockerfile jika menggunakan --source .

  • Gunakan gcloud app deploy jika memakai App Engine.


🔄 Alternatif: Deploy ke App Engine (Tanpa Docker)

Buat file app.yaml di root proyek:

runtime: nodejs18
instance_class: F1
automatic_scaling:
  max_instances: 2

Ubah deploy.yml:

- name: Deploy to App Engine
  run: |
    gcloud app deploy --quiet

📈 Monitoring CI/CD Pipeline

  • Cek progress di tab Actions GitHub

  • Cek log deploy di Google Cloud Console → Cloud Run / App Engine

  • Pantau error atau build log dari GitHub dan GCP


🧠 Tips Tambahan

  • Gunakan branch staging untuk testing sebelum merge ke main

  • Tambahkan testing otomatis (unit test, lint, dsb) ke workflow GitHub Actions

  • Gunakan Docker jika kamu ingin deploy aplikasi lintas bahasa dan framework

  • Pastikan API dan billing sudah aktif di GCP


✅ Kesimpulan

Menghubungkan GitHub ke GCP menggunakan CI/CD GitHub Actions memungkinkan kamu untuk deploy otomatis setiap kali push kode. Proses ini hemat waktu, minim error, dan cocok untuk workflow pengembangan modern.


🔗 Baca panduan GCP & DevOps lainnya di iBoxnet:

  • Cara Deploy Project ke Google Cloud Run

  • Panduan Docker untuk Pemula

  • Rekomendasi Platform Cloud Gratis 2025

  • Setup CI/CD GitHub ke VPS Ubuntu (Non-GCP)

Posting Komentar

0 Komentar