Isolation compiling environment construction method and device, equipment and storage medium

By building an isolated compilation environment using Docker container technology, the problems of build conflicts and complex dependency management in multi-developer collaboration are solved, enabling rapid setup and consistency of the development environment and improving the management efficiency of the software development lifecycle.

CN118885175APending Publication Date: 2024-11-01SHANGHAI DONGPU INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410953036.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-16
Publication Date
2024-11-01

AI Technical Summary

Technical Problem

Existing front-end build tools are prone to build conflicts in multi-developer collaborative environments, have complex dependency management, resulting in low development efficiency and difficulty in ensuring environment consistency.

Method used

By using Docker container technology, an isolated compilation environment is built, project and dependency information is obtained to create a Dockerfile, Docker containers are built, and port mapping and configuration tools are integrated to ensure the consistency and maintainability of the development environment.

Benefits of technology

It enables rapid setup and high consistency of the development environment, reduces productivity losses caused by environmental differences, promotes the standardization of the development process and continuous integration/continuous deployment, and improves the management efficiency of the software development lifecycle.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118885175A_ABST
    Figure CN118885175A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of data processing, in particular to an isolation compiling environment construction method and device, equipment and a storage medium, and the method comprises the following steps: obtaining project information and dependency information to create a Dockerfile; a Docker basic mirror image is obtained, and a Docker container is constructed on the basis of the Docker file and the Docker basic mirror image; obtaining network configuration information of a host, so as to carry out port mapping on the constructed Docker container; compiling script information of the configuration tool, and integrating the script information into a Docker container; configuration command information of the configuration tool and container command information of the Docker isolation container are obtained and packaged, a packaged script is obtained, the packaged script is packaged into the Docker container, and the Docker isolation container is obtained; according to the method disclosed by the invention, rapid establishment of the development environment can be realized, high consistency and easy maintainability of the plurality of established development environments can be ensured, productivity loss caused by environment difference is solved, and data support is provided for efficient management and quality improvement of the software development life cycle.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data processing technology, and in particular to a method, device, equipment and storage medium for constructing an isolated compilation environment. Background Art

[0002] As the complexity of web applications continues to rise, front-end development is facing increasingly severe challenges; with multiple development teams working in parallel, code conflicts, build conflicts, and dependency management issues are common.

[0003] Although current front-end build tools (such as Webpack, Parcel, etc.) have alleviated these problems to a certain extent, there are still the following significant deficiencies that need to be addressed:

[0004] 1. Build conflicts: When multiple developers edit the same code segment at the same time and try to build it, build conflicts frequently occur, seriously affecting development efficiency.

[0005] 2. Dependency management: Complex dependencies not only make the build process time-consuming, but also increase the difficulty of debugging, posing a threat to the stability and maintainability of the project.

[0006] 3. Environmental consistency: It is difficult to maintain consistency between the development environment and the production environment, resulting in the dilemma of "local operation is normal, but problems arise after deployment", which brings great inconvenience to project deployment and operation and maintenance.

[0007] It can be seen that the existing technology still needs to be improved and enhanced. Summary of the invention

[0008] In order to overcome the shortcomings of the prior art, the purpose of the present invention is to provide an isolated compilation environment construction method, device, equipment and storage medium, which can realize the rapid construction of a development environment and ensure the high consistency and easy maintainability of the multiple development environments constructed.

[0009] A first aspect of the present invention provides a method for building an isolated compilation environment, including: obtaining project information and dependency information, creating a Dockerfile based on the obtained project information and dependency information; obtaining a Docker base image, building a Docker container based on the created Dockerfile and the obtained Docker base image; obtaining the host's network configuration information, and performing port mapping on the constructed Docker container according to the obtained network configuration information; writing script information of a configuration tool, and integrating the script information into the constructed Docker container; obtaining configuration command information of the configuration tool and container command information of the Docker isolated container, encapsulating the configuration command information and the container command information to obtain an encapsulation script, and packaging the encapsulation script into the constructed Docker container to obtain a Docker isolated container.

[0010] Optionally, in a first implementation of the first aspect of the present invention, the obtaining of project information and dependency information, and creating a Dockerfile based on the obtained project information and dependency information specifically includes: initializing an npm project to obtain project information, wherein the project information includes a package.json file; obtaining dependency information, installing the dependencies in a node_modules folder of the npm project according to the dependency information, and adding corresponding entries to the package.json file, wherein the added entries are precise version numbers corresponding to the dependencies, to obtain a complete npm project; based on the complete npm project, creating a Dockerfile in the project root directory.

