Paramiko-based automatic compiling and deploying method

Automatic compilation and deployment is achieved through the Paramiko library, solving the problem of inefficiency of traditional manual deployment methods and achieving efficient and stable project development and operation and maintenance processes.

CN120295635APending Publication Date: 2025-07-11SHENZHEN LANYOU TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510411155.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-02
Publication Date
2025-07-11

AI Technical Summary

Technical Problem

Traditional manual deployment methods are inefficient and error-prone, resulting in the project deployment process being time-consuming and risky, and cannot meet the efficient development and operation and maintenance needs of complex projects.

Method used

The automated compilation and deployment method based on Paramiko is adopted to realize remote operations of the compilation server and the deployment server through SSH and SFTP protocols, including uploading, decompressing, compiling, downloading of package files and process management of the deployment server to ensure automated and efficient process execution.

Benefits of technology

It significantly improves development and operation and maintenance efficiency, reduces human operation errors, optimizes the deployment process, improves the accuracy and stability of the project, and shortens the project cycle.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120295635A_ABST
    Figure CN120295635A_ABST
Patent Text Reader

Abstract

The invention provides an automatic compiling and deploying method based on Paramiko, which comprises the following steps: S1, establishing connection between a Paramiko library and a compiling server through an SSH protocol, obtaining a to-be-compiled source code packet, reading a local source code packet path and a compiling server target directory path through a configuration file, and uploading the source code packet to the compiling server; s2, executing a decompression command on the compiling server; and remotely operating the compiling server and the deployment server by utilizing an SSH protocol. The method comprises the following steps of: connecting a compiling server through an automatic script to finish compiling tasks such as uploading a source code packet, executing a compiling command and downloading a compiling packet file; and then a deployment server is connected to realize compiling package file uploading, deployment operation and comprehensive management of processes, for example, an old process is stopped in time and a new process is started. Omnibearing automation of compiling, deployment and process management is achieved in the whole process, the development and operation and maintenance efficiency is greatly improved, and the probability of manual operation errors is effectively reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of artificial intelligence, and more specifically, to an automated compilation and deployment method based on Paramiko.

[0002] As the complexity of projects continues to increase, the number of modules to be deployed in the test environment is also increasing day by day. The traditional manual deployment method gradually exposes problems of low efficiency and high error rates. In the current process, updating or deploying modules usually requires manually executing operations one by one according to the deployment manual. When the number of modules involved is small, manually executing compilation and deployment commands is relatively simple and straightforward. However, as the project structure becomes more complex, the deployment work in the test environment also becomes more cumbersome and time-consuming. Compiling and deploying each module requires a large amount of man-hours.

[0003] This repetitive and cumbersome work mode not only consumes valuable time resources, but also increases the risk of deployment failure or system anomalies due to human operation errors. Relying on the method of manual input or copying commands is both time-consuming and error-prone, making the entire deployment process neither efficient nor reliable. The existing technical solutions mainly rely on manual execution of compilation and deployment operations step by step. This method requires a large amount of human and time costs, seriously reducing work efficiency, and due to the uncertainty of manual operations, increasing the possibility of errors during the deployment process.

[0004] Therefore, developing an automated compilation and deployment method based on Paramiko has become an important technical requirement today. Summary of the Invention

[0005] The technical problem to be solved by the present invention is to provide an automated compilation and deployment method based on Paramiko that improves development and operation and maintenance efficiency and reduces the possibility of human operation errors in view of the deficiencies in the above technical solutions.

[0006] The present invention provides an automated compilation and deployment method based on Paramiko, and the method includes the following steps:

[0007] S1, establish a connection between the Paramiko library and the compilation server through the SSH protocol, obtain the source code package to be compiled, read the local source code package path and the target directory path of the compilation server through the configuration file, and upload the source code package to the compilation server;

[0008] S2, execute an extraction command on the compilation server, extract the source code package and store it in a specified directory, perform a compilation command operation on the extracted source code package to obtain a successfully compiled compilation package, and download the compilation package file from the compilation server through the SFTP protocol and store it locally;

