Friday, January 19, 2024

How to automatically deploy code from GitHub

This tutorial will show you how to use GitHub to deploy code to an Ubuntu server.


Generate an SSH key on Server

1. login your server using ssh. 

ssh root@IP_Address

2. Run the command

ssh-keygen -b 4096






Click on enter until the key generates





















SSH Key being Generated.

Add the public key to authorized_key

cat id_rsa.pub >> authorized_keys
Create Action in GitHub

1. Create secrets in GitHub.























Copy and paste the private ssh key from server using the cat command

cat id_rsa

Create next secrets host and user name. Host should be the IP address and user name is the user in the server in here the user name is 'root'.




















2. Also add public ssh key on GitHub Authentication Keys




















Click on 'New SSH key' and paste the public ssh key that created in server.

cat id_rsa.pub

3. Clone the Git repository into the server 
 git clone -b main --depth 1 git@github.com:YourUserName/YourRepository.git

3.Create an action



Click on 'set up a workflow yourself', and copy paste the given script.



name: Auto Deploy

# Controls when the action will run. 
on:
  # Triggers the workflow on push or pull request events but only for the master branch
  push:
    branches: [ main ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:       
    - name: Deploy using ssh
      uses: appleboy/ssh-action@master
      with:
        host: ${{ secrets.HOST }}
        username: ${{ secrets.USERNAME }}
        key: ${{ secrets.SSH_KEY }}
        port: 22
        run: |
          ssh $username@$host "
          cd /odoo/custom-addons/learnrepo &&
          git pull origin main"
          


And click on commit changes in the top right corner.


Click the Action menu now. When it functions, a green checkmark appears. 





Thursday, October 5, 2023

Install Odoo 16 on Ubuntu 20.04

1. Login your server 

    ssh root@IP_Address

2. Run the Following Command

    sudo apt update

    sudo apt upgrade

3. Install PostgreSql

    sudo apt install postgresql 

4. Install the following packages and dependencies required for the Odoo 16 installation


sudo apt install build-essential wget git python3-pip python3-dev python3-venv python3-wheel libfreetype6-dev libxml2-dev libzip-dev libsasl2-dev python3-setuptools libjpeg-dev zlib1g-dev libpq-dev libxslt1-dev libldap2-dev libtiff5-dev libopenjp2-7-dev  

5. Create a System User and Postgres User 

    sudo useradd -m -d /opt/odoo16 -U -r -s /bin/bash odoo16

    -We have created a system user named "odoo16" with the home directory set to "/opt/odoo16."

    sudo su - postgres -c "createuser -s odoo16"

    -Here we have created a postgres user role named "odoo16".

    5.1.  Alter postgres user password

        sudo su - postgres

        psql

        alter user odoo16 with password 'password_we_need';

        exit 

        exit

6. Install Wkhtmltopdf

    -Download the package


wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.bionic_amd64.deb

    -Install the package

        sudo apt-get install fontconfig libxrender1 xfonts-75dpi xfonts-base

        - If any errors occur while running the above command, please execute the following command 

            sudo apt --fix-broken install

        sudo dpkg -i wkhtmltox_0.12.5-1.bionic_amd64.deb

    -Fix dependencies

        sudo apt install -f

7. Install Odoo 16

     -switch to system user odoo16

        sudo su - odoo16

    -Download Odoo 16 from Github

        git clone https://www.github.com/odoo/odoo --depth 1 --branch 16.0 odoo16

    -Create python Virtual Environment and Activate

        cd /opt/odoo16

        python3 -m venv odoo16-venv

        source odoo16-venv/bin/activate

    -Install requirements

        pip3 install wheel

        pip3 install -r odoo16/requirements.txt 

    -deactivate Virtual Environment and exit

        deactivate && exit

8. Create a custom addons directory and change ownership to user odoo16

    mkdir /opt/odoo16/odoo16/custom-addons

    chown odoo16: /opt/odoo16/odoo16/custom-addons

9. Create Log file

    mkdir /var/log/odoo16

    touch /var/log/odoo16/odoo.log

    touch /var/log/odoo16/odoo_all.log

    chown -R odoo16: /var/log/odoo16/

10. Create a configuration file 

    nano /etc/odoo16.conf

    -Paste the given lines into the "odoo16.conf" file

[options]
admin_passwd = admin@master
db_host = localhost
db_port = 5432
db_user = odoo16
db_password = password_we_need
xmlrpc_port = 8069
logfile = /var/log/odoo16/odoo.log
addons_path = /opt/odoo16/odoo16/addons,/opt/odoo16/odoo16/custom-addons/git_repo
proxy_mode = True
dbfilter = ^%d$
list_db = False
workers = 8
longpolling_port = 8072
limit_memory_hard = 6442450944
limit_memory_soft = 5368709120
limit_time_real = 10000000
limit_time_cpu = 600
max_cron_threads = 2

    - Change workers and below lines based on your server configuration

    10.1 Create an another configuration file (optional)

        nano /etc/odoo16_all_db.conf

[options]
admin_passwd = admin@master
db_host = localhost
db_port = 5432
db_user = odoo16
db_password = password_we_need
xmlrpc_port = 8080
logfile = /var/log/odoo16/odoo_all.log
addons_path = /opt/odoo16/odoo16/addons,/opt/odoo16/odoo16/custom-addons/git_repo
limit_time_real=1000000
proxy_mode=True
workers = 2
longpolling_port = 8079
limit_time_cpu = 600
max_cron_threads = 2
 

11. create a systemd service file for running Odoo 16

    sudo nano /etc/systemd/system/odoo16.service

     -Paste the given lines into the "odoo16.service" file

[Unit]
Description=Odoo16
Requires=postgresql.service
After=network.target postgresql.service

[Service]
Type=simple
SyslogIdentifier=odoo16
PermissionsStartOnly=true
User=odoo16
Group=odoo16
ExecStart=/opt/odoo16/odoo16-venv/bin/python3 /opt/odoo16/odoo16/odoo-bin -c /etc/odoo16.conf
StandardOutput=journal+console

[Install]
WantedBy=multi-user.target
 
    11.1 Create an another service file(optional)

        sudo nano /etc/systemd/system/odoo16_all_db.service

[Unit]
Description=Odoo16alldb
Requires=postgresql.service
After=network.target postgresql.service

[Service]
Type=simple
SyslogIdentifier=odoo16alldb
PermissionsStartOnly=true
User=odoo16
Group=odoo16
ExecStart= /opt/odoo16/odoo16-venv/bin/python3 /opt/odoo16/odoo16/odoo-bin -c /etc/odoo16_all_db.conf
StandardOutput=journal+console

[Install]
WantedBy=multi-user.target
    11.1. Start service
             service odoo16 start      
             service odoo16_all_db start  

12. Intall Nginx web server
       
    sudo apt update
    sudo apt install nginx
    sudo ufw allow 'Nginx HTTP'

13. Create new configuration files for odoo16 and odoo16_all_db 

    sudo nano /etc/nginx/sites-available/odoo16.conf
    
   
upstream odoo16 {
server 127.0.0.1:8069;
}
upstream odoochats {
server 127.0.0.1:8072;
}


server {
     listen 80;
     server_name *.hostname.com;

proxy_read_timeout 28000s;
proxy_connect_timeout 28000s;
proxy_send_timeout 28000s;


# Add Headers for odoo proxy mode
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;

# log
access_log /var/log/nginx/odoo.access.log;
error_log /var/log/nginx/odoo.error.log;

# Redirect requests to odoo backend server
location / {
proxy_redirect off;
proxy_pass http://odoo16;
}
location /longpolling {
proxy_pass http://odoochats;
}

# common gzip
gzip_types text/css text/less text/plain text/xml application/xml application/json application/javascript;
gzip on;


client_body_in_file_only clean;
client_body_buffer_size 128K;
client_max_body_size 500M;
sendfile on;
send_timeout 28000s;
keepalive_timeout 28000;
}

    
sudo nano /etc/nginx/sites-available/odoo16_all_db.conf
    
#odoo server
upstream odoo {
server 127.0.0.1:8080;
}
upstream odoochat {
server 127.0.0.1:8079;
}


server {
listen 80;
server_name IP_Address;

proxy_read_timeout 288000s;
proxy_connect_timeout 288000s;
proxy_send_timeout 288000s;


# Add Headers for odoo proxy mode
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;

# log
access_log /var/log/nginx/odoo.access.log;
error_log /var/log/nginx/odoo.error.log;

# Redirect requests to odoo backend server
location / {
proxy_redirect off;
proxy_pass http://odoo;
proxy_max_temp_file_size 4096M;
}
location ~* /web/static/ {
         proxy_cache_valid 200 90m;
         proxy_buffering on;
         expires 864000;
         proxy_pass http://odoo;
 }


location /longpolling {
proxy_pass http://odoochat;
}

# common gzip
gzip_types text/css text/less text/plain text/xml application/xml application/json application/javascript;
gzip on;

client_body_in_file_only clean;
client_body_buffer_size 512M;
client_max_body_size 6000M;
sendfile on;
send_timeout 28800s;
keepalive_timeout 28800s;
}
14. Create symlink into sites-enabled

    sudo ln -s /etc/nginx/sites-available/odoo16.conf /etc/nginx/sites-enabled/
    
    sudo ln -s /etc/nginx/sites-available/odoo16_all_db.conf /etc/nginx/sites-enabled/
    
15. Start nginx service

     sudo nginx -t

     sudo service nginx restart

16. Enter the IP address into your web browser.



How to automatically deploy code from GitHub

This tutorial will show you how to use GitHub to deploy code to an Ubuntu server. Generate an SSH key on Server 1. login your server using s...