[0011] Optionally, in a second implementation of the first aspect of the present invention, obtaining a Docker base image and building a Docker container based on the created Dockerfile and the obtained Docker base image specifically includes: obtaining a Docker base image, wherein the Docker base image is the official node.js; setting a label for the Docker base image to obtain a Docker container image; running the docker build command in the project root directory, building a Docker container according to the created Dockerfile and the Docker container image, and setting basic information of the Docker container.

[0012] Optionally, in a third implementation of the first aspect of the present invention, setting the basic information of the Docker container specifically includes: using the docker run command to run the Docker container to set the basic parameters of the Docker container, the basic parameters including the name, background running parameters and automatic restart parameters; using the docker exec -it <container name> / bin / bash command to enter the terminal of the Docker container, and perform basic configuration and initialization operations on the Docker container; setting periodic tasks, and backing up the Docker container image and Docker container based on the periodic tasks.

[0013] Optionally, in a fourth implementation of the first aspect of the present invention, the obtaining of the host's network configuration information and performing port mapping on the constructed Docker container according to the obtained network configuration information specifically include: obtaining the host's network configuration information, wherein the host's network configuration information includes a host routing table; obtaining the Docker container's network configuration information, wherein the Docker container's network configuration information includes a container IP address; retrieving the host routing table based on the container IP address to determine whether the container IP address is in the routing table; if so, configuring the Compose file of Docker Compose, and performing port mapping on the Docker container based on the configured Compose file.

[0014] Optionally, in a fifth implementation of the first aspect of the present invention, the writing of script information of the configuration tool and integrating the script information into the constructed Docker container specifically includes: writing script information of the Ansible configuration tool, wherein the script information is used to set the host name, install software packages, configure network settings, and manage users; installing the Ansible configuration tool in the Docker container; and copying the script information of the Ansible configuration tool to the ansible subdirectory of the directory where the Docker container is located, so as to integrate the script information into the constructed Docker container.

[0015] Optionally, in a sixth implementation of the first aspect of the present invention, the configuration command information of the configuration tool and the container command information of the Docker isolated container are obtained, the configuration command information and the container command information are encapsulated to obtain a packaging script, and the packaging script is packaged into the constructed Docker container to obtain the Docker isolated container, specifically including: obtaining the configuration command information of the configuration tool, the configuration command information including application configuration file commands and management node commands; obtaining the container command information of the Docker isolated container, the container command information including a start command, a stop command and a rebuild command; writing a Shell script based on the obtained configuration command information and container command information, and setting the name of the Shell script to obtain a packaging script; packaging the packaging script into the constructed Docker container to obtain a Docker isolated container.

[0016] A second aspect of the present invention provides an isolated compilation environment construction device, including: a creation module, which is used to obtain project information and dependency information, and create a Dockerfile based on the obtained project information and dependency information; a construction module, which is used to obtain a Docker base image, and build a Docker container based on the created Dockerfile and the obtained Docker base image; a mapping module, which is used to obtain the network configuration information of the host, and perform port mapping on the constructed Docker container according to the obtained network configuration information; an integration module, which is used to write script information of a configuration tool, and integrate the script information into the constructed Docker container; an encapsulation module, which obtains the configuration command information of the configuration tool and the container command information of the Docker isolated container, encapsulates the configuration command information and the container command information to obtain an encapsulation script, and packages the encapsulation script into the constructed Docker container to obtain a Docker isolated container.

[0017] Optionally, in a first implementation method of the second aspect of the present invention, the creation module includes: an initialization unit, used to initialize the npm project and obtain project information, wherein the project information includes a package.json file; a first acquisition unit, used to obtain dependency information, install the dependencies in the node_modules folder of the npm project according to the dependency information, and add corresponding entries to the package.json file, wherein the added entries are precise version numbers corresponding to the dependencies, to obtain a complete npm project; and a creation unit, used to create a Dockerfile in the project root directory based on the complete npm project.

[0018] Optionally, in a second implementation method of the second aspect of the present invention, the building module includes: a second acquisition unit, used to obtain a Docker base image, wherein the Docker base image is the official node.js; a first setting unit, used to set a label for the Docker base image to obtain a Docker container image; a building unit, used to run the docker build command in the project root directory, build a Docker container according to the created Dockerfile and the Docker container image, and set the basic information of the Docker container.

[0019] Optionally, in a third implementation of the second aspect of the present invention, the building module also includes: an operating unit, used to run the Docker container using the docker run command to set the basic parameters of the Docker container, wherein the basic parameters include the name, background running parameters, and automatic restart parameters; a second setting unit, used to use the docker exec -it <container name> / bin / bash command to enter the terminal of the Docker container and perform basic configuration and initialization operations on the Docker container; a backup unit, used to set periodic tasks and back up the Docker container image and Docker container based on the periodic tasks.

