Automatic publishing and deploying method and system based on Jenkins and Docker
By adopting automatic release and deployment methods and systems based on Jenkins and Docker in the program release process, the problems of version management and running environment differences are solved, and efficient program release is achieved.
Patent Information
- Application Number
- CN202510066707.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-16
- Publication Date
- 2025-04-25
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The existing technology has version management problems, problems caused by differences in the operating environment, and problems of low release efficiency in the program release process, especially in the scenarios of frequent deployment.
Using automatic release and deployment methods and systems based on Jenkins and Docker, an automated release process is built through Jenkins, Docker's image layering technology is used to generate business images, and version management and deployment are carried out through the cloud management platform.
Business image version management is carried out through the cloud management platform, and Docker image layering technology is used to ensure that the dependency package needs to be downloaded only once, avoiding problems caused by differences in customer environments and improving release efficiency.
Smart Images

Figure CN119883294A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data transmission deployment, and in particular to an automatic publishing and deployment method and system based on Jenkins and Docker. Background Art
[0002] Under the existing technology, the process of program release is generally as follows: (1) The developer uses Maven to compile a new version of the jar package using the command "maven package". The compiled jar package is about 100MB in size and contains the business code and the dependency packages required by the business code.
[0003] (2) The developer logs in to the server that needs to be updated through ssh. The command is "ssh username@IP -p port". After entering the command, the server password is required. Sometimes more than one server may need to be updated, and it is necessary to log in to multiple servers to perform the update operation.
[0004] (3) Upload the jar package to the server. The command for uploading files is "scp -P port file local path username@IP: file remote path".
[0005] (4) Back up the old version of the jar package. The command is "mv old version jar package old version jar package.bak.date".
[0006] (5) Stop the old version service. The command is “kill old version service PID”.
[0007] (6) Start the new version of the jar package. The command is "nohup java -jar new version of the jar package &".
[0008] On this basis, even if Jenkins is introduced to achieve automated deployment, there are still some problems that need to be solved: 1. Most Jenkins deployment solutions still use SSH to execute commands on a specific server, but the manual process has changed to automatic. Since some customers have not upgraded, it is more necessary to establish a version correspondence at the source code level. 2. In scenarios where frequent deployment is required, such as emergency handling of online issues and release of updates to development servers, the compiled product obtained using the conventional Jenkins build solution is usually 100MB+, and a release in this scenario will take a long time; 3. For private deployment, the customer environment is usually difficult to control, so it is necessary to solve the problems caused by the differences in different environments. Summary of the invention
[0009] The technical problem to be solved by the present invention is to provide an automatic publishing and deployment method and system based on Jenkins and Docker, solve the problems of version management and operating environment differences, and improve publishing efficiency.
[0010] In order to solve the above technical problems, the technical solution adopted by the present invention is: An automatic publishing method based on Jenkins and Docker, using Jenkins to build an automatic publishing process, the automatic publishing process includes the following steps: S1. Obtain the source code version, business version and deployment environment to be built; S2. Obtain code according to the source code version, and generate a business image based on Maven and Docker image layering technology, where the business image includes a business jar package and basic dependency packages; S3: Upload the business image, the business version and the deployment environment to the cloud management platform, and trigger a deployment event corresponding to the deployment environment.
[0011] In order to solve the above technical problems, the technical solution adopted by the present invention is: An automatic deployment method based on Jenkins and Docker, including the following steps: S1. Receive a deployment event corresponding to the current deployment environment, and obtain a new version of the business image from the cloud management platform. If the basic image layer already exists locally, only the application image layer in the business image needs to be obtained; The deployment event is triggered based on the above-mentioned automatic publishing method based on Jenkins and Docker; S2. Call Docker to start the new version of the business image as a new Docker container, and read the preset functional environment parameters and pass them to the Docker container; S3. Start the new version of the Docker container to start the business program.
[0012] In order to solve the above technical problems, the technical solution adopted by the present invention is: An automatic publishing terminal based on Jenkins and Docker includes a first processor, a first memory, and a first computer program stored in the first memory and executable on the first processor. When the first computer program is executed, the steps in the automatic publishing method based on Jenkins and Docker are implemented.
[0013] In order to solve the above technical problems, the technical solution adopted by the present invention is: An automatic deployment terminal based on Jenkins and Docker includes a second processor, a second memory, and a second computer program stored in the second memory and executable on the second processor. When the second computer program is executed, the steps in the automatic deployment method based on Jenkins and Docker are implemented.
[0014] In order to solve the above technical problems, the technical solution adopted by the present invention is: An automatic deployment system based on Jenkins and Docker, including a publishing end, a deployment end, and a cloud management platform; And the steps in the above-mentioned automatic publishing method based on Jenkins and Docker are implemented through the publishing end; The steps in the above-mentioned automatic deployment method based on Jenkins and Docker are implemented through the deployment end.
[0015] The beneficial effects of the present invention are: an automatic publishing and deployment method and system based on Jenkins and Docker of the present invention manages business image versions through a cloud management platform. At the same time, the business image is implemented based on Docker image layering technology, ensuring that the dependent package only needs to be downloaded once and there is only one copy. At the same time, the characteristics of the Docker container environment being isolated from the external environment are utilized to avoid problems caused by differences in customer environments. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 This is a flow chart of an automatic publishing method based on Jenkins and Docker in an embodiment of the present invention; Figure 2 This is a flow chart of an automatic deployment method based on Jenkins and Docker in an embodiment of the present invention; Figure 3 This is an overall example diagram of the release and deployment process of an embodiment of the present invention; Figure 4 This is a structural example diagram of an automatic publishing terminal based on Jenkins and Docker in an embodiment of the present invention; Figure 5 This is a structural example diagram of an automatic deployment terminal based on Jenkins and Docker in an embodiment of the present invention; Figure 6 This is a structural example diagram of an automatic deployment system based on Jenkins and Docker according to an embodiment of the present invention; Description of labels: 1. An automatic publishing terminal based on Jenkins and Docker; 2. A first processor; 3. A first memory; 4. An automatic deployment terminal based on Jenkins and Docker; 5. A second processor; 6. A second memory; 7. An automatic deployment system based on Jenkins and Docker; 8. A cloud management platform; 9. A publishing terminal; 10. A deployment terminal. DETAILED DESCRIPTION
[0017] In order to explain the technical content, achieved objectives and effects of the present invention in detail, the following is an explanation in combination with the implementation modes and the accompanying drawings.
[0018] Please refer to Figure 1 as well as Figure 3 , an automatic publishing method based on Jenkins and Docker, using Jenkins to build an automatic publishing process, the automatic publishing process includes the following steps: S1. Obtain the source code version, business version and deployment environment to be built; S2. Obtain code according to the source code version, and generate a business image based on Maven and Docker image layering technology, where the business image includes a business jar package and basic dependency packages; S3: Upload the business image, the business version and the deployment environment to the cloud management platform, and trigger a deployment event corresponding to the deployment environment.
[0019] From the above description, it can be seen that the beneficial effects of the present invention are: an automatic publishing and deployment method and system based on Jenkins and Docker of the present invention manages business image versions through a cloud management platform. At the same time, the business image is implemented based on Docker image layering technology, ensuring that the dependent package only needs to be downloaded once and there is only one copy. At the same time, the characteristics of the Docker container environment being isolated from the external environment are utilized to avoid problems caused by differences in customer environments.
[0020] Further, step S2 comprises the steps of: S21. Obtain code according to the source code version, and build the business jar package through Maven based on preconfigured building parameters; S22. According to the constructed business jar package and the existing basic dependency package, a Docker image is generated based on Docker's image layering technology to obtain a business image.
[0021] From the above description, we can know that by using the Maven plug-in, the build products are divided into business jar packages and basic dependency packages, and the business image is generated by using the Docker image layering mechanism.
[0022] Furthermore, the business image includes the business jar package and the basic dependency package specifically: The business image uses the basic dependency package as the basic image layer and the business jar package as the application image layer.
[0023] From the above description, we can see that the image layering mechanism of Docker is used to take the basic dependency package as the basic image layer.
[0024] Please refer to Figure 2 and Figure 3 , an automatic deployment method based on Jenkins and Docker, including the steps: S1. Receive a deployment event corresponding to the current deployment environment, and obtain a new version of the business image from the cloud management platform. If the basic image layer already exists locally, only the application image layer in the business image needs to be obtained; The deployment event is triggered based on the above-mentioned automatic publishing method based on Jenkins and Docker; S2. Call Docker to start the new version of the business image as a new Docker container, and read the preset functional environment parameters and pass them to the Docker container; S3. Start the new version of the Docker container to start the business program.
[0025] From the above description, it can be seen that the business image version management is performed through the cloud management platform. At the same time, the business image is implemented based on the Docker image layering technology, which ensures that the basic dependency package only needs to be downloaded once. In subsequent updates, only the business jar package in the business image needs to be downloaded. The basic dependency package exists and only exists in one copy. At the same time, the business image is started as a new Docker container by utilizing the isolation of the Docker container environment from the external environment to start the business program, avoiding problems caused by differences in customer environments.
[0026] Furthermore, the functional environment parameters include a database address and functions that are allowed to be accessed.
[0027] From the above description, we can know that the function environment parameters are passed to the Docker container for use, including the database address and the parameters allowed to be accessed.
[0028] Furthermore, step S3 is specifically as follows: The new version of the Docker container is started to run the entry script, and the entry script reads the functional environment variables and starts the business program.
[0029] From the above description, it can be seen that the entrypoint script is executed, and the script reads the environment variables and starts the business program.
[0030] Furthermore, the cloud management platform is configured with different environment keys for different deployment environments; Step S1 is specifically as follows: Upon receiving a deployment event corresponding to the current deployment environment, the cloud management platform is asked to obtain a new version of the business image by carrying the environment key of the current environment. The cloud management platform verifies the environment key and returns the business version of the new version of the business image. The business image is obtained from the Docker repository of the cloud management platform according to the business version. When the basic image layer already exists locally, only the application image layer in the business image needs to be obtained.
[0031] From the above description, it can be seen that for different deployment environments, the cloud management platform needs to carry the environment key of the current environment when obtaining the business image, so as to distinguish the environment and ensure security.
[0032] The invention discloses an automatic publishing and deployment method and system based on Jenkins and Docker, which are suitable for remote deployment of program projects.
[0033] Please refer to Figure 1 and Figure 3 , Embodiment 1 of the present invention is: An automatic publishing method based on Jenkins and Docker, using Jenkins to build an automatic publishing process, the automatic publishing process includes the following steps: S1. Obtain the source code version, business version, and deployment environment to be built.
[0034] In this embodiment, the developer writes the code, submits it to Gitlab, and then opens the Jenkins web interface to enter the corresponding instructions to start a build and release process. According to the input instructions, the source code version, business version, and deployment environment of this build are confirmed.
[0035] Send a deployment start notification to the corresponding personnel, carrying some deployment parameters.
[0036] S2. Obtain code according to the source code version, and generate a business image based on Maven and Docker image layering technology, where the business image includes a business jar package and basic dependency packages; The business image contains the business jar package and basic dependency package: The business image uses the basic dependency package as the basic image layer and the business jar package as the application image layer.
[0037] Step S2 comprises the steps of: S21. Obtain code according to the source code version, and build the business jar package through Maven based on preconfigured building parameters; S22. According to the constructed business jar package and the existing basic dependency package, a Docker image is generated based on Docker's image layering technology to obtain a business image.
[0038] In this embodiment, the code is pulled from Gitlab and Maven is used for code construction. In this step, the construction parameters have been configured to ensure that the construction product is only the business jar package, achieving the purpose of lightweight release.
[0039] Generate a business image from the build product. The image will be built based on the existing basic dependency packages. With the help of Docker's image layering technology, it is ensured that the dependency packages are only pulled once to save the network and time consumption caused by frequent transmission of dependency parts. Provide a version number for the business image.
[0040] Submit the source code version to the Gitlab repository to form a release version record.
[0041] S3: Upload the business image, the business version and the deployment environment to the cloud management platform, and trigger a deployment event corresponding to the deployment environment.
[0042] In this embodiment, the service image, service version, and deployment environment are submitted to the cloud management platform, and a deployment event corresponding to the deployment environment is triggered (ie, a deployment event is triggered to the local management platform of the deployment end corresponding to the deployment environment).
[0043] Send a deployment completion notification to the corresponding personnel, along with the deployment results.
[0044] Please refer to Figure 2 and Figure 3 , Embodiment 2 of the present invention is: In this embodiment, the deployment steps of the local management platform of the deployment end after the publishing end triggers the deployment event are described.
[0045] An automatic deployment method based on Jenkins and Docker, including the following steps: S1. Receive a deployment event corresponding to the current deployment environment, and obtain a new version of the business image from the cloud management platform. If the basic image layer already exists locally, only the application image layer in the business image needs to be obtained; The deployment event is triggered based on an automatic publishing method based on Jenkins and Docker described in the first embodiment above.
[0046] The cloud management platform is configured with different environment keys for different deployment environments; Step S1 is specifically as follows: Upon receiving a deployment event corresponding to the current deployment environment, the cloud management platform is asked to obtain a new version of the business image by carrying the environment key of the current environment. The cloud management platform verifies the environment key and returns the business version of the new version of the business image. The business image is obtained from the Docker repository of the cloud management platform according to the business version. When the basic image layer already exists locally, only the application image layer in the business image needs to be obtained.
[0047] In this embodiment, after the deployment event is triggered, the latest version information is requested from the cloud management platform through the local management platform. In order to ensure security and distinguish the environment, this step needs to carry the key of the environment.
[0048] Get the version number (business version) of the new version and the business image download address, and then pull the business image.
[0049] S2. Call Docker to start the new version of the business image as a new Docker container, and read the preset functional environment parameters and pass them to the Docker container; The function environment parameters include a database address and functions that are allowed to be accessed.
[0050] In this embodiment, the Docker container of the old version of the service is stopped, and the set functional environment variables, such as the addresses of mysql and redis, and the functions allowed to be accessed, are read.
[0051] The local management platform calls Docker to start the new version of the business image as a new container, and provides the environment parameters read from the previous step, passing the environment parameters to the container as an environment variable (such as docker run -itd -eMYSQL=192.168.4.51:3306 -e REDIS=192.168.4.52:6379 -e USER_REGIST=falsebusiness:1.1; XX=YY after the -e parameter represents the environment parameter).
[0052] In this embodiment, the environment of the customer's deployment end is difficult to control, which is reflected in the following aspects: For example, published packages are often used for: Operating system: Ubuntu 20.04 (may also be 18.04, 22.04, the actual difference is not big); Architecture: x86_64 (or AMD64, both are different names for the same architecture); Java: 8 (or 1.8, just a different name).
[0053] The deployment environment may be: Operating system: It may be Debian, Red Hat, CentOS, Windows, macOS, but the specific version is more difficult to guarantee; Architecture: may be x86_32, arm, RISC-V; At the same time, the deployment environment may not necessarily contain Java programs, or may only contain Java 6, 11, 17, 21, and other versions.
[0054] In this embodiment, a basic dependency package is provided in the business image through Docker image layering technology. The basic dependency package includes the specified operating system Ubuntu18.04 and the specified Java8. When the image is started as a container, no matter what the environment outside the image is, the system inside the image must be a specified system. The difference in architecture can also be achieved by registering qemu to docker to start heterogeneous containers.
[0055] S3. Start the new version of the Docker container to start the business program; Step S3 is specifically as follows: The new version of the Docker container is started to run the entry script, and the entry script reads the functional environment variables and starts the business program.
[0056] In this embodiment, the container starts and executes the entrypoint script, which reads the environment variables and starts the business program. After the business program starts, it reads and uses other environment variables.
[0057] Please refer to Figure 4 , Embodiment 3 of the present invention is: An automatic publishing terminal 1 based on Jenkins and Docker includes a first processor 2, a first memory 3, and a first computer program stored in the first memory 3 and executable on the first processor 2. When the first computer program is executed, the steps of the automatic publishing method based on Jenkins and Docker described in the first embodiment are implemented.
[0058] Please refer to Figure 5 , Embodiment 4 of the present invention is: An automatic deployment terminal 4 based on Jenkins and Docker includes a second processor 5, a second memory 6, and a second computer program stored in the second memory 6 and executable on the second processor 5. When the second computer program is executed, the steps of the automatic deployment method based on Jenkins and Docker described in the above embodiment 2 are implemented.
[0059] Please refer to Figure 6 , Embodiment 5 of the present invention is: An automatic deployment system 7 based on Jenkins and Docker, comprising a publishing terminal 9, a deployment terminal 10 and a cloud management platform 8; And the steps of the automatic publishing method based on Jenkins and Docker described in the above embodiment 1 are implemented through the publishing terminal 9; The steps of the automatic deployment method based on Jenkins and Docker described in the above embodiment 2 are implemented through the deployment terminal 10.
[0060] To sum up, the automatic publishing and deployment method and system based on Jenkins and Docker provided by the present invention manage business image versions through a cloud management platform. At the same time, the business image is implemented based on Docker image layering technology to ensure that the dependent package only needs to be downloaded once and there is only one copy. At the same time, the Docker container environment is isolated from the external environment to avoid problems caused by differences in customer environments.
[0061] The above descriptions are merely embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent transformations made using the contents of the present invention's specification and drawings, or directly or indirectly applied in related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. An automatic publishing method based on Jenkins and Docker, characterized in that: Use Jenkins to build an automated release process, which includes the following steps: S1. Obtain the source code version, business version and deployment environment to be built; S2. Obtain code according to the source code version, and generate a business image based on Maven and Docker image layering technology, where the business image includes a business jar package and basic dependency packages; S3: Upload the business image, the business version and the deployment environment to the cloud management platform, and trigger a deployment event corresponding to the deployment environment.
2. According to the automatic publishing method based on Jenkins and Docker according to claim 1, it is characterized in that: Step S2 comprises the steps of: S21. Obtain code according to the source code version, and build the business jar package through Maven based on preconfigured building parameters; S22. According to the constructed business jar package and the existing basic dependency package, a Docker image is generated based on Docker's image layering technology to obtain a business image.
3. According to the automatic publishing method based on Jenkins and Docker according to claim 1, it is characterized in that: The business image contains the business jar package and basic dependency package: The business image uses the basic dependency package as the basic image layer and the business jar package as the application image layer.
4. An automatic deployment method based on Jenkins and Docker, characterized in that: Includes steps: S1. Receive a deployment event corresponding to the current deployment environment, and obtain a new version of the business image from the cloud management platform. If the basic image layer already exists locally, only the application image layer in the business image needs to be obtained; The deployment event is triggered based on an automatic publishing method based on Jenkins and Docker as described in any one of claims 1 to 3 above; S2. Call Docker to start the new version of the business image as a new Docker container, and read the preset functional environment parameters and pass them to the Docker container; S3. Start the new version of the Docker container to start the business program.
5. The automatic deployment method based on Jenkins and Docker according to claim 4, characterized in that: The function environment parameters include a database address and functions that are allowed to be accessed.
6. The automatic deployment method based on Jenkins and Docker according to claim 4, characterized in that: Step S3 is specifically as follows: The new version of the Docker container is started to run the entry script, and the entry script reads the functional environment variables and starts the business program.
7. The automatic deployment method based on Jenkins and Docker according to claim 4, characterized in that: The cloud management platform is configured with different environment keys for different deployment environments; Step S1 is specifically as follows: Upon receiving a deployment event corresponding to the current deployment environment, the cloud management platform is asked to obtain a new version of the business image by carrying the environment key of the current environment. The cloud management platform verifies the environment key and returns the business version of the new version of the business image. The business image is obtained from the Docker repository of the cloud management platform according to the business version. When the basic image layer already exists locally, only the application image layer in the business image needs to be obtained.
8. An automatic publishing terminal based on Jenkins and Docker, comprising a first processor, a first memory, and a first computer program stored in the first memory and executable on the first processor, characterized in that: When the first computer program is executed, the steps of the automatic publishing method based on Jenkins and Docker described in any one of claims 1 to 3 are implemented.
9. An automatic deployment terminal based on Jenkins and Docker, comprising a second processor, a second memory, and a second computer program stored in the second memory and executable on the second processor, characterized in that: When the second computer program is executed, the steps of the automatic deployment method based on Jenkins and Docker described in any one of claims 4 to 7 are implemented.
10. An automatic deployment system based on Jenkins and Docker, characterized in that: Includes publishing end, deployment end and cloud management platform; And the steps in the automatic publishing method based on Jenkins and Docker described in any one of claims 1 to 3 above are implemented through the publishing end; The steps in the automatic deployment method based on Jenkins and Docker described in any one of claims 4 to 7 above are implemented through the deployment end.
Citation Information
Patent Citations
A micro-service packaging deployment method and system
CN109634657A
Docker-based devops continuous delivery and automation system and method
CN115981673A
Platform automatic deployment updating method and device, equipment and medium
CN118535188A
Enhanced cloud-computing environment deployment
US20230244466A1