-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.ps1
More file actions
112 lines (91 loc) · 3.5 KB
/
deploy.ps1
File metadata and controls
112 lines (91 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Cloud Run Deployment Script for Finance Dashboard (Windows)
# Usage: .\deploy.ps1 -ProjectId "my-project" -ServiceName "finance-dashboard" -Region "us-central1"
param(
[Parameter(Mandatory=$true)]
[string]$ProjectId,
[Parameter(Mandatory=$false)]
[string]$ServiceName = "finance-dashboard",
[Parameter(Mandatory=$false)]
[string]$Region = "us-central1"
)
# Color output functions
function Write-Status {
Write-Host "[✓] $args" -ForegroundColor Green
}
function Write-Error-Custom {
Write-Host "[✗] $args" -ForegroundColor Red
exit 1
}
function Write-Warning-Custom {
Write-Host "[!] $args" -ForegroundColor Yellow
}
Write-Host ""
Write-Host "Finance Dashboard Cloud Run Deployment" -ForegroundColor Cyan
Write-Host "Project: $ProjectId" -ForegroundColor Gray
Write-Host "Service: $ServiceName" -ForegroundColor Gray
Write-Host "Region: $Region" -ForegroundColor Gray
Write-Host ""
# Step 1: Check prerequisites
Write-Status "Checking prerequisites..."
$hasGcloud = Get-Command gcloud -ErrorAction SilentlyContinue
if (-not $hasGcloud) {
Write-Error-Custom "gcloud CLI not found. Install from: https://cloud.google.com/sdk/docs/install"
}
$hasDocker = Get-Command docker -ErrorAction SilentlyContinue
if (-not $hasDocker) {
Write-Error-Custom "Docker not found. Install from: https://docs.docker.com/get-docker/"
}
Write-Status "Prerequisites OK"
# Step 2: Set GCP project
Write-Status "Setting GCP project to $ProjectId..."
& gcloud config set project $ProjectId
if ($LASTEXITCODE -ne 0) {
Write-Error-Custom "Failed to set GCP project"
}
# Step 3: Enable required APIs
Write-Status "Enabling required GCP APIs..."
& gcloud services enable run.googleapis.com 2>$null
& gcloud services enable cloudbuild.googleapis.com 2>$null
& gcloud services enable containerregistry.googleapis.com 2>$null
Write-Status "APIs enabled"
# Step 4: Build Docker image
Write-Status "Building Docker image..."
& gcloud builds submit `
--tag gcr.io/$ProjectId/$ServiceName:latest `
--region=$Region `
--timeout=1800s
if ($LASTEXITCODE -ne 0) {
Write-Error-Custom "Docker build failed"
}
Write-Status "Docker image built and pushed"
# Step 5: Deploy to Cloud Run
Write-Status "Deploying to Cloud Run..."
& gcloud run deploy $ServiceName `
--image gcr.io/$ProjectId/$ServiceName:latest `
--platform managed `
--region $Region `
--allow-unauthenticated `
--memory 512Mi `
--cpu 1 `
--timeout 120 `
--max-instances 100 `
--set-env-vars CLOUD_RUN=true,ENVIRONMENT=production,DEBUG=false
if ($LASTEXITCODE -ne 0) {
Write-Error-Custom "Cloud Run deployment failed"
}
Write-Status "Deployment complete!"
# Step 6: Get service URL
$ServiceUrl = & gcloud run services describe $ServiceName `
--platform managed `
--region $Region `
--format 'value(status.url)'
Write-Status "Service URL: $ServiceUrl"
Write-Host ""
Write-Host "Next steps:" -ForegroundColor Cyan
Write-Host "1. Update .env.production with CLOUD_RUN_SERVICE_URL=$ServiceUrl"
Write-Host "2. Run database migrations:"
Write-Host " gcloud run jobs create migrate-db --image gcr.io/$ProjectId/$ServiceName:latest --region $Region --execute -- python manage.py migrate"
Write-Host "3. View logs:"
Write-Host " gcloud run logs read $ServiceName --platform managed --region $Region --follow"
Write-Host "4. Test API with:"
Write-Host " curl -X POST ""$ServiceUrl/api/authentication/"" -H 'Content-Type: application/json' -d '{""email"": ""demo.admin@gmail.com"", ""password"": ""demo@admin2026""}'`n"