Update ci_app_node.yml #3
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
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node | |
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs | |
name: MS-CLIENTES-DEV CI | |
env: | |
SSH_PRIVATE_KEY: ${{ secrets.PEM_MS_CLIENTES_DEV }} | |
REMOTE_USER: ec2-user | |
REMOTE_HOST: ${{ secrets.IP_CLIENTES_DEV }} | |
APP_NAME: app.js | |
on: | |
push: | |
branches: [ "romina-clientes" ] | |
jobs: | |
ci-clientes-dev: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout código fuente | |
uses: actions/checkout@v3 | |
- name: Instalar paquetes nodejs npm git | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ env.REMOTE_HOST }} | |
username: ${{ env.REMOTE_USER }} | |
key: ${{ env.SSH_PRIVATE_KEY }} | |
script: | | |
if ! command -v nodejs &> /dev/null; then | |
sudo yum install -y nodejs | |
else | |
echo "Node.js is installed." | |
fi | |
if ! command -v npm &> /dev/null; then | |
sudo yum install -y npm | |
else | |
echo "npm is installed." | |
fi | |
if ! command -v git &> /dev/null; then | |
sudo yum install -y git | |
else | |
echo "Git is installed." | |
fi | |
- name: Crear directorio | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ env.REMOTE_HOST }} | |
username: ${{ env.REMOTE_USER }} | |
key: ${{ env.SSH_PRIVATE_KEY }} | |
script: | | |
sudo rm -rf /opt/ms-clientes-dev-app | |
sudo mkdir /opt/ms-clientes-dev-app | |
- name: Clonar repositorio | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ env.REMOTE_HOST }} | |
username: ${{ env.REMOTE_USER }} | |
key: ${{ env.SSH_PRIVATE_KEY }} | |
script: | | |
cd /opt/ms-clientes-dev-app | |
sudo git clone -b romina-clientes https://${{ secrets.TOKEN_GH_CLIENTES }}@github.com/alkemyTech/UMSA-DevOps-T3 . | |
- name: Instalar paquetes con NPM | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ env.REMOTE_HOST }} | |
username: ${{ env.REMOTE_USER }} | |
key: ${{ env.SSH_PRIVATE_KEY }} | |
script: | | |
if npm list -g -depth 0 express &> /dev/null; then | |
echo "Express is installed." | |
else | |
sudo npm install express -g | |
fi | |
if npm list -g -depth 0 pm2 ; then | |
echo "PM2 is installed." | |
else | |
sudo npm install pm2 -g | |
fi | |
- name: Iniciar aplicación Node con PM2 | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ env.REMOTE_HOST }} | |
username: ${{ env.REMOTE_USER }} | |
key: ${{ env.SSH_PRIVATE_KEY }} | |
script: | | |
cd /opt/ms-clientes-dev-app | |
pm2 start app.js | |
- name: Verificar estado de la aplicación | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ env.REMOTE_HOST }} | |
username: ${{ env.REMOTE_USER }} | |
key: ${{ env.SSH_PRIVATE_KEY }} | |
script: | | |
cd /opt/ms-clientes-dev-app | |
if curl http://localhost:3000 ; then | |
echo "App is running." | |
else | |
echo "App is not running." | |
exit 1 | |
fi |