[0020] Optionally, in a fourth implementation of the second aspect of the present invention, the mapping module includes: a third acquisition unit, used to acquire network configuration information of the host, wherein the network configuration information of the host includes a host routing table; a fourth acquisition unit, used to acquire network configuration information of the Docker container, wherein the network configuration information of the Docker container includes a container IP address; a judgment unit, used to retrieve the host routing table based on the container IP address, and determine whether the container IP address is in the routing table; and a mapping unit, used to, if so, configure the Compose file of Docker Compose, and perform port mapping for the Docker container based on the configured Compose file.

[0021] Optionally, in a fifth implementation of the second aspect of the present invention, the integration module includes: a first writing unit, used to write script information of the Ansible configuration tool, wherein the script information is used to set the host name, install the software package, configure the network settings, and manage users; an installation unit, used to install the Ansible configuration tool in the Docker container; and an integration unit, used to copy the script information of the Ansible configuration tool to the ansible subdirectory of the directory where the Docker container is located, so as to integrate the script information into the constructed Docker container.

[0022] Optionally, in a sixth implementation of the second aspect of the present invention, the encapsulation module includes: a fifth acquisition unit, used to obtain configuration command information of the configuration tool, the configuration command information including application configuration file commands and management node commands; a sixth acquisition unit, used to obtain container command information of the Docker isolated container, the container command information including a start command, a stop command and a rebuild command; a second writing unit, used to write a Shell script based on the acquired configuration command information and container command information, and set the name of the Shell script to obtain an encapsulation script; an encapsulation unit, used to package the encapsulation script into the constructed Docker container to obtain a Docker isolated container.

[0023] The third aspect of the present invention provides an isolated compilation environment construction device, which includes: a memory and at least one processor, wherein instructions are stored in the memory; at least one of the processors calls the instructions in the memory so that the isolated compilation environment construction device executes each step of the isolated compilation environment construction method described in any one of the above items.

[0024] A fourth aspect of the present invention provides a computer-readable storage medium having instructions stored thereon, and when the instructions are executed by a processor, the various steps of any of the above-mentioned methods for constructing an isolated compilation environment are implemented.

[0025] In the technical solution of the present invention, a Dockerfile is created by obtaining project information and dependency information; a Docker base image is obtained, and a Docker container is built based on the Dockerfile and the Docker base image; the network configuration information of the host is obtained to perform port mapping for the constructed Docker container; script information of the configuration tool is written, and the script information is integrated into the Docker container; configuration command information of the configuration tool and container command information of the Docker isolated container are obtained and packaged to obtain a packaged script, and the packaged script is packaged into the Docker container to obtain a Docker isolated container; the method disclosed in the present application can realize the rapid construction of a development environment, and can ensure the high consistency and easy maintainability of multiple development environments constructed, solve the productivity loss caused by environmental differences, and provide data support for efficient management and quality improvement of the software development life cycle. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] Figure 1 A first flow chart of a method for constructing an isolated compilation environment provided by an embodiment of the present invention;

[0027] Figure 2 A second flow chart of the method for constructing an isolated compilation environment provided by an embodiment of the present invention;

[0028] Figure 3 A third flow chart of the method for constructing an isolated compilation environment provided by an embodiment of the present invention;

[0029] Figure 4 A fourth flow chart of the method for constructing an isolated compilation environment provided by an embodiment of the present invention;

[0030] Figure 5 A fifth flow chart of the method for constructing an isolated compilation environment provided by an embodiment of the present invention;

[0031] Figure 6 A sixth flow chart of the method for constructing an isolated compilation environment provided by an embodiment of the present invention;

[0032] Figure 7 A seventh flow chart of the method for constructing an isolated compilation environment provided by an embodiment of the present invention;

[0033] Figure 8 A schematic diagram of the structure of an isolated compilation environment construction device provided by an embodiment of the present invention;

[0034] Fig. 9 A schematic diagram of the structure of an isolated compilation environment construction device provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0035] The present invention provides a method, apparatus, device and storage medium for constructing an isolated compilation environment. The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" or "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0036] For ease of understanding, the specific process of the embodiment of the present invention is described below. Figure 1 , an embodiment of the method for constructing an isolated compilation environment in an embodiment of the present invention includes:

[0037] 101. Obtain project information and dependency information, and create a Dockerfile based on the obtained project information and dependency information;

[0038] In this embodiment, Dockerfile is a text file that contains all the commands and configuration information required to build a Docker image; it is usually used to automatically build, release, and run applications; Dockerfile allows users to define the application's base image, environment variables, dependencies, run commands, etc., to ensure that the application can run consistently in different environments.

