'How to automatically install python packages when using CPanel with Continuous Deployment?

I'm trying to make a Continuous Deployment workflow using GitHub Actions to deploy on shared Hosting (CPanel).

I have setup a workflow for serving the frontend static pages through the use of the library FTP-Deploy-Action. https://github.com/SamKirkland/FTP-Deploy-Action

Now I wish to use it deploy my python backend too. I have created a python app and setup the libraries but I wish to be able to pip install any new packages I add later on.

I know there is a .cpanel.yml file that is suppose to automate Deployment but all the examples I have found consists of just copying files from one directory to another.

This is my current github actions main.yml file which is making it possible to CD my frontend files.

on:
  push:
    branches:
      - staging

name: 🚀 Deploy website on push (staging)
jobs:
  web-deploy:
    name: 🎉 Deploy
    runs-on: ubuntu-latest
    steps:
    - name: 🚚 Get latest code
      uses: actions/checkout@v2

    - name: 🔨 Build Project
      run: |
        npm install
        npm run build
    
    - name: 📂 Sync files (Frontend)
      uses: SamKirkland/[email protected]
      with:
        server: ${{ secrets.ftp_username }}
        username: ${{ secrets.ftp_username }}
        password: ${{ secrets.ftp_password }}
        server-dir: /public_http/
        exclude: |
          **/.git*
          **/.git*/**
          **/node_modules/**
          **/env/**
          **/mywebsite/**
          README.md
          requirements.txt

I have tried to make this into

on:
  push:
    branches:
      - staging

name: 🚀 Deploy website on push (staging)
jobs:
  web-deploy:
    name: 🎉 Deploy
    runs-on: ubuntu-latest
    steps:
    - name: 🚚 Get latest code
      uses: actions/checkout@v2
    
    - name: 📂 Sync files (Frontend)
      uses: SamKirkland/[email protected]
      with:
        server: ${{ secrets.ftp_server }}
        username: ${{ secrets.ftp_username }}
        password: ${{ secrets.ftp_password }}
        server-dir: /public_html/
        exclude: |
          **/.git*
          **/.git*/**
          **/node_modules/**
          **/env/**
          **/mywebsitebackend/**
          README.md
          requirements.txt

    - name: 📂 Sync files (Backend)
      uses: SamKirkland/[email protected]
      with:
        server: ${{ secrets.ftp_server }}
        username: ${{ secrets.ftp_username }}
        password: ${{ secrets.ftp_password }}
        server-dir: /mywebsitebackend/
        exclude: |
          **/.git*
          **/.git*/**
          **/node_modules/**
          **/env/**
          README.md
          index.html

This can theoretically copy the files into the proper directories but I wish to be able to run python pip install -r requirements.txt on my remote server automatically.

Is there anyway to run pip install automatically on CPanel?

PS.I read about the Pull and Push workflow but couldn't find a desireable outcome. I wish to push to my github repo and have it all be done automatically.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source