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
SSH Key being Generated.
1. Create secrets in GitHub.
3.Create an action
Add the public key to authorized_key
cat id_rsa.pub >> authorized_keys
Create Action 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'.
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.