As my ubuntu server is having low spec can I do `n...
# random
e
As my ubuntu server is having low spec can I do
npm run build
using github action and then just pass that build to nginx server to show new react app running? npm run build on server not working giving me message: The build failed because the process exited too early. This probably means the system ran out of memory or someone called
kill -9
on the process.
w
Yes. Run a GitHub Action and push the built code into a specific branch (
build
, perhaps?). The pull the branch on your Ubuntu server. Here's a sample GitHub Actions workflow to push a build to a specific branch. https://umanggalaiya.in/blog/2020/github-pages-action.html
e
I have one more question. I wasted around 4-5 hrs because I react app build was failing. Getting this message:
##[error]Process completed with exit code 1.
but once I added CI=false in env it worked any idea why so?
if I go with run: self-hosted then it trys to run build on server which is again giving me same message: build failed because the process exited too early. This probably means the system ran out of memory or someone called kill -9 on the process or FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory so instead of run: self-hosted should I go with specific ubuntu version? eg: ubuntu-20.04 etc?? but then how will I get that build folder into my server which can be used by nginx?
w
but once I added CI=false in env it worked any idea why so?
No idea, would need to take a look at your build process to figure out. What's
run: self-hosted
?
e
What's 
run: self-hosted
?
that is using github runner
w
The workflow snippet in my blogpost uses ubuntu-latest
e
@witty-air-63049 I did as per your suggestion please check below github action workflow:
Copy code
name: Node.js CI

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build:

    runs-on: ubuntu-20.04
    env:
      CI: false
      REACT_APP_ENV: ${{ secrets.REACT_APP_ENV }}

    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-node@v2
      with:
        node-version: 16.14.0
    - run: npm ci
    - run: npm run build

    - uses: actions/checkout@v1

    - name: Copy repository contents via scp
      uses: appleboy/scp-action@master
      env:
        HOST: ${{ secrets.LINODE_HOST }}
        USERNAME: ${{ secrets.LINODE_USERNAME }}
        PORT: ${{ secrets.LINODE_PORT }}
        KEY: ${{ secrets.LINODE_SSH_KEY }}
      with:
        source: "."
        target: "/var/www/mywebsite"
but when on remote server I check /var/www/mywebsite I don't see build folder. How can I copy build folder as well to this path: /var/www/mywebsite ?? any suggestions?
w
Not sure, man. I've never done scp stuff.
e
I was able to do it. check this workflow:
Copy code
name: Node.js CI

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build:

    runs-on: ubuntu-20.04
    env:
      CI: false
      REACT_APP_ENV: ${{ secrets.REACT_APP_ENV }}

    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-node@v2
      with:
        node-version: 16.14.0
    - run: npm ci
    - run: npm run build

      # Share artifact inside workflow
    - name: Share artifact inside workflow
      uses: actions/upload-artifact@v1
      with:
        name: micro-saas-frontend-build
        path: build

  deploy:
    runs-on: ubuntu-20.04
    # When application is successfully tested and build has been generated
    # Then we can start with deployment
    needs: build
    steps:
      # Download previously shared build
      - name: Get artifact
        uses: actions/download-artifact@v1
        with:
          name: micro-saas-frontend-build
      - shell: bash
        run: |
          cd micro-saas-frontend-build
          ls
      - name: Copy build folder via scp
        uses: appleboy/scp-action@master
        env:
          HOST: ${{ secrets.LINODE_HOST }}
          USERNAME: ${{ secrets.LINODE_USERNAME }}
          PORT: ${{ secrets.LINODE_PORT }}
          KEY: ${{ secrets.LINODE_SSH_KEY }}
        with:
          source: "micro-saas-frontend-build"
          target: "/var/www/mywebsite"
it works fine
reason for doing this was build was not successful on my ubuntu server because it has very low specs 1GB ram so build was failing due to limited resources i.e RAM
w
Awesome. Glad you got it working!
👍 1