update ssh after deploy command #7
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
name: π Deploy website on push | |
on: | |
push: | |
branches: | |
- main # Change this to your default branch if different | |
jobs: | |
web-deploy: | |
name: π Deploy | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Checkout the latest code | |
- name: π Get latest code | |
uses: actions/checkout@v4 | |
# Step 2: Install Node.js 20 (updated to the latest version) | |
- name: Use Node.js 20 | |
uses: actions/setup-node@v3 | |
with: | |
node-version: "20" | |
# Step 3: Sync files to the server via FTP (Upload all files to /home/tbtouris/api) | |
- name: π Sync files | |
uses: SamKirkland/FTP-Deploy-Action@v4.3.5 | |
with: | |
server: ${{ vars.FTP_SERVER }} # Add this secret in your GitHub repository settings | |
username: ${{ vars.FTP_USERNAME }} # Add this secret | |
password: ${{ vars.FTP_PASSWORD }} # Add this secret | |
local-dir: ./ # All root files will be uploaded | |
server-dir: /home/tbtouris/api/ # Server directory path | |
protocol: ftps # Use ftps for a secure connection | |
exclude: | # Exclude unnecessary files | |
**/.git* | |
**/.git*/** | |
**/node_modules/** | |
**/frontend/node_modules/** | |
**/backend/node_modules/** | |
# Step 4: Install dependencies and build the project on the server using a custom SSH port | |
- name: π§ Install and Build on Server | |
run: | | |
sshpass -p "${{ vars.SSH_PASSWORD }}" ssh -o StrictHostKeyChecking=no -T -p ${{ vars.SSH_PORT }} ${{ vars.SSH_USER }}@${{ vars.SSH_HOST }} << 'EOF' | |
cd /home/tbtouris/api | |
npm install | |
npm run build | |
EOF | |
env: | |
SSH_PASSWORD: ${{ vars.SSH_PASSWORD }} | |
SSH_USER: ${{ vars.SSH_USER }} | |
SSH_HOST: ${{ vars.SSH_HOST }} | |
SSH_PORT: ${{ vars.SSH_PORT }} |