Site icon JnPnote

How to Auto-Deploy Using Github Actions React Project to Raspberry Pi

I have Raspberry Pi 2 from my friend, and set it up already. And I worked on building Portfolio Website with React. I want to host this site myself.

I haven’t write post for setting up the RPi, but there are tons of tutorials. You can refer to them to setup the RPi.

I wanted to make the deployment easier, like whenever I push to Github, my rpi server pull the latest commit and build it. I was looking for the tutorial a lot, but most of them are making the rpi itself as remote. However, I wanted to use github as my remote. Push my local work to github, and Pull the latest commit on github to rpi. And I found a package name git-auto-deploy, but I was kind of confusing about webhooks, so I was searching more. And found this Youtube video Automatic Deployment With Github Actions.

In case you just want to know how to deploy, you can refer to my previous post How to Deploy React Project to Raspberry Pi.

1. Prerequisites

FYI, I am using Windows10 and Windows Powershell.

2. Create Workflow

# 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: Node.js CI

on:
  push:
    branches: [ "master" ]

jobs:
  build:

    runs-on: self-hosted

    strategy:
      matrix:
        node-version: [19.x]
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/

    steps:
    - uses: actions/checkout@v3
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v3
      with:
        node-version: ${{ matrix.node-version }}
        cache: 'npm'
    - run: npm i
    - run: npm run build --if-present
    - run: npm test

3. Setup the Runner on RPi

sudo ./svc.sh install
sudo ./svc.sh start
sudo ./svc.sh status 

4. Configure Nginx

sudo nano /etc/nginx/sites-available/jisoo
sudo systemctl reload nginx

5. Check Auto-Deploy

6. Conclusion

It is not that difficult to setup, but it was taking more than 10 minutes while the tutorial video was taking less than a minute because my RPi is old and not powerful. So, I would deploy by just copy paste the build folder.

Exit mobile version