[0009] S3. Establish an SSH connection between the Paramiko library and the deployment server through the SSH protocol, read the local compilation package file path and the target directory path of the deployment server from the configuration file, and upload the compilation package file to the deployment server through the SFTP protocol;

[0010] S4. Back up the old version of the compilation package file on the deployment server to the backup deployment directory, and replace the old version of the compilation package file with the new version of the compilation package file;

[0011] S5. Delete the processes deployed on the deployment server, restart the new processes, and verify the deployment status.

[0012] In the automated compilation and deployment method based on Paramiko of the present invention; the step S2 includes the following steps:

[0013] S21. Execute the decompression command on the compilation server, where the format of the source code package is.zip or.tar.gz, and select the decompression tool unzip or tar according to the source code package format to decompress the source code package and store it in the specified directory.

[0014] In the automated compilation and deployment method based on Paramiko of the present invention; the step S2 further includes the following steps:

[0015] S22. According to different development languages or build tools, execute the corresponding compilation command operations to obtain a successfully compiled compilation package file.

[0016] In the automated compilation and deployment method based on Paramiko of the present invention; the step S2 further includes the following steps:

[0017] S23. Determine the path of the compilation package file on the compilation server and the local storage path through the configuration file; use the SFTPClient class of the Paramiko library to download the compilation package file from the compilation server to the local through the SFTP protocol.

[0018] In the automated compilation and deployment method based on Paramiko of the present invention; the step S4 includes the following steps:

[0019] S41. Check whether the old version of the compilation package file exists in the deployment directory of the deployment server; if it exists, create a backup deployment directory and copy or move the old version of the compilation package file to the backup deployment directory.

[0020] In the automated compilation and deployment method based on Paramiko of the present invention; the step S4 further includes the following steps:

[0021] S42. Copy the new version of the compilation package file to the backup deployment directory to replace the old version of the compilation package file, and set the permissions of the new version of the compilation package file to be the same as those of the old version of the compilation package file.

[0022] In the automated compilation and deployment method based on Paramiko of the present invention; the step S5 includes the following steps:

[0023] S51. Before deploying the new version of the compilation package file, use pkill -f application name or process name to stop the process of the old version of the compilation package file; start the new process of the new version of the compilation package file, and use the ps or top command to check whether the new process runs successfully. If the new process does not run successfully, trigger an alarm and record the error log.

[0024] The automated compilation and deployment method based on Paramiko of the present invention uses the SSH protocol to remotely operate the compilation server and the deployment server. Through the automated script, first connect to the compilation server to complete compilation tasks such as uploading the source code package, executing the compilation command, and downloading the compilation package file; then connect to the deployment server to implement the upload, deployment operation, and overall management of the process of the compilation package file, such as stopping the old process in time and starting the new process. The entire process achieves the full automation of compilation, deployment, and process management, greatly improving the development and operation and maintenance efficiency, and effectively reducing the probability of human operation errors. Description of the Drawings

[0025] Figure 1 is a schematic flowchart of the automated compilation and deployment method based on Paramiko of the present invention. Detailed Embodiments

[0026] In order to make the objectives, technical solutions, and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.

[0027] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects and do not necessarily need to describe a specific order or sequence. It should be understood that such used data can be interchanged under appropriate circumstances so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, application, product, or device that includes a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products, or devices.

[0028] As Figure 1 shown Figure 1

[0029] Figure 4 is a schematic flowchart of an embodiment of the automated compilation and deployment method based on Paramiko of the present invention. A method for automated compilation and deployment based on Paramiko is provided, including the following steps:

[0029] In step S1, a connection between the Paramiko library and the compilation server is established through the SSH protocol, the source code package to be compiled is obtained, the local source code package path and the target directory path of the compilation server are read through the configuration file, and the source code package is uploaded to the compilation server;

