Organizar archivos de deployment en carpeta deploy/
This commit is contained in:
61
deploy/gcloud/create-vm.sh
Normal file
61
deploy/gcloud/create-vm.sh
Normal file
@@ -0,0 +1,61 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script para crear la VM en Google Cloud
|
||||
# Ejecutar este script desde tu máquina local con gcloud CLI instalado
|
||||
|
||||
PROJECT_ID="tu-proyecto-gcloud" # Cambiar por tu project ID
|
||||
ZONE="us-central1-a"
|
||||
VM_NAME="snatchgame-vm"
|
||||
MACHINE_TYPE="e2-micro"
|
||||
IMAGE_FAMILY="ubuntu-2004-lts"
|
||||
IMAGE_PROJECT="ubuntu-os-cloud"
|
||||
|
||||
echo "Creando VM para SnatchGame en Google Cloud..."
|
||||
|
||||
# Crear la VM
|
||||
gcloud compute instances create $VM_NAME \
|
||||
--project=$PROJECT_ID \
|
||||
--zone=$ZONE \
|
||||
--machine-type=$MACHINE_TYPE \
|
||||
--network-interface=network-tier=PREMIUM,subnet=default \
|
||||
--maintenance-policy=MIGRATE \
|
||||
--provisioning-model=STANDARD \
|
||||
--service-account=default \
|
||||
--scopes=https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write,https://www.googleapis.com/auth/servicecontrol,https://www.googleapis.com/auth/service.management.readonly,https://www.googleapis.com/auth/trace.append \
|
||||
--tags=http-server,https-server \
|
||||
--create-disk=auto-delete=yes,boot=yes,device-name=$VM_NAME,image=projects/$IMAGE_PROJECT/global/images/family/$IMAGE_FAMILY,mode=rw,size=20,type=projects/$PROJECT_ID/zones/$ZONE/diskTypes/pd-standard \
|
||||
--no-shielded-secure-boot \
|
||||
--shielded-vtpm \
|
||||
--shielded-integrity-monitoring \
|
||||
--labels=environment=production,app=snatchgame \
|
||||
--reservation-affinity=any \
|
||||
--metadata-from-file startup-script=startup-script.sh
|
||||
|
||||
echo "VM creada exitosamente!"
|
||||
|
||||
# Obtener IP externa
|
||||
EXTERNAL_IP=$(gcloud compute instances describe $VM_NAME --zone=$ZONE --format='get(networkInterfaces[0].accessConfigs[0].natIP)')
|
||||
|
||||
echo ""
|
||||
echo "=================================================="
|
||||
echo "VM SnatchGame creada exitosamente!"
|
||||
echo "=================================================="
|
||||
echo "Nombre: $VM_NAME"
|
||||
echo "Zona: $ZONE"
|
||||
echo "IP Externa: $EXTERNAL_IP"
|
||||
echo "=================================================="
|
||||
echo ""
|
||||
echo "Próximos pasos:"
|
||||
echo "1. Configurar DNS en Cloudflare:"
|
||||
echo " A record: snatchgame.nucleoriofrio.com → $EXTERNAL_IP"
|
||||
echo ""
|
||||
echo "2. Esperar ~5 minutos para que el startup script termine"
|
||||
echo ""
|
||||
echo "3. Verificar que funciona:"
|
||||
echo " http://$EXTERNAL_IP"
|
||||
echo ""
|
||||
echo "4. Una vez que DNS se propague:"
|
||||
echo " http://snatchgame.nucleoriofrio.com"
|
||||
echo ""
|
||||
echo "Para monitorear el progreso del startup script:"
|
||||
echo "gcloud compute ssh $VM_NAME --zone=$ZONE --command='sudo tail -f /var/log/syslog'"
|
||||
137
deploy/gcloud/startup-script.sh
Normal file
137
deploy/gcloud/startup-script.sh
Normal file
@@ -0,0 +1,137 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Startup script para VM de Google Cloud
|
||||
# Este script se ejecuta cuando la VM inicia
|
||||
|
||||
# Update system
|
||||
apt-get update
|
||||
apt-get install -y apt-transport-https ca-certificates curl software-properties-common
|
||||
|
||||
# Install Docker
|
||||
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
|
||||
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
|
||||
apt-get update
|
||||
apt-get install -y docker-ce docker-ce-cli containerd.io
|
||||
|
||||
# Install Docker Compose
|
||||
curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
|
||||
chmod +x /usr/local/bin/docker-compose
|
||||
|
||||
# Install Nginx
|
||||
apt-get install -y nginx
|
||||
|
||||
# Create nginx config for SnatchGame
|
||||
cat > /etc/nginx/sites-available/snatchgame << 'EOF'
|
||||
server {
|
||||
listen 80;
|
||||
server_name snatchgame.nucleoriofrio.com;
|
||||
client_max_body_size 100M;
|
||||
|
||||
# Frontend (puerto 3000 del contenedor)
|
||||
location / {
|
||||
proxy_pass http://localhost:3000;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_http_version 1.1;
|
||||
}
|
||||
|
||||
# WebSocket de Colyseus
|
||||
location /ws {
|
||||
proxy_pass http://localhost:2567;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
|
||||
# Headers específicos para WebSocket
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
|
||||
# Timeouts para WebSocket
|
||||
proxy_connect_timeout 60s;
|
||||
proxy_send_timeout 60s;
|
||||
proxy_read_timeout 60s;
|
||||
}
|
||||
|
||||
# API REST general
|
||||
location /api/ {
|
||||
proxy_pass http://localhost:2567/api/;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_http_version 1.1;
|
||||
}
|
||||
|
||||
# SSE para dashboard
|
||||
location /api/dashboard-stream {
|
||||
proxy_pass http://localhost:2567/api/dashboard-stream;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
|
||||
# Headers específicos para SSE
|
||||
proxy_buffering off;
|
||||
proxy_cache off;
|
||||
proxy_read_timeout 24h;
|
||||
proxy_http_version 1.1;
|
||||
}
|
||||
|
||||
# Monitor de Colyseus (opcional)
|
||||
location /colyseus {
|
||||
proxy_pass http://localhost:2567/colyseus;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_http_version 1.1;
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
# Enable site
|
||||
ln -sf /etc/nginx/sites-available/snatchgame /etc/nginx/sites-enabled/
|
||||
rm -f /etc/nginx/sites-enabled/default
|
||||
|
||||
# Start services
|
||||
systemctl enable nginx
|
||||
systemctl start nginx
|
||||
systemctl enable docker
|
||||
systemctl start docker
|
||||
|
||||
# Create deployment script
|
||||
cat > /opt/deploy-snatchgame.sh << 'EOF'
|
||||
#!/bin/bash
|
||||
|
||||
# Script para desplegar nueva versión del juego
|
||||
echo "Deploying SnatchGame..."
|
||||
|
||||
# Parar contenedor anterior
|
||||
docker stop snatchgame 2>/dev/null || true
|
||||
docker rm snatchgame 2>/dev/null || true
|
||||
|
||||
# Obtener última imagen
|
||||
docker pull gitea.nucleoriofrio.com/nucleo000/snatchgame:latest
|
||||
|
||||
# Ejecutar nuevo contenedor
|
||||
docker run -d \
|
||||
--name snatchgame \
|
||||
--restart unless-stopped \
|
||||
-p 3000:3000 \
|
||||
-p 2567:2567 \
|
||||
gitea.nucleoriofrio.com/nucleo000/snatchgame:latest
|
||||
|
||||
echo "SnatchGame deployed successfully!"
|
||||
EOF
|
||||
|
||||
chmod +x /opt/deploy-snatchgame.sh
|
||||
|
||||
# Initial deployment
|
||||
/opt/deploy-snatchgame.sh
|
||||
|
||||
echo "VM setup completed!"
|
||||
25
deploy/gcloud/update-deployment.sh
Normal file
25
deploy/gcloud/update-deployment.sh
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script para actualizar el deployment en la VM de Google Cloud
|
||||
# Se puede ejecutar manualmente o desde CI/CD
|
||||
|
||||
PROJECT_ID="tu-proyecto-gcloud" # Cambiar por tu project ID
|
||||
ZONE="us-central1-a"
|
||||
VM_NAME="snatchgame-vm"
|
||||
|
||||
echo "Actualizando deployment en VM de Google Cloud..."
|
||||
|
||||
# Ejecutar script de deployment en la VM
|
||||
gcloud compute ssh $VM_NAME \
|
||||
--zone=$ZONE \
|
||||
--command="sudo /opt/deploy-snatchgame.sh"
|
||||
|
||||
echo "Deployment actualizado exitosamente!"
|
||||
|
||||
# Verificar que el contenedor está corriendo
|
||||
echo "Verificando estado del contenedor..."
|
||||
gcloud compute ssh $VM_NAME \
|
||||
--zone=$ZONE \
|
||||
--command="docker ps | grep snatchgame"
|
||||
|
||||
echo "¡Listo! El juego debería estar disponible en http://snatchgame.nucleoriofrio.com"
|
||||
Reference in New Issue
Block a user