Home  >  Article  >  Backend Development  >  Docker+LNMP+Jenkins+Code Cloud realizes automatic deployment of PHP code

Docker+LNMP+Jenkins+Code Cloud realizes automatic deployment of PHP code

藏色散人
藏色散人forward
2020-01-17 14:30:504066browse

Automated deployment (continuous integration/CI continuous delivery/CD) is a trend in software development and is a good help for the development of DevOps. Today’s practice is based on the Docker Jenkins LNMP code cloud to realize the automated deployment process of PHP code.

Environment configuration

Operating system: CentOS Linux release 7.6.1810

Docker version: 19.03.5

Jenkins version: 2.204.1

Nginx version: 1.15.5

PHP version: 7.2.26

MySQL version: 8.0.18

Redis version :5.0.5

Code Cloud: Code Warehouse

Code Cloud Warehouse Preparation

Create Project Warehouse

Docker+LNMP+Jenkins+Code Cloud realizes automatic deployment of PHP code

Jenkins preparation

Install the ssh plug-in

Because building the project requires executing some shell commands on the server, So use ssh login method to communicate with the remote server.

1. System Management->Plug-in Management

2. Search: ssh, install it

Docker+LNMP+Jenkins+Code Cloud realizes automatic deployment of PHP code

Docker+LNMP+Jenkins+Code Cloud realizes automatic deployment of PHP code

##New project task

The task name cannot be in Chinese, choose the first one: Freestyle project Custom project

Docker+LNMP+Jenkins+Code Cloud realizes automatic deployment of PHP code

##Engineering task configuration

1. Source code management selection: git

2. Repository URL: warehouse address (mine is the code cloud warehouse)

3. Credentials, select Add

4. Add credentials

5. Configure the warehouse private key (for details, please view the warehouse key management help of Code Cloud)

Docker+LNMP+Jenkins+Code Cloud realizes automatic deployment of PHP code

Docker+LNMP+Jenkins+Code Cloud realizes automatic deployment of PHP codeAfter the credentials are configured successfully, just select the Username configured in the previous step. If you successfully connect to the warehouse address, no error will be reported.

Docker+LNMP+Jenkins+Code Cloud realizes automatic deployment of PHP codeBuild trigger selection: Github hook trigger for GITScm polling

Docker+LNMP+Jenkins+Code Cloud realizes automatic deployment of PHP codeBuild environment: Use secret text(s) or file(s) //Transfer files privately

Credentials: Select the specified credentials git

Docker+LNMP+Jenkins+Code Cloud realizes automatic deployment of PHP code

Configure ssh

1. System Management->System Configuration

2. Configure remote server ssh related information

Docker+LNMP+Jenkins+Code Cloud realizes automatic deployment of PHP code

Docker+LNMP+Jenkins+Code Cloud realizes automatic deployment of PHP code

Configure build shell script

Build: Execute shell script on remote host using ssh //Execute remote server shell script when building

1. Fill in SSH site //Remote server ssh Login

2. Command //shell script

Remarks:

Because the code is automatically deployed in the workspace directory of jenkins, and the project’s site directory is in /data/ www, so when building, you need to copy the updated code file to the project site (there are many ways to implement it. Here, use a copy of the code because the size of the code will not take up a lot of space. Nowadays, many static Resources are placed on some cloud services)

I initially used the soft connection method, but because nginx does not support soft connection access.

Docker+LNMP+Jenkins+Code Cloud realizes automatic deployment of PHP code

Docker+LNMP+Jenkins+Code Cloud realizes automatic deployment of PHP codeAfter the configuration is completed, click Save

Code Cloud Code Push

Modify the code in the code cloud warehouse, and then submit the PR to the master branch

Docker+LNMP+Jenkins+Code Cloud realizes automatic deployment of PHP code

Manual construction of deployment tasks

Click Build manually to realize automated code deployment

Remarks:

Also It can be configured to automatically build directly after monitoring git push (this is recommended for the test environment)

Clicking the build manually is for better management (this is recommended for the production environment)

Docker+LNMP+Jenkins+Code Cloud realizes automatic deployment of PHP code

Docker+LNMP+Jenkins+Code Cloud realizes automatic deployment of PHP code

If the task construction fails, there will be an error message and a red mark //very convenient for management

Docker+LNMP+Jenkins+Code Cloud realizes automatic deployment of PHP code

Docker+LNMP+Jenkins+Code Cloud realizes automatic deployment of PHP code

Visit the website

After the automated deployment task is successfully built, visit our project to see the modification effect

Docker+LNMP+Jenkins+Code Cloud realizes automatic deployment of PHP code

The above is the detailed content of Docker+LNMP+Jenkins+Code Cloud realizes automatic deployment of PHP code. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete