Skip to content

Merge pull request #57 from danial117/server_dev_39 #82

Merge pull request #57 from danial117/server_dev_39

Merge pull request #57 from danial117/server_dev_39 #82

Workflow file for this run

name: SSH Server Deployment
on:
push:
branches:
- server
jobs:
ssh-folder-management:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up SSH client
run: |
sudo apt-get update
sudo apt-get install -y sshpass
- name: Connect to SSH and perform operations
env:
SERVER_IP: ${{ secrets.SERVER_IP }}
SERVER_USER: ${{ secrets.SERVER_USER }}
SERVER_PASSWORD: ${{ secrets.SERVER_PASSWORD }}
run: |
sshpass -p "$SERVER_PASSWORD" ssh -o StrictHostKeyChecking=no "$SERVER_USER@$SERVER_IP" << 'EOF'
# Navigate to the target directory
cd /home/infovit-api/htdocs/api.infovit.us
# Delete all files and directories except 'ecosystem.config.cjs' and 'public'
find . -mindepth 1 -maxdepth 1 ! -name 'ecosystem.config.cjs' ! -name 'public' ! -name '.env' -exec rm -rf {} +
# Clone the specific branch of the GitHub repository into a temporary directory
git clone -b server https://github.com/danial117/Pharma.git ./git
# Move the contents of the temporary directory to the target directory
mv ./git/* ./
mv ./git/.[!.]* ./ # Move hidden files
# Clean up by removing the temporary directory
rm -rf ./git
rm -rf ./.git
rm -rf ./.github
# Install dependencies
npm install
# Start the application with pm2
pm2 delete all
pm2 start ecosystem.config.cjs --env production
# Create the 'public' directory with 'brands', 'products', and 'news' subdirectories
mkdir -p /home/infovit-api/htdocs/api.infovit.us/public/brands
mkdir -p /home/infovit-api/htdocs/api.infovit.us/public/products
mkdir -p /home/infovit-api/htdocs/api.infovit.us/public/products/large
mkdir -p /home/infovit-api/htdocs/api.infovit.us/public/products/medium
mkdir -p /home/infovit-api/htdocs/api.infovit.us/public/products/small
mkdir -p /home/infovit-api/htdocs/api.infovit.us/public/news
EOF