Skip to content

Commit

Permalink
Merge pull request #4 from fga-eps-mds/108-deploy-service
Browse files Browse the repository at this point in the history
LGTM
  • Loading branch information
DaviMatheus authored Aug 19, 2024
2 parents 19bc9b1 + 7c4779c commit 3b97dbc
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/deploy.yml
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
62 changes: 62 additions & 0 deletions scripts/deploy_back_studio.sh
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
24 changes: 24 additions & 0 deletions scripts/manage_process_studio.sh
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

0 comments on commit 3b97dbc

Please sign in to comment.