[0030] In step S2, an extraction command is executed on the compilation server, the source code package is extracted and stored in a specified directory after extraction, and a compilation command operation is performed on the extracted source code package to obtain a successfully compiled compilation package, and the compilation package file is downloaded from the compilation server through the SFTP protocol and stored locally;

[0031] In step S3, an SSH connection between the Paramiko library and the deployment server is established through the SSH protocol, the local compilation package file path and the target directory path of the deployment server are read through the configuration file, and the compilation package file is uploaded to the deployment server through the SFTP protocol;

[0032] In step S4, the old version of the compilation package file on the deployment server is backed up to the backup deployment directory, and the old version of the compilation package file is replaced with the new version of the compilation package file;

[0033] In step S5, the deployed process on the deployment server is deleted, a new process is restarted, and the deployment status is verified.

[0034] In this embodiment, step S2 includes the following steps:

[0035] In step S21, an extraction command is executed on the compilation server, where the format of the source code package is.zip or.tar.gz, and the extraction tool unzip or tar is selected according to the source code package format to extract the source code package and store it in a specified directory.

[0036] In this embodiment, step S2 further includes the following steps:

[0037] In step S22, according to different development languages or build tools, corresponding compilation command operations are executed to obtain a successfully compiled compilation package file.

[0038] In this embodiment, step S2 further includes the following steps:

[0039] In step S23, determine the path of the compilation package file on the compilation server and the local storage path through the configuration file; use the SFTPClient class of the Paramiko library to download the compilation package file from the compilation server to the local through the SFTP protocol.

[0040] In this embodiment, step S4 includes the following steps:

[0041] In step S41, check whether the old version compilation package file exists in the deployment directory of the deployment server; if it exists, create a backup deployment directory and copy or move the old version compilation package file to the backup deployment directory.

[0042] In this embodiment, step S4 further includes the following steps:

[0043] In step S42, copy the new version compilation package file to the backup deployment directory to replace the old version compilation package file, and set the permissions of the new version compilation package file to be the same as those of the old version compilation package file.

[0044] In this embodiment, step S5 includes the following steps:

[0045] In step S51, before deploying the new version compilation package file, use pkill -f application name or process name to stop the process of the old version compilation package file; start the new process of the new version compilation package file, and use the ps or top command to check whether the new process runs successfully. If the new process does not run successfully, trigger an alarm and record the error log.

[0046] Specifically, the present invention is specifically designed for the compilation and deployment processes of the front - end and back - end modules, with high adaptability and professionalism. By using automated scripts, remote connection and operation of the compilation server and the deployment server are realized, and a series of key links such as file upload, code compilation, product download, and system deployment are accurately and efficiently completed. This measure greatly optimizes the deployment process of the test environment, significantly improves the deployment efficiency, and shortens the project cycle.

[0047] In addition, artificial intelligence technology can also be combined and deeply integrated into the deployment process. With its powerful data analysis and intelligent decision - making capabilities, artificial intelligence can automatically adjust the deployment strategy according to the real - time needs and environmental changes of the project, further enhancing the intelligent level of the deployment process. This not only improves the accuracy and stability of the deployment, but also provides comprehensive and powerful support for the efficient development and operation and maintenance of the project, ensuring that the project always maintains an efficient and stable running state during the rapid iteration process.

[0048] To achieve the automated compilation and deployment of the project, we can utilize the paramiko library in Python to perform remote operations on the compilation server and the deployment server. The following are the detailed operation steps:

[0049] Environmental preparation steps; Before starting the operation, it is necessary to ensure whether the paramiko library is installed. If not installed, the following command can be used for installation: pip install paramiko; Import the library, import the paramiko library in the Python script: import paramiko; Create an SSH client object using paramiko.SSHClient(), automatically accept the host key. To automatically handle the host key verification during the first connection, the automatic acceptance policy can be set: ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()). Read the IP address, port, username, and password of the compilation server from the configuration file, and then use the connect() method to connect to the compilation server..