[0039] 102. Obtain a Docker base image, and build a Docker container based on the created Dockerfile and the obtained Docker base image;

[0040] In this embodiment, the Docker base image can be an operating system image such as Ubuntu, CentOS, etc. These base images provide a basic operating system environment and software packages, making subsequent application deployment simpler and more reliable; a Docker container is an instance of a Docker image. By running the Docker image, one or more Docker containers can be created and applications can be run in them; multiple Docker containers are isolated from each other, and each Docker container has its own file system, network stack, and process space, ensuring the security and portability of the application.

[0041] 103. Obtain network configuration information of the host, and perform port mapping on the constructed Docker container according to the obtained network configuration information;

[0042] In this embodiment, the host is the main control device where the logistics project is located, that is, the control device where the development environment actually used by the development team is located.

[0043] 104. Write the script information of the configuration tool and integrate the script information into the constructed Docker container;

[0044] In this embodiment, the configuration tool is integrated into the constructed Docker container. The configuration tool plays a vital role in software development and operation and maintenance. Specifically, the configuration tool can be used for version control, collaboration support and automated deployment, and has security features such as access control and encryption, which can protect project code and configuration files from unauthorized access or tampering; further, the configuration management tool records all historical changes and provides an auditable way to track and review the project development process.

[0045] 105. Obtain configuration command information of the configuration tool and container command information of the Docker isolated container, encapsulate the configuration command information and the container command information to obtain an encapsulation script, and package the encapsulation script into the constructed Docker container to obtain the Docker isolated container.

[0046] The present application discloses a method for constructing an isolated compilation environment, which obtains project information and dependency information to create a Dockerfile; obtains a Docker base image, and constructs a Docker container based on the Dockerfile and the Docker base image; obtains the network configuration information of the host to perform port mapping for the constructed Docker container; writes script information of a configuration tool, and integrates the script information into the Docker container; obtains configuration command information of the configuration tool and container command information of the Docker isolated container and encapsulates them to obtain an encapsulated script, and packages the encapsulated script into the Docker container to obtain a Docker isolated container; the method disclosed in the present application can realize the rapid construction of a development environment, and can ensure the high consistency and easy maintainability of the multiple development environments constructed, which not only solves the productivity loss caused by environmental differences, but also promotes the standardization of the development process and the deepening of continuous integration / continuous deployment (CI / CD) practices, and provides data support for the efficient management and quality improvement of the software development life cycle, so that more developers can focus on business logic rather than environmental configuration, and accelerate the iteration speed of innovative products.

[0047] See also Figure 2 , a second embodiment of the method for constructing an isolated compilation environment in an embodiment of the present invention includes:

[0048] 201. Initialize the npm project and obtain project information, wherein the project information includes a package.json file;

[0049] 202. Obtain dependency information, install the dependency in the node_modules folder of the npm project according to the dependency information, and add corresponding entries in the package.json file. The added entries are the precise version numbers corresponding to the dependencies, thereby obtaining a complete npm project.

[0050] 203. Based on the improved npm project, create a Dockerfile in the project root directory;

[0051] In this embodiment, npm is the Node Package Manager, the default package manager of Node.js, which is used to download and install the dependency libraries required for the project, and is used to install, manage and publish Node.js modules; the specific version number of each dependency is accurately recorded through the package.json file. Specifically, package.json stores metadata about the Node.js project, including the project name, version, dependencies, etc., to ensure that the same dependency tree is obtained each time the installation is performed, that is, to ensure the consistency of dependencies between team development members and avoid version conflicts; when the build task is executed inside the Docker container, these dependencies are installed to the local directory of the container (such as node_modules), which is completely isolated from the host environment, ensuring the reproducibility of the build results.

[0052] In this embodiment, the project root directory is the starting directory or main directory of the logistics project, which contains all subdirectories, files, code libraries and other related resources of the logistics project; in the project root directory, the core files of the logistics project can be found, such as index.html (for Web projects), main.py (for Python projects) or other startup files; in addition, the project root directory may also contain project configuration files (such as .env, config.json, etc.), documents, dependency files (such as package.json, requirements.txt, etc.) and other files and subdirectories closely related to the project.

[0053] See also Figure 3 , a third embodiment of the method for constructing an isolated compilation environment in an embodiment of the present invention includes:

[0054] 301. Obtain a Docker base image, where the Docker base image is the official node.js.

[0055] In other embodiments, the Docker basic image can also be independently compiled according to the needs of the actual logistics project.

[0056] 302. Set a label for the Docker base image to obtain the Docker container image;

