forked from fga-eps-mds/2024.1-CALCULUS-StudioMaker
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from fga-eps-mds/108-deploy-service
LGTM
- Loading branch information
Showing
3 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Deploy Studio Maker in Azure | ||
|
||
# Dispara o workflow para push e pull request na branch 'dev' | ||
on: | ||
push: | ||
branches: | ||
- dev | ||
|
||
|
||
|
||
|
||
jobs: | ||
run-script: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: executing remote ssh commands using password | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ secrets.IP_VM_AZURE_DEV }} | ||
username: ${{ secrets.USER_VM_AZURE_DEV }} | ||
password: ${{ secrets.USER_VM_AZURE_DEV }} | ||
port: 22 | ||
request_pty: true | ||
script: | | ||
ls -alt | ||
cd /home/Calculus-admin1/app | ||
pwd | ||
sudo ./manage_process_back_studio.sh | ||
echo "Starting deploy Studio Service" | ||
sudo ./deploy_back_studio.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/bin/bash | ||
|
||
SESSION_NAME="backend-user-session" | ||
ENV="dev" | ||
DIR1="/home/Calculus-admin1/app/2024.1-CALCULUS-StudioMaker" | ||
|
||
# Comandos renomeados para refletir a ordem de execução | ||
CMD1="git fetch" | ||
CMD2="git checkout $ENV" | ||
CMD3="git pull origin $ENV" | ||
CMD4="npm install" | ||
CMD5="npm run start" | ||
CMD6="echo Starting Deploy Studio Maker backend" | ||
|
||
# Função para iniciar a sessão tmux e executar comandos | ||
start_tmux_session() { | ||
# Criar uma nova sessão tmux | ||
tmux kill-session -t $SESSION_NAME 2>/dev/null | ||
tmux new-session -d -s $SESSION_NAME | ||
|
||
# Executar os comandos na pasta do frontend | ||
tmux send-keys -t $SESSION_NAME "cd $DIR1" C-m | ||
tmux send-keys -t $SESSION_NAME "$CMD1" C-m | ||
tmux send-keys -t $SESSION_NAME "$CMD2" C-m | ||
tmux send-keys -t $SESSION_NAME "$CMD3" C-m | ||
tmux send-keys -t $SESSION_NAME "$CMD4" C-m | ||
tmux send-keys -t $SESSION_NAME "$CMD5" C-m | ||
tmux send-keys -t $SESSION_NAME "$CMD6" C-m | ||
|
||
# Anexar à sessão tmux para visualizar os comandos em execução | ||
# tmux attach-session -t $SESSION_NAME | ||
} | ||
|
||
# Função para executar o health check | ||
run_healthcheck() { | ||
PORT=3002 | ||
CHECK_INTERVAL=5 | ||
|
||
echo "Deploy backend iniciado" | ||
echo "Iniciando health check para a porta $PORT..." | ||
|
||
while true; do | ||
# Executa o comando para verificar se a porta está em uso | ||
OUTPUT=$(ss -tuln | grep ":$PORT") | ||
|
||
# Verifica se há algum resultado | ||
if [ -n "$OUTPUT" ]; then | ||
echo "A porta $PORT está em uso. Encerrando o health check." | ||
echo "Deploy realizado com sucesso!" | ||
break | ||
else | ||
echo "A porta $PORT não está em uso. Verificando novamente em $CHECK_INTERVAL segundos..." | ||
sleep $CHECK_INTERVAL | ||
fi | ||
done | ||
} | ||
|
||
# Iniciar a sessão tmux e executar os comandos | ||
start_tmux_session | ||
|
||
# Após a execução do tmux, iniciar o health check | ||
run_healthcheck |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
|
||
# Portas que precisam ser verificadas | ||
PORT1=3002 | ||
|
||
# Função para encerrar processos que estão usando a porta | ||
kill_process_on_port() { | ||
local PORT=$1 | ||
PID=$(lsof -t -i:$PORT) | ||
if [ -n "$PID" ]; then | ||
echo "Terminating process on port $PORT (PID: $PID)" | ||
sudo kill -9 $PID | ||
else | ||
echo "No process running on port $PORT" | ||
fi | ||
} | ||
|
||
|
||
# Encerrar processos nas portas especificadas | ||
kill_process_on_port $PORT1 | ||
|
||
# Encerrar processos relacionados ao `nest` | ||
echo "Terminating all processes for 'nest'" | ||
#sudo pkill nest |