Spaces:
Sleeping
Sleeping
VenkateshRoshan
commited on
Commit
·
b57f58a
1
Parent(s):
2a73da8
GCP Instance action added
Browse files- .github/workflows/deploy_gcloud.yml +87 -0
- __pycache__/__init__.cpython-310.pyc +0 -0
- __pycache__/app.cpython-310.pyc +0 -0
- deploy_gcloud.sh +104 -0
- gcloud_notes.txt +7 -0
- gcp_instance_startup_script.sh +26 -0
.github/workflows/deploy_gcloud.yml
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Deploy to Google Cloud
|
2 |
+
|
3 |
+
on:
|
4 |
+
push:
|
5 |
+
branches: [ main ]
|
6 |
+
pull_request:
|
7 |
+
branches: [ main ]
|
8 |
+
|
9 |
+
env:
|
10 |
+
PROJECT_ID: mlops-cs4
|
11 |
+
GCE_INSTANCE: mlops-cs4
|
12 |
+
GCE_ZONE: us-central1-a
|
13 |
+
|
14 |
+
jobs:
|
15 |
+
deploy:
|
16 |
+
runs-on: ubuntu-latest
|
17 |
+
|
18 |
+
steps:
|
19 |
+
- uses: actions/checkout@v2
|
20 |
+
|
21 |
+
# Authenticate to Google Cloud
|
22 |
+
- id: 'auth'
|
23 |
+
uses: 'google-github-actions/auth@v1'
|
24 |
+
with:
|
25 |
+
credentials_json: '${{ secrets.GCP_SA_KEY }}'
|
26 |
+
|
27 |
+
# Setup gcloud CLI
|
28 |
+
- name: Set up Cloud SDK
|
29 |
+
uses: google-github-actions/setup-gcloud@v1
|
30 |
+
with:
|
31 |
+
project_id: ${{ env.PROJECT_ID }}
|
32 |
+
|
33 |
+
# Enable required APIs
|
34 |
+
- name: Enable APIs
|
35 |
+
run: |
|
36 |
+
gcloud services enable compute.googleapis.com
|
37 |
+
|
38 |
+
# Create or update compute instance
|
39 |
+
- name: Deploy compute instance
|
40 |
+
run: |
|
41 |
+
if ! gcloud compute instances describe ${{ env.GCE_INSTANCE }} --zone=${{ env.GCE_ZONE }}; then
|
42 |
+
gcloud compute instances create ${{ env.GCE_INSTANCE }} \
|
43 |
+
--image-family=ubuntu-2004-lts \
|
44 |
+
--image-project=ubuntu-os-cloud \
|
45 |
+
--machine-type=e2-medium \
|
46 |
+
--zone=${{ env.GCE_ZONE }} \
|
47 |
+
--boot-disk-size=30GB \
|
48 |
+
--tags=http-server \
|
49 |
+
--metadata-from-file=startup-script=gcp_instance_startup_script.sh
|
50 |
+
fi
|
51 |
+
|
52 |
+
# Create firewall rule if it doesn't exist
|
53 |
+
- name: Setup firewall rule
|
54 |
+
run: |
|
55 |
+
if ! gcloud compute firewall-rules describe allow-ports; then
|
56 |
+
gcloud compute firewall-rules create allow-ports \
|
57 |
+
--direction=INGRESS \
|
58 |
+
--priority=1000 \
|
59 |
+
--network=default \
|
60 |
+
--action=ALLOW \
|
61 |
+
--rules=tcp:7860,tcp:8000,tcp:9100 \
|
62 |
+
--source-ranges=0.0.0.0/0 \
|
63 |
+
--target-tags=http-server
|
64 |
+
fi
|
65 |
+
|
66 |
+
# Wait for instance to be ready
|
67 |
+
- name: Wait for instance
|
68 |
+
run: sleep 180
|
69 |
+
|
70 |
+
# Pull and run Docker container
|
71 |
+
- name: Deploy container
|
72 |
+
run: |
|
73 |
+
gcloud compute ssh ${{ env.GCE_INSTANCE }} --zone=${{ env.GCE_ZONE }} --command="sudo docker pull venkateshroshan/mlops-cs4:latest && sudo docker run -d -p 7860:7860 -p 8000:8000 -p 9100:9100 venkateshroshan/mlops-cs4:latest"
|
74 |
+
|
75 |
+
# Get instance IP
|
76 |
+
- name: Get instance IP
|
77 |
+
run: |
|
78 |
+
echo "EXTERNAL_IP=$(gcloud compute instances describe ${{ env.GCE_INSTANCE }} --zone=${{ env.GCE_ZONE }} --format='get(networkInterfaces[0].accessConfigs[0].natIP)')" >> $GITHUB_ENV
|
79 |
+
|
80 |
+
# Output deployment information
|
81 |
+
- name: Deployment Info
|
82 |
+
run: |
|
83 |
+
echo "Deployment complete!"
|
84 |
+
echo "Your application is accessible at:"
|
85 |
+
echo "http://${{ env.EXTERNAL_IP }}:7860"
|
86 |
+
echo "http://${{ env.EXTERNAL_IP }}:8000"
|
87 |
+
echo "http://${{ env.EXTERNAL_IP }}:9100"
|
__pycache__/__init__.cpython-310.pyc
DELETED
Binary file (155 Bytes)
|
|
__pycache__/app.cpython-310.pyc
DELETED
Binary file (2.1 kB)
|
|
deploy_gcloud.sh
ADDED
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
|
3 |
+
# 1. Login to gcloud (this will open a browser window)
|
4 |
+
echo "Logging in to Google Cloud..."
|
5 |
+
gcloud auth login
|
6 |
+
|
7 |
+
# 2. Set project
|
8 |
+
echo "Setting project to mlops-cs4..."
|
9 |
+
gcloud config set project mlops-cs4
|
10 |
+
|
11 |
+
# 3. Enable required APIs
|
12 |
+
echo "Enabling required APIs..."
|
13 |
+
gcloud services enable compute.googleapis.com
|
14 |
+
|
15 |
+
# 4. Create compute instance
|
16 |
+
echo "Creating compute instance..."
|
17 |
+
gcloud compute instances create mlops-cs4 \
|
18 |
+
--image-family=ubuntu-2004-lts \
|
19 |
+
--image-project=ubuntu-os-cloud \
|
20 |
+
--machine-type=e2-medium \
|
21 |
+
--zone=us-central1-a \
|
22 |
+
--boot-disk-size=30GB \
|
23 |
+
--tags=http-server \
|
24 |
+
--metadata=startup-script='#!/bin/bash
|
25 |
+
apt-get update
|
26 |
+
apt-get install -y apt-transport-https ca-certificates curl software-properties-common
|
27 |
+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
|
28 |
+
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
|
29 |
+
apt-get update
|
30 |
+
apt-get install -y docker-ce
|
31 |
+
# Install prerequisites
|
32 |
+
apt-get install -y \
|
33 |
+
apt-transport-https \
|
34 |
+
ca-certificates \
|
35 |
+
curl \
|
36 |
+
gnupg \
|
37 |
+
lsb-release
|
38 |
+
|
39 |
+
# Add Docker official GPG key
|
40 |
+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
|
41 |
+
|
42 |
+
# Add Docker repository
|
43 |
+
echo \
|
44 |
+
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
|
45 |
+
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
|
46 |
+
|
47 |
+
# Update apt and install Docker
|
48 |
+
apt-get update
|
49 |
+
apt-get install -y docker-ce docker-ce-cli containerd.io
|
50 |
+
|
51 |
+
# Add current user to docker group
|
52 |
+
usermod -aG docker ubuntu
|
53 |
+
|
54 |
+
# Verify Docker is running
|
55 |
+
systemctl status docker
|
56 |
+
|
57 |
+
apt-get update
|
58 |
+
apt-get install -y docker.io
|
59 |
+
systemctl start docker
|
60 |
+
systemctl enable docker
|
61 |
+
# Add the default user to docker group
|
62 |
+
usermod -aG docker venkateshroshan95
|
63 |
+
# Create the docker group if it doesnt exist
|
64 |
+
groupadd -f docker
|
65 |
+
# Set proper permissions for Docker socket
|
66 |
+
chmod 666 /var/run/docker.sock'
|
67 |
+
|
68 |
+
|
69 |
+
# 5. Create firewall rule
|
70 |
+
echo "Creating firewall rule..."
|
71 |
+
|
72 |
+
gcloud compute firewall-rules create allow-ports \
|
73 |
+
--direction=INGRESS \
|
74 |
+
--priority=1000 \
|
75 |
+
--network=default \
|
76 |
+
--action=ALLOW \
|
77 |
+
--rules=tcp:7860,tcp:8000,tcp:9100 \
|
78 |
+
--source-ranges=0.0.0.0/0 \
|
79 |
+
--target-tags=http-server
|
80 |
+
|
81 |
+
# Wait for instance to be ready and Docker to be installed
|
82 |
+
echo "Waiting for instance to be ready..."
|
83 |
+
sleep 180
|
84 |
+
|
85 |
+
# Get the external IP
|
86 |
+
EXTERNAL_IP=$(gcloud compute instances describe mlops-cs4 --zone=us-central1-a \
|
87 |
+
--format='get(networkInterfaces[0].accessConfigs[0].natIP)')
|
88 |
+
|
89 |
+
# 7. Pull Docker image
|
90 |
+
echo "Pulling Docker image..."
|
91 |
+
gcloud compute ssh mlops-cs4 --zone=us-central1-a --command="docker pull venkateshroshan/mlops-cs4:latest"
|
92 |
+
|
93 |
+
# 8. Run Docker container
|
94 |
+
echo "Running Docker container..."
|
95 |
+
gcloud compute ssh mlops-cs4 --zone=us-central1-a --command="docker run -d -p 7860:7860 -p 8000:8000 -p 9100:9100 venkateshroshan/mlops-cs4:latest"
|
96 |
+
|
97 |
+
# 9 & 10. Get and print external IP
|
98 |
+
echo "External IP address: $EXTERNAL_IP"
|
99 |
+
|
100 |
+
echo "Deployment complete!"
|
101 |
+
echo "Your application is accessible at:"
|
102 |
+
echo "http://$EXTERNAL_IP:7860"
|
103 |
+
echo "http://$EXTERNAL_IP:8000"
|
104 |
+
echo "http://$EXTERNAL_IP:9100"
|
gcloud_notes.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
1 . sudo apt-get update && sudo apt-get install google-cloud-sdk
|
2 |
+
2 . gcloud init
|
3 |
+
-> it will open the browser
|
4 |
+
-> choose the account
|
5 |
+
-> give access
|
6 |
+
-> then it will ask for project to choose
|
7 |
+
3 .
|
gcp_instance_startup_script.sh
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
apt-get update
|
3 |
+
apt-get install -y apt-transport-https ca-certificates curl software-properties-common
|
4 |
+
|
5 |
+
# Add Docker official GPG key
|
6 |
+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
|
7 |
+
|
8 |
+
# Add Docker repository
|
9 |
+
echo \
|
10 |
+
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
|
11 |
+
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
|
12 |
+
|
13 |
+
# Update apt and install Docker
|
14 |
+
apt-get update
|
15 |
+
apt-get install -y docker-ce docker-ce-cli containerd.io
|
16 |
+
|
17 |
+
# Start and enable Docker
|
18 |
+
systemctl start docker
|
19 |
+
systemctl enable docker
|
20 |
+
|
21 |
+
# Create docker group and add user
|
22 |
+
groupadd -f docker
|
23 |
+
usermod -aG docker ubuntu
|
24 |
+
|
25 |
+
# Set proper permissions for Docker socket
|
26 |
+
chmod 666 /var/run/docker.sock
|