[0050] Create an SFTP client using the created SSH client object, and upload the local source code package to the compilation server via the SFTP protocol. Read the local source code package path and the compilation server target directory path from the configuration file. Create an SFTP client: sftp = ssh_client.open_sftp(); Upload the source code package to the compilation server: sftp.put(local_file_path, remote_file_path). It is necessary to ensure that local_file_path is the correct path of the local source code package, and ensure that remote_file_path is the correct path of the target directory on the compilation server; both of these paths can be read from the configuration file.

[0051] On the compilation server, use the command-line tool to extract the source file package from the compressed format (such as.zip or.tar.gz) to the specified directory. The purpose is to facilitate subsequent compilation operations. This process can be automated through the command-line tool (such as unzip or tar). The following are examples of extraction for different compressed formats: For example, extract the.zip file source_code.zip to the directory / app / source: For example, extract the.tar.gz file source_code.tar.gz to the directory / app / source; For example, extract the.tar.gz file source_code.tar.gz to the directory / app / source: tar -xzvf source_code.tar.gz -C / app / source.

[0052] On the compilation server, ensure to switch to the directory where the source code package file is stored. This can be achieved through the following command: cd / path / to / source / code; Depending on different development languages or build tools, there can be different compilation commands. For example:

[0053] Front-end projects (such as projects based on Node.js and npm): npm run build; After executing the above command, compiled static resource files are usually generated in the dist directory.

[0054] Back-end projects (such as projects based on the Go language): go build -o main; After executing this command, an executable file main will be generated.

[0055] During the compilation process, the compilation tool will generate a compilation package file in the specified directory. It is necessary to clarify the file path and file name of the compilation package. For example: After compiling a front-end project, a dist folder may be generated. After compiling a back-end project, an executable file (such as app or main) may be generated. Use the SFTPClient class of the paramiko library to download the compilation package file from the compilation server via the SFTP protocol; On the compilation server, the compilation package file is usually located in a specific directory. This path needs to be specified as the source path for SFTP download. Use the get() method of SFTPClient to download the compilation package file from the compilation server to the local specified path. Both of these paths can be read from the configuration file.

[0056] Repeat the environment preparation steps, create an SSH client object again and set the automatic host key acceptance policy. Read the IP address, port, username, and password of the deployment server from the configuration file, and then connect to the deployment server.

[0057] Use the paramiko library to create an SFTP client and upload the compilation package file to the deployment server via the SFTP protocol. Create an SFTP client: sftp = ssh_client.open_sftp(); Upload the compilation package to the deployment server: sftp.put(local_file_path, remote_file_path). It is necessary to ensure that local_file_path is the correct path of the local compilation package and remote_file_path is the correct path of the target directory on the deployment server; Both of these paths can be placed in the configuration file for reading.

[0058] Before deploying the new version of the compilation package file, it is necessary to back up the old version of the compilation package file. First, check whether there is an old version of the compilation package file in the backup deployment directory. If it exists, create a backup deployment directory and move or copy the old package to the backup deployment directory. Finally, copy the new version of the compilation package file to the backup deployment directory to replace the old version of the compilation package file, and ensure that the file permissions of the new deployment package are the same as those of the old package, aiming to avoid deployment failures caused by permission issues.

[0059] If it is a front-end deployment, usually the deployment can be completed after replacing the new version of the compilation package file. For example, after the front-end static resources are deployed, the front-end page can be directly accessed.

[0060] Before deploying the new version, it is necessary to ensure that the process of the old version of the compilation package file has stopped. The implementation method is to use pkill -f application name or process name. According to your deployment requirements, start the process of the new version. After starting the process, it is necessary to check whether the new process is running successfully. Use the ps or top command to check whether the process is running, such as: ps -aux | grep application name. Through the above steps, the automated compilation and deployment of the project can be realized, improving the development and operation and maintenance efficiency and reducing human operation errors.

[0061] The beneficial effects of an automated compilation and deployment method based on Paramiko provided by an embodiment of the present invention are at least as follows:

[0062] 1. In the scenario where there are a large number of compilation packages, the present invention significantly reduces the probability of human operation errors and improves the accuracy and stability of operations.