[0057] In this embodiment, a label is set for the Docker base image to facilitate subsequent identification and use.

[0058] 303. Run the docker build command in the project root directory to build a Docker container based on the created Dockerfile and Docker container image, and set the basic information of the Docker container;

[0059] In this embodiment, the basic information of the Docker container includes the container name, background running parameters, automatic restart parameters, etc.

[0060] See also Figure 4 The fourth embodiment of the method for constructing an isolated compilation environment in the embodiment of the present invention includes:

[0061] 401. Run the Docker container using the docker run command to set basic parameters of the Docker container, where the basic parameters include a name, background running parameters, and automatic restart parameters;

[0062] 402. Use the docker exec -it <container name> / bin / bash command to enter the terminal of the Docker container and perform basic configuration and initialization operations on the Docker container;

[0063] In this embodiment, the basic configuration includes setting up a database connection, and the initialization operation includes importing initial data.

[0064] 403. Set up periodic tasks to back up Docker container images and Docker containers based on periodic tasks;

[0065] In this embodiment, the periodic task can be to perform a backup of the Docker container image and the Docker container once a week. Regular backup can prevent data loss or damage, and when the developer changes the machine or needs to continue development on other machines, the Docker environment can be quickly migrated.

[0066] See also Figure 5 The fifth embodiment of the method for constructing an isolated compilation environment in the embodiment of the present invention includes:

[0067] 501. Obtain network configuration information of a host, where the network configuration information of the host includes a host routing table;

[0068] In this embodiment, the network configuration information of the host is used to confirm whether the network interface (such as eth0, wlan0, etc.) on the host is correctly configured and active, and it is confirmed that there are no rules in the firewall settings that prevent the container from communicating with the host. The host routing table is used to ensure that the host has the correct routing entry for the network address segment of the container.

[0069] 502. Obtain network configuration information of the Docker container, where the network configuration information of the Docker container includes a container IP address;

[0070] In this embodiment, by obtaining the network configuration information of the Docker container, confirming the network mode used by the container (such as bridge, host, none, etc.), and understanding the impact of the mode on communication, and checking the IP address of the container to ensure that it is within the network address segment of the host and does not conflict with other devices.

[0071] 503. Retrieve the host routing table based on the container IP address to determine whether the container IP address is in the routing table;

[0072] In this embodiment, if the container IP address is not in the routing table, the Docker container cannot communicate with the host over the network, and an error prompt indicating unsuccessful communication is returned.

[0073] 504. If yes, configure the Compose file of Docker Compose, and perform port mapping for the Docker container based on the configured Compose file;

[0074] In this embodiment, before configuring the Compose file, you can try to ping the IP address of the Docker container from the host to check whether it can respond successfully.

[0075] In this embodiment, Docker Compose is integrated to further enhance the building process of the Docker container. Docker Compose is a tool for defining and running multi-container Docker applications. Through Compose, YAML files can be used to configure the application's services, networks, and volumes, and a single command can be used to start and stop the entire application. In the Compose file, port mapping can be used to map the container's ports to different ports on the host, or port forwarding can be used to allow multiple containers to share the same host port, so that developers can define a set of related services, networks, and volumes, as well as the dependencies between them, to start and stop the entire application stack with one click, greatly simplifying the development and testing process under the microservice architecture. Port mapping allows the Docker container's ports to be mapped to different ports on the host, which means that when a user accesses a port on the host, the traffic will be automatically forwarded to the corresponding port in the container, which is very useful in many scenarios, especially when the user needs to expose the services in the container or wants to access the application in the container from the outside.

[0076] See also Figure 6 The sixth embodiment of the method for constructing an isolated compilation environment in the embodiment of the present invention includes:

[0077] 601. Write script information of the Ansible configuration tool, where the script information is used to set a host name, install software packages, configure network settings, and manage users;

[0078] In this embodiment, the Ansible configuration tool is used to ensure that the environment configuration from development to production remains highly consistent. Specifically, Ansible uses a simple YAML configuration management infrastructure, supports software deployment, configuration management, task automation and other functions, and can help users define and manage infrastructure configuration, automate common IT tasks, and reduce errors.

[0079] 602. Install the Ansible configuration tool in the Docker container;

[0080] In this embodiment, after the installation of the Ansible configuration tool is completed, the RUNansible-playbook instruction in the Dockerfile can be used to run the Ansible playbook when the Docker container is built.

[0081] 603. Copy the script information of the Ansible configuration tool to the ansible subdirectory of the directory where the Docker container is located, so as to integrate the script information into the constructed Docker container;

