Skip to content

Commit 6591a67

Browse files
committed
feat: sh local install
1 parent 1665654 commit 6591a67

File tree

2 files changed

+151
-0
lines changed

2 files changed

+151
-0
lines changed

local_install.sh

+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
#!/bin/bash
2+
3+
# Definir cores para melhor legibilidade
4+
RED='\033[0;31m'
5+
GREEN='\033[0;32m'
6+
YELLOW='\033[1;33m'
7+
NC='\033[0m' # No Color
8+
9+
# Função para log
10+
log() {
11+
echo -e "${GREEN}[INFO]${NC} $1"
12+
}
13+
log_error() {
14+
echo -e "${RED}[ERROR]${NC} $1"
15+
}
16+
log_warning() {
17+
echo -e "${YELLOW}[WARNING]${NC} $1"
18+
}
19+
20+
# Verificar se está rodando como root
21+
if [ "$(id -u)" = "0" ]; then
22+
log_error "Este script não deve ser executado como root"
23+
exit 1
24+
fi
25+
26+
# Verificar sistema operacional
27+
OS="$(uname -s)"
28+
case "${OS}" in
29+
Linux*)
30+
if [ ! -x "$(command -v curl)" ]; then
31+
log_warning "Curl não está instalado. Tentando instalar..."
32+
if [ -x "$(command -v apt-get)" ]; then
33+
sudo apt-get update && sudo apt-get install -y curl
34+
elif [ -x "$(command -v yum)" ]; then
35+
sudo yum install -y curl
36+
else
37+
log_error "Não foi possível instalar curl automaticamente. Por favor, instale manualmente."
38+
exit 1
39+
fi
40+
fi
41+
;;
42+
Darwin*)
43+
if [ ! -x "$(command -v curl)" ]; then
44+
log_error "Curl não está instalado. Por favor, instale o Xcode Command Line Tools."
45+
exit 1
46+
fi
47+
;;
48+
*)
49+
log_error "Sistema operacional não suportado: ${OS}"
50+
exit 1
51+
;;
52+
esac
53+
54+
# Verificar conexão com a internet antes de prosseguir
55+
if ! ping -c 1 8.8.8.8 &> /dev/null; then
56+
log_error "Sem conexão com a internet. Por favor, verifique sua conexão."
57+
exit 1
58+
fi
59+
60+
# Adicionar verificação de espaço em disco
61+
REQUIRED_SPACE=1000000 # 1GB em KB
62+
AVAILABLE_SPACE=$(df -k . | awk 'NR==2 {print $4}')
63+
if [ $AVAILABLE_SPACE -lt $REQUIRED_SPACE ]; then
64+
log_error "Espaço em disco insuficiente. Necessário pelo menos 1GB livre."
65+
exit 1
66+
fi
67+
68+
# Adicionar tratamento de erro para comandos npm
69+
npm_install_with_retry() {
70+
local max_attempts=3
71+
local attempt=1
72+
73+
while [ $attempt -le $max_attempts ]; do
74+
log "Tentativa $attempt de $max_attempts para npm install"
75+
if npm install; then
76+
return 0
77+
fi
78+
attempt=$((attempt + 1))
79+
[ $attempt -le $max_attempts ] && log_warning "Falha na instalação. Tentando novamente em 5 segundos..." && sleep 5
80+
done
81+
82+
log_error "Falha ao executar npm install após $max_attempts tentativas"
83+
return 1
84+
}
85+
86+
# Adicionar timeout para comandos
87+
execute_with_timeout() {
88+
timeout 300 $@ || log_error "Comando excedeu o tempo limite de 5 minutos: $@"
89+
}
90+
91+
# Verificar se o NVM já está instalado
92+
if [ -d "$HOME/.nvm" ]; then
93+
log "NVM já está instalado."
94+
else
95+
log "Instalando NVM..."
96+
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
97+
fi
98+
99+
# Carregar o NVM no ambiente atual
100+
export NVM_DIR="$HOME/.nvm"
101+
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
102+
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
103+
104+
# Verificar se a versão do Node.js já está instalada
105+
if command -v node >/dev/null 2>&1 && [ "$(node -v)" = "v20.10.0" ]; then
106+
log "Node.js v20.10.0 já está instalado."
107+
else
108+
log "Instalando Node.js v20.10.0..."
109+
nvm install v20.10.0
110+
fi
111+
112+
nvm use v20.10.0
113+
114+
# Verificar as versões instaladas
115+
log "Verificando as versões instaladas:"
116+
log "Node.js: $(node -v)"
117+
log "npm: $(npm -v)"
118+
119+
# Instala dependências do projeto
120+
log "Instalando dependências do projeto..."
121+
rm -rf node_modules
122+
npm install
123+
124+
# Deploy do banco de dados
125+
log "Deploy do banco de dados..."
126+
npm run db:generate
127+
npm run db:deploy
128+
129+
# Iniciar o projeto
130+
log "Iniciando o projeto..."
131+
if [ "$1" = "-dev" ]; then
132+
npm run dev:server
133+
else
134+
npm run build
135+
npm run start:prod
136+
fi
137+
138+
log "Instalação concluída com sucesso!"
139+
140+
# Criar arquivo de log
141+
LOGFILE="./installation_log_$(date +%Y%m%d_%H%M%S).log"
142+
exec 1> >(tee -a "$LOGFILE")
143+
exec 2>&1
144+
145+
# Adicionar trap para limpeza em caso de interrupção
146+
cleanup() {
147+
log "Limpando recursos temporários..."
148+
# Adicione comandos de limpeza aqui
149+
}
150+
trap cleanup EXIT

src/api/routes/instance.router.ts

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export class InstanceRouter extends RouterBroker {
1212
super();
1313
this.router
1414
.post('/create', ...guards, async (req, res) => {
15+
console.log('create instance', req.body);
1516
const response = await this.dataValidate<InstanceDto>({
1617
request: req,
1718
schema: instanceSchema,

0 commit comments

Comments
 (0)