Difference between revisions of "Github CI/CD"

From Logic Wiki
Jump to: navigation, search
Line 37: Line 37:
 
  <USERNAME> ALL=(ALL) NOPASSWD: /usr/sbin/service nginx start, /usr/sbin/service nginx stop, /usr/sbin/service nginx restart
 
  <USERNAME> ALL=(ALL) NOPASSWD: /usr/sbin/service nginx start, /usr/sbin/service nginx stop, /usr/sbin/service nginx restart
 
With this Linux will not ask sudo pass for stop start restart of nginx  
 
With this Linux will not ask sudo pass for stop start restart of nginx  
 +
 +
== Github Action ==
 +
Before everything make sure that your project is in the root of git folders.
 +
 +
For react projects it's better to set CI environment variable to false in '''package.json''' to ignore warnings
 +
<pre>
 +
  "scripts": {
 +
    "build": "CI=false && react-scripts build",
 +
</pre>
 +
* Create a folder in the root  "'''.github'''" and inside of it create another folder "'''workflows'''"
 +
* Create a yaml file with any name like "'''deploytotest.yml'''"
 +
The content of the file is like :
 +
<pre>
 +
name: deploytotest CI
 +
 +
on:
 +
  push:
 +
    branches: [ develop ]
 +
  pull_request:
 +
    branches: [ develop ]
 +
 +
jobs:
 +
  build:
 +
    runs-on: self-hosted
 +
 +
    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 ci
 +
      - run: npm run build
 +
</pre>
  
  
 
---------------------
 
---------------------
 
see : [https://www.youtube.com/watch?v=6-RtA6FlbgQ&list=PL_7mM2_n2qvbtLhKo6Ijqt2cnmCAd2JVi&index=10&t=2348s https://www.youtube.com/watch?v=6-RtA6FlbgQ&list=PL_7mM2_n2qvbtLhKo6Ijqt2cnmCAd2JVi&index=10&t=2348s]
 
see : [https://www.youtube.com/watch?v=6-RtA6FlbgQ&list=PL_7mM2_n2qvbtLhKo6Ijqt2cnmCAd2JVi&index=10&t=2348s https://www.youtube.com/watch?v=6-RtA6FlbgQ&list=PL_7mM2_n2qvbtLhKo6Ijqt2cnmCAd2JVi&index=10&t=2348s]

Revision as of 11:28, 5 April 2022


Preparing Linux

In Linux you have to do everything with a user but not root.

In order to create a user use adduser command

NGinx setup

Follow Nginx

Github Runner

Like the agents in TFS Github has runners So we need to install runners to pull github repositories when they are pushed.

1 - Go to repository

2 - Go to settings

3 - Go to Actions -> Runners

4 - Click New self-hosted runner

5 - Select the operating system

6 - Go to the folder you want to install the runner and pull the codes in your environment

7 - Give full permission

sudo chmod -R 777 /var/www/FrontEnd

8 - Follow the download steps in github

9 - Follow the Configure steps in github

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

Sudo Trick

sudo visudo -f /etc/sudoers.d/<USERNAME>

in the file

<USERNAME> ALL=(ALL) NOPASSWD: /usr/sbin/service nginx start, /usr/sbin/service nginx stop, /usr/sbin/service nginx restart

With this Linux will not ask sudo pass for stop start restart of nginx

Github Action

Before everything make sure that your project is in the root of git folders.

For react projects it's better to set CI environment variable to false in package.json to ignore warnings

  "scripts": {
    "build": "CI=false && react-scripts build",
  • Create a folder in the root ".github" and inside of it create another folder "workflows"
  • Create a yaml file with any name like "deploytotest.yml"

The content of the file is like :

name: deploytotest CI

on:
  push:
    branches: [ develop ]
  pull_request:
    branches: [ develop ]

jobs:
  build:
    runs-on: self-hosted

    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 ci
      - run: npm run build



see : https://www.youtube.com/watch?v=6-RtA6FlbgQ&list=PL_7mM2_n2qvbtLhKo6Ijqt2cnmCAd2JVi&index=10&t=2348s