forked from sammajayi/byro
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudbuild.yaml
More file actions
49 lines (41 loc) · 1.53 KB
/
cloudbuild.yaml
File metadata and controls
49 lines (41 loc) · 1.53 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
steps:
- name: 'python:3.11'
dir: 'Backend'
entrypoint: 'pip'
args: ['install', '-r', 'requirements.txt']
id: 'install-deps'
# Deploy to Compute Engine
- name: 'gcr.io/cloud-builders/gcloud'
entrypoint: 'bash'
args:
- '-c'
- |
# Copy Backend directory to server
gcloud compute scp --recurse --zone=us-central1-a Backend/ web-server:/tmp/app/
# Deploy on the server
gcloud compute ssh web-server --zone=us-central1-a --command="
# Stop existing application
sudo pkill -f gunicorn || true
sudo pkill -f python || true
# Move new code
sudo rm -rf /var/www/app || true
sudo mv /tmp/app /var/www/app
sudo chown -R www-data:www-data /var/www/app
# Install dependencies and setup
cd /var/www/app
sudo pip3 install -r requirements.txt
# Set environment variables for production
export GOOGLE_CLOUD_PROJECT=final-project-472521
export DJANGO_SETTINGS_MODULE=api.settings
# Run Django commands
sudo -E python3 manage.py collectstatic --noinput || true
sudo -E python3 manage.py migrate || true
# Start the application with correct wsgi path
cd /var/www/app
sudo -E python3 -m gunicorn --bind 0.0.0.0:8000 --daemon api.wsgi:application
"
id: 'deploy'
waitFor: ['install-deps']
timeout: 1200s
options:
logging: CLOUD_LOGGING_ONLY