First, the required environment and tools

Submit end(Local end)

  1. Git environment
  2. Program source code

Update the end(Server)

  1. The server
  2. The pagoda panel
  3. Pagoda WebHook plugin
  4. The environment required to run the project

Name and address of flat(lot)

  1. Project GitHub repository address

2. Obtain the git public key of the update server

1. Set the global user name and email address to be the same as those in the GitHub repository.

Git global configuration and individual repository username mailbox configuration
git config --global user.name  "username"
git config --global user.email  "[email protected]"
Copy the code

2. Generate a Git public key

Git public key for automatic pull
ssh-keygen -t rsa -C "Your @ email.com"
Copy the code

3. View the git public key

Git public key
cat ~/.ssh/id_rsa.pub
Copy the code

4. Copy the git public key

Add git public key to GitHub

1. Open theGitHub

2. Click on theHead portrait

3. Selectsettings

4. SelectSSH and GPG keys

5. Click on theNew SSh key

6. Add a Git public key

Four, configure the pagoda webhook

1. Open the Pagoda WebHook plug-in

2. Set the script name

3. Add the following script

4. Just change your warehouse address

5. Other parts do not need to be modified

#! /bin/bash
echo ""
Print the current time
date --date='0 days ago' "+%Y-%m-%d %H:%M:%S"
echo "Start"
Check whether the pagoda WebHook parameter exists
if [ ! -n "The $1" ];
then 
          echo "Param parameter error"
          echo "End"
          exit
fi
Git project path ($1 is the parameter after param, pointing to your server's directory)
gitPath="/www/wwwroot/The $1"
#git url (SSH instead of your git address)
gitHttp="[email protected]: your account/repository name.git"
 
echo "Web site path:$gitPath"
 
Check whether the project path exists
if [ -d "$gitPath" ]; then
        cd $gitPath
        Check whether a git directory exists
        if [ ! -d ".git" ]; then
                echo "Clone git in this directory"
                git clone $gitHttp gittemp
                mv gittemp/.git .
                rm -rf gittemp
        fi
        Git pull command: git pull command:
        #git reset --hard origin/master
        #git pull origin master
        git fetch --all && git reset --hard origin/master && git pull
        Set directory permissions
        chown -R www:www $gitPath
        echo "End"
        exit
else
        echo "The project path does not exist"
        echo "End"
        exit
fi
Copy the code

GitHub webhook

1. Open thePagoda WebHook plugin

2. Click on theLook at the key

3. The replication request address is as follows

#webhook request addresshttp://panel address: panel port? Access_key = key &param= your code directory addressCopy the code

4. Open theGitHub

5. Enter theProject code repository

6. Selectsettings

7. SelectWebhooks

8. ClickAdd Webhooks

9. Payload URL

  1. Put in the webhook request address you copied

  2. Modify the parameters after param

  3. For example, project address:

  4. / WWW /wwwroot/ Project directory

  5. Param = project directory

  6. / WWW/below/don’t need

10. Content type

Select application/json * * * *Copy the code

11. Secret

Please don't fill * * * *Copy the code

12. Which events would you like to trigger this webhook?

Select **Just the push event.**Copy the code

13. ActiveThe selected

14. Click the button lastAdd Webhooks

Initialize the project on the server

Note: Manual pull deployment is required for the first time to ensure that subsequent automatic pull meets requirements and can be executed normally.

1. Access the project directory

2. Initialize git execution

git init
Copy the code

3. Connect to the remote warehouse (SSH mode is required)

git remote add origin [email protected]:yourName/repositoryname.git
Copy the code

4. Pull the desired branch code

git pull origin master
Copy the code

5. Install dependencies based on project requirements

# for example: PHP composer, Node NPM, etc......Copy the code

6. Complete the deployment

7. Commit code locally every time in the future

8. The code is automatically updated on the server

More front-end content welcome to pay attention to the public number: day small day personal network