This repository was archived by the owner on Feb 5, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-completo.sh
More file actions
151 lines (125 loc) · 3.91 KB
/
deploy-completo.sh
File metadata and controls
151 lines (125 loc) · 3.91 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/bash
# 🚀 Script de Deploy Completo para Produção
# Este script configura e executa o sistema completo
set -e # Parar em caso de erro
echo "🚀 Iniciando deploy completo para produção..."
echo "================================================"
# Cores para output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Função para log colorido
log_info() {
echo -e "${BLUE}ℹ️ $1${NC}"
}
log_success() {
echo -e "${GREEN}✅ $1${NC}"
}
log_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
log_error() {
echo -e "${RED}❌ $1${NC}"
}
# 1. Verificar pré-requisitos
log_info "Verificando pré-requisitos..."
# Verificar se Go está instalado
if ! command -v go &> /dev/null; then
log_error "Go não está instalado!"
exit 1
fi
# Verificar se Node.js está instalado
if ! command -v node &> /dev/null; then
log_error "Node.js não está instalado!"
exit 1
fi
# Verificar se npm está instalado
if ! command -v npm &> /dev/null; then
log_error "npm não está instalado!"
exit 1
fi
log_success "Pré-requisitos verificados"
# 2. Verificar arquivo de credenciais
log_info "Verificando credenciais do Google Cloud..."
if [ -z "$GOOGLE_APPLICATION_CREDENTIALS" ]; then
log_warning "Variável GOOGLE_APPLICATION_CREDENTIALS não configurada"
log_info "Verificando arquivo .env..."
if [ -f ".env" ]; then
source .env
if [ -z "$GOOGLE_APPLICATION_CREDENTIALS" ]; then
log_error "GOOGLE_APPLICATION_CREDENTIALS não encontrada no .env"
log_info "Configure o arquivo .env com suas credenciais"
exit 1
fi
else
log_error "Arquivo .env não encontrado!"
log_info "Execute: cp env.production .env e configure as credenciais"
exit 1
fi
fi
if [ ! -f "$GOOGLE_APPLICATION_CREDENTIALS" ]; then
log_error "Arquivo de credenciais não encontrado: $GOOGLE_APPLICATION_CREDENTIALS"
log_info "Baixe as credenciais do Google Cloud Console"
exit 1
fi
log_success "Credenciais verificadas"
# 3. Instalar dependências do frontend
log_info "Instalando dependências do frontend..."
npm install --legacy-peer-deps
if [ $? -eq 0 ]; then
log_success "Dependências do frontend instaladas"
else
log_error "Erro ao instalar dependências do frontend"
exit 1
fi
# 4. Build do frontend
log_info "Fazendo build do frontend..."
npm run build
if [ $? -eq 0 ]; then
log_success "Build do frontend concluído"
else
log_error "Erro no build do frontend"
exit 1
fi
# 5. Build do backend
log_info "Fazendo build do backend..."
go build -o main main.go
if [ $? -eq 0 ]; then
log_success "Build do backend concluído"
else
log_error "Erro no build do backend"
exit 1
fi
# 6. Configurar modo de produção
export GIN_MODE=release
log_info "Modo de produção configurado"
# 7. Verificar se a porta está livre
log_info "Verificando disponibilidade da porta 8080..."
if lsof -Pi :8080 -sTCP:LISTEN -t >/dev/null ; then
log_warning "Porta 8080 já está em uso"
read -p "Deseja parar o processo na porta 8080? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
sudo lsof -ti:8080 | xargs kill -9
log_success "Processo na porta 8080 parado"
else
log_error "Porta 8080 ocupada. Configure outra porta ou pare o processo"
exit 1
fi
fi
# 8. Iniciar servidor
log_info "Iniciando servidor em modo produção..."
echo "================================================"
echo "🌐 Servidor rodando em: http://localhost:8080"
echo "🔗 Health check: http://localhost:8080/health"
echo "🗺️ Geocoding API: http://localhost:8080/api/geocoding?address=endereco"
echo "📊 Para parar o servidor, pressione Ctrl+C"
echo "================================================"
# Exportar variáveis do .env para o ambiente
if [ -f ".env" ]; then
export $(grep -v '^#' .env | xargs)
fi
# Executar servidor
./main