Deploy ke Google Cloud Run dengan CI/CD
Panduan lengkap deploy aplikasi containerized ke Google Cloud Run dengan pipeline CI/CD menggunakan GitHub Actions.
Deploy ke Google Cloud Run dengan CI/CD
Cloud Run adalah serverless platform dari Google Cloud yang memungkinkan kita menjalankan container tanpa perlu manage infrastructure. Di artikel ini, saya akan share pengalaman deploy aplikasi ke Cloud Run.
Kenapa Cloud Run?
- Pay per use - Hanya bayar saat container running
- Auto scaling - Scale dari 0 sampai ribuan instance
- Container-based - Deploy container apapun
- Managed SSL - HTTPS gratis otomatis
Persiapan Dockerfile
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 8080
CMD ["npm", "start"]
Setup GitHub Actions
Buat file .github/workflows/deploy.yml:
name: Deploy to Cloud Run
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Auth GCP
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}
- name: Deploy to Cloud Run
uses: google-github-actions/deploy-cloudrun@v2
with:
service: my-app
region: asia-southeast1
source: .
Environment Variables
Untuk secrets, gunakan Secret Manager:
gcloud secrets create MY_SECRET --data-file=./secret.txt
Lalu reference di Cloud Run service.
Monitoring
Cloud Run terintegrasi dengan Cloud Monitoring dan Cloud Logging. Kita bisa:
- Lihat request latency dan error rates
- Set up alerting
- Trace requests dengan Cloud Trace
Tips
💡 Selalu set
--min-instances=1untuk production agar tidak ada cold start
Kesimpulan
Cloud Run adalah pilihan excellent untuk deploy containerized apps dengan minimal ops overhead. Kombinasi dengan GitHub Actions membuat workflow development jadi smooth!