[0082] In this embodiment, the script information of the Ansible configuration tool is copied to the ansible subdirectory of the directory where the Docker container is located. Such a directory structure helps to maintain the organization and maintainability of the project, and also facilitates the reference of these files during the Docker build process. The command line tool can be used to complete the copying of the script information. After the move or copy is completed, check the / path / to / project / ansible directory to ensure that the Ansible playbook and inventory files are correctly placed.

[0083] In this embodiment, the constructed Ansible playbook should be designed to be idempotent so that no side effects occur when run multiple times.

[0084] See also Figure 7 The seventh embodiment of the method for constructing an isolated compilation environment in the embodiment of the present invention includes:

[0085] 701. Obtain configuration command information of a configuration tool, where the configuration command information includes an application configuration file command and a management node command;

[0086] 702. Obtain container command information of the Docker isolated container, where the container command information includes a start command, a stop command, and a rebuild command;

[0087] In this embodiment, the Docker start command is used to start the required container, and the Docker stop command is used to stop the running container; when the code or dependencies of the application are modified, the Docker rebuild command is used to rebuild the image.

[0088] 703. Write a Shell script based on the acquired configuration command information and container command information, and set the name of the Shell script to obtain a packaged script;

[0089] In this embodiment, the written Shell script also includes an initialization environment command, and the initialization environment command is used to pull necessary Docker images, configure environment variables, etc.

[0090] 704. Pack the encapsulation script into the constructed Docker container to obtain a Docker isolated container.

[0091] In this embodiment, the relationship between the encapsulated script and the Docker container is mainly reflected in that the script can be encapsulated or packaged into the Docker container to achieve portability, consistency and isolation of the application. The following is a detailed explanation of the relationship between them: Encapsulated script is a technology that combines a series of commands or codes into a single file (such as .sh, .py, etc.), which can be directly run to perform a series of tasks. Scripts are often used to automate various tasks, such as system configuration, data backup, software testing, etc.

[0092] In this embodiment, Docker container technology, as a lightweight virtualization solution, allows developers to quickly create an environment isolated from the host operating system on their own computers; this is not limited to the runtime environment of programming languages ​​(such as Python, Node.js), but also includes any services required for development or testing, such as database servers (MySQL, MongoDB), cache services (Redis), message queues, etc. Through Dockerfile, developers can write a series of instructions to define the container build process, including the selection of base images, dependency installation, port mapping, etc.; Docker container: a lightweight, portable software packaging standard that contains everything needed to run software: code, runtime, libraries, environment variables, and configuration files.

[0093] In this embodiment, by integrating the configuration tool in the Docker container, the user's environment configuration can be highly consistent at every step from development to production, and a unified command line interface (CLI) tool is provided to provide developers with a convenient interaction method, making operations such as environment initialization and container lifecycle management simple and intuitive. Daily development and maintenance work can be completed efficiently without in-depth understanding of the specific commands of Docker or configuration management tools.

[0094] The above describes the method for constructing an isolated compilation environment in an embodiment of the present invention. The following describes the device for constructing an isolated compilation environment in an embodiment of the present invention. Figure 8 , an embodiment of the isolated compilation environment construction device in the embodiment of the present invention includes:

[0095] A creation module 801 is used to obtain project information and dependency information, and create a Dockerfile based on the obtained project information and dependency information; a construction module 802 is used to obtain a Docker base image, and build a Docker container based on the created Dockerfile and the obtained Docker base image; a mapping module 803 is used to obtain the network configuration information of the host, and perform port mapping on the constructed Docker container according to the obtained network configuration information; an integration module 804 is used to write script information of the configuration tool, and integrate the script information into the constructed Docker container; an encapsulation module 805 is used to obtain the configuration command information of the configuration tool and the container command information of the Docker isolated container, encapsulate the configuration command information and the container command information to obtain an encapsulation script, and package the encapsulation script into the constructed Docker container to obtain a Docker isolated container.

[0096] In this embodiment, the creation module 801 includes: an initialization unit 8011, which is used to initialize the npm project and obtain project information, wherein the project information includes a package.json file; a first acquisition unit 8012, which is used to obtain dependency information, install the dependency in the node_modules folder of the npm project according to the dependency information, and add corresponding entries in the package.json file, wherein the added entry is the precise version number corresponding to the dependency, to obtain a complete npm project; a creation unit 8013, which is used to create a Dockerfile in the project root directory based on the complete npm project.

[0097] In this embodiment, the building module 802 includes: a second acquisition unit 8021, used to obtain a Docker base image, which is the official node.js; a first setting unit 8022, used to set a label for the Docker base image to obtain a Docker container image; a building unit 8023, used to run the docker build command in the project root directory, build a Docker container according to the created Dockerfile and the Docker container image, and set the basic information of the Docker container.