[0063] 2. By enhancing the intelligence of the test environment deployment, the present invention effectively improves the work efficiency of the project in the whole process of development, testing, compilation and deployment, making the project progress more efficiently and smoothly.

[0064] 3. The present invention greatly reduces the compilation and deployment costs during the update of the test environment. With just one key operation, the compilation, deployment and update of the environment can be quickly completed, realizing the optimal utilization of resources.

[0065] It should be noted that for the foregoing method embodiments, for the sake of simple description, they are all expressed as a series of action combinations. However, those skilled in the art should know that the present invention is not limited by the described action sequence, because according to the present invention, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to the present invention.

[0066] Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be implemented by means of software plus a necessary general hardware platform. Of course, it can also be implemented by hardware, but in many cases the former is a better implementation. Based on such an understanding, the technical solution of the present invention, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions for causing a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in various embodiments of the present invention.

[0067] Therefore, as described above, the above are only the preferred specific embodiments of the present invention, and the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by those skilled in the art within the technical scope disclosed by the present invention should be covered by the protection scope of the present invention. The protection scope of the present invention should be subject to the protection scope of the claims.

Claims

1. An automated compilation and deployment method based on Paramiko, characterized in that The method includes the following steps: S1. Establish a connection between the Paramiko library and the compilation server through the SSH protocol, obtain the source code package to be compiled, read the local source code package path and the target directory path of the compilation server through the configuration file, and upload the source code package to the compilation server; S2. Execute the decompression command on the compilation server, decompress the source code package and store it in the specified directory, perform compilation command operations on the decompressed source code package to obtain a successfully compiled compilation package, and download the compilation package file from the compilation server through the SFTP protocol and store it locally; S3. Establish an SSH connection between the Paramiko library and the deployment server through the SSH protocol, read the local compilation package file path and the target directory path of the deployment server through the configuration file, and upload the compilation package file to the deployment server through the SFTP protocol; S4. Back up the old version of the compilation package file on the deployment server to the backup deployment directory, and replace the old version of the compilation package file with the new version of the compilation package file; S5. Delete the deployed process on the deployment server, restart the new process, and verify the deployment status.

2. The automated compilation and deployment method based on Paramiko according to claim 1, characterized in that, The step S2 includes the following steps: S21. Execute the decompression command on the compilation server, where the format of the source code package is.zip or.tar.gz, and select the decompression tool unzip or tar according to the source code package format to decompress the source code package and store it in the specified directory.

3. The automated compilation and deployment method based on Paramiko according to claim 2, wherein The step S2 further includes the following steps: S22. Execute corresponding compilation command operations according to different development languages or build tools to obtain a successfully compiled compilation package file.

4. The automated compilation and deployment method based on Paramiko according to claim 3, characterized in that The step S2 further includes the following steps: S23. Determine the path of the compilation package file on the compilation server and the local storage path through the configuration file; use the SFTPClient class of the Paramiko library to download the compilation package file from the compilation server to the local through the SFTP protocol.

5. The automated compilation and deployment method based on Paramiko according to claim 4, characterized in that The step S4 includes the following steps: S41. Check whether the old version of the compilation package file exists in the deployment directory of the deployment server; if it exists, create a backup deployment directory and copy or move the old version of the compilation package file to the backup deployment directory.

6. The automated compilation and deployment method based on Paramiko according to claim 5, characterized in that The step S4 further includes the following steps: S42. Copy the new version of the compilation package file to the backup deployment directory to replace the old version of the compilation package file, and set the permissions of the new version of the compilation package file to be the same as those of the old version of the compilation package file.

7. The automated compilation and deployment method based on Paramiko according to claim 6, characterized in that The step S5 includes the following steps: S51. Before deploying the new version of the compilation package file, use pkill -f application name or process name to stop the process of the old version of the compilation package file; start the new process of the new version of the compilation package file, and use the ps or top command to check whether the new process runs successfully. If the new process does not run successfully, trigger an alarm and record the error log.