[0098] In this embodiment, the building module 802 also includes: an operation unit 8024, which is used to run the Docker container using the docker run command to set the basic parameters of the Docker container, wherein the basic parameters include the name, background operation parameters and automatic restart parameters; a second setting unit 8025, which is used to use the docker exec -it <container name> / bin / bash command to enter the terminal of the Docker container and perform basic configuration and initialization operations on the Docker container; a backup unit 8026, which is used to set periodic tasks and back up the Docker container image and Docker container based on the periodic tasks.

[0099] In this embodiment, the mapping module 803 includes: a third acquisition unit 8031, used to obtain network configuration information of the host, and the network configuration information of the host includes a host routing table; a fourth acquisition unit 8032, used to obtain network configuration information of the Docker container, and the network configuration information of the Docker container includes a container IP address; a judgment unit 8033, used to retrieve the host routing table based on the container IP address, and determine whether the container IP address is in the routing table; a mapping unit 8034, used to configure the Compose file of Docker Compose, and perform port mapping on the Docker container based on the configured Compose file.

[0100] In this embodiment, the integration module 804 includes: a first writing unit 8041, used to write script information of the Ansible configuration tool, and the script information is used to set the host name, install the software package, configure the network settings and manage users; an installation unit 8042, used to install the Ansible configuration tool in the Docker container; an integration unit 8043, used to copy the script information of the Ansible configuration tool to the ansible subdirectory of the directory where the Docker container is located, so as to integrate the script information into the constructed Docker container.

[0101] In this embodiment, the encapsulation module 805 includes: a fifth acquisition unit 8051, used to obtain configuration command information of the configuration tool, and the configuration command information includes application configuration file commands and management node commands; a sixth acquisition unit 8052, used to obtain container command information of the Docker isolated container, and the container command information includes a start command, a stop command and a rebuild command; a second writing unit 8053, used to write a Shell script based on the obtained configuration command information and container command information, and set the name of the Shell script to obtain an encapsulation script; an encapsulation unit 8054, used to package the encapsulation script into the constructed Docker container to obtain a Docker isolated container.

[0102] above Figure 8 The isolated compilation environment construction device in the embodiment of the present invention is described in detail from the perspective of modular functional entities. The isolated compilation environment construction device in the embodiment of the present invention is described in detail from the perspective of hardware processing.

[0103] Fig. 9 1 is a schematic diagram of the structure of an isolated compilation environment construction device provided by an embodiment of the present invention. The isolated compilation environment construction device 900 may have relatively large differences due to different configurations or performances, and may include one or more processors (central processing units, CPU) 910 (for example, one or more processors) and a memory 920, and one or more storage media 930 (for example, one or more mass storage devices) storing application programs 933 or data 932. Among them, the memory 920 and the storage medium 930 can be short-term storage or permanent storage. The program stored in the storage medium 930 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the isolated compilation environment construction device 900. Furthermore, the processor 910 can be configured to communicate with the storage medium 930, and execute a series of instruction operations in the storage medium 930 on the isolated compilation environment construction device 900 to implement the steps of the isolated compilation environment construction method provided in the above-mentioned method embodiments.

[0104] The isolated compilation environment construction device 900 may also include one or more power supplies 940, one or more wired or wireless network interfaces 950, one or more input and output interfaces 960, and / or one or more operating systems 931, such as Windows Serve, Mac OS X, Unix, Linux, FreeBSD, etc. Those skilled in the art will appreciate that the isolated compilation environment construction device structure shown in the present application does not constitute a limitation on the isolated compilation environment construction device, and may include more or less components than shown in the figure, or combine certain components, or arrange components differently.

[0105] The present invention also provides a computer-readable storage medium, which may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium. Instructions are stored in the computer-readable storage medium. When the instructions are executed on a computer, the computer executes the steps of the isolated compilation environment construction method.

[0106] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the above-described system, device, or unit can refer to the corresponding process in the aforementioned method embodiment and will not be repeated here.

[0107] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program codes.

[0108] Finally, it should be noted that the above description is only a preferred example of the present invention and is not intended to limit the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art can still modify the technical solutions described in the aforementioned embodiments or replace some of the technical features therein by equivalents. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for constructing an isolated compilation environment, characterized in that: include: Obtain project information and dependency information, and create a Dockerfile based on the obtained project information and dependency information; Get the Docker base image, and build a Docker container based on the created Dockerfile and the obtained Docker base image; Obtain the network configuration information of the host, and perform port mapping on the constructed Docker container according to the obtained network configuration information; Write the script information of the configuration tool and integrate the script information into the built Docker container; The configuration command information of the configuration tool and the container command information of the Docker isolated container are obtained, the configuration command information and the container command information are packaged to obtain a packaging script, and the packaging script is packaged into the constructed Docker container to obtain a Docker isolated container.

2. The method for constructing an isolated compilation environment according to claim 1, characterized in that: The obtaining of project information and dependency information, and creating a Dockerfile based on the obtained project information and dependency information, specifically includes: Initialize the npm project and obtain project information, including the package.json file; Get dependency information, install the dependencies in the node_modules folder of the npm project according to the dependency information, and add corresponding entries in the package.json file. The added entries are the exact version numbers corresponding to the dependencies, and the npm project is completed. Based on the completed npm project, create a Dockerfile in the project root directory.

3. The method for constructing an isolated compilation environment according to claim 1, characterized in that: The step of obtaining a Docker base image and building a Docker container based on the created Dockerfile and the obtained Docker base image specifically includes: Get the Docker base image, which is the official node.js. Set a tag for the Docker base image to get the Docker container image; Run the docker build command in the project root directory to build a Docker container based on the created Dockerfile and Docker container image, and set the basic information of the Docker container.

4. The method for constructing an isolated compilation environment according to claim 3, characterized in that: The basic information of setting the Docker container specifically includes: Run the Docker container using the docker run command to set basic parameters of the Docker container, including name, background running parameters, and automatic restart parameters; Use the docker exec -it <container name> / bin / bash command to enter the terminal of the Docker container and perform basic configuration and initialization operations on the Docker container; Set up periodic tasks to back up Docker container images and Docker containers based on periodic tasks.

5. The method for constructing an isolated compilation environment according to claim 1, characterized in that: The obtaining of the network configuration information of the host and performing port mapping on the constructed Docker container according to the obtained network configuration information specifically includes: Acquire network configuration information of a host, wherein the network configuration information of the host includes a host routing table; Obtain network configuration information of a Docker container, wherein the network configuration information of the Docker container includes a container IP address; Search the host routing table based on the container IP address to determine whether the container IP address is in the routing table; If so, configure the Compose file of Docker Compose and map ports to the Docker container based on the configured Compose file.

6. The method for constructing an isolated compilation environment according to claim 1, characterized in that: The script information of the configuration tool is written and integrated into the constructed Docker container, specifically including: Write script information for the Ansible configuration tool, which is used to set the host name, install software packages, configure network settings, and manage users; Install the Ansible configuration tool in the Docker container; Copy the script information of the Ansible configuration tool to the ansible subdirectory of the directory where the Docker container is located to integrate the script information into the built Docker container.

7. The method for constructing an isolated compilation environment according to claim 1, characterized in that: The step of obtaining configuration command information of the configuration tool and container command information of the Docker isolated container, encapsulating the configuration command information and the container command information to obtain an encapsulation script, and packaging the encapsulation script into the constructed Docker container to obtain the Docker isolated container specifically includes: Obtain configuration command information of a configuration tool, wherein the configuration command information includes application configuration file commands and management node commands; Obtain container command information of the Docker isolated container, wherein the container command information includes a start command, a stop command, and a rebuild command; A Shell script is written based on the acquired configuration command information and container command information, and a name of the Shell script is set to obtain a packaged script; The encapsulated script is packaged into the constructed Docker container to obtain a Docker isolated container.

8. An isolated compilation environment construction device, characterized in that: include: Create a module to obtain project information and dependency information, and create a Dockerfile based on the obtained project information and dependency information; The build module is used to obtain the Docker base image and build a Docker container based on the created Dockerfile and the obtained Docker base image; A mapping module is used to obtain the network configuration information of the host and perform port mapping on the constructed Docker container according to the obtained network configuration information; Integration module, used to write script information of configuration tools and integrate the script information into the built Docker container; The encapsulation module obtains the configuration command information of the configuration tool and the container command information of the Docker isolated container, encapsulates the configuration command information and the container command information to obtain the encapsulation script, and packages the encapsulation script into the constructed Docker container to obtain the Docker isolated container.

9. An isolated compilation environment construction device, characterized in that: The isolated compilation environment construction device includes: a memory and at least one processor, wherein instructions are stored in the memory; At least one of the processors calls the instructions in the memory to enable the isolated compilation environment construction device to perform each step of the isolated compilation environment construction method as described in any one of claims 1-7.

10. A computer-readable storage medium having instructions stored thereon, characterized in that: When the instructions are executed by the processor, the various steps of the method for constructing an isolated compilation environment as described in any one of claims 1 to 7 are implemented.