Customized offline product package deployment method and system based on Go language

By adopting a custom offline product package deployment method based on the Go language, the problem of missing dependency resources during the deployment of offline product packages is solved, and efficient deployment compatible with hosts and Kubernetes is achieved, reducing the complexity of operation and maintenance and manpower costs.

CN118409759BActive Publication Date: 2024-10-15HANGZHOU YUNZHE TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410853050.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-28
Publication Date
2024-10-15
Estimated Expiration
2044-06-28

AI Technical Summary

Technical Problem

In existing technologies, offline product packages are prone to missing dependent resources during the packaging process, leading to deployment failures. Furthermore, resource configuration requires a significant amount of manpower, and the deployment method is incompatible with the host and k8s in a Kubernetes environment.

Method used

A custom offline product package deployment method based on the Go language is adopted. By obtaining a pre-defined configuration file, an offline product package is generated, and the configuration and variable information is parsed in the target environment to determine the dependencies and startup order. It supports deployment on Kubernetes and host machines.

Benefits of technology

It improves deployment flexibility and compatibility, reduces manpower costs, supports dual deployment on hosts and Kubernetes, simplifies resource configuration, and reduces operational complexity.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118409759B_ABST
    Figure CN118409759B_ABST
Patent Text Reader

Abstract

The present application discloses a method and system for deploying a custom offline product package based on the go language, which relates to the field of computer technology and includes the following steps: obtaining a pre-customized first configuration file; generating an offline product package according to the first configuration file, and transferring the offline product package to the target environment; parsing the offline product package in the target environment to obtain configuration information and related variable information, and rendering the related variable information according to the environment variables of the target environment; determining the dependency and startup sequence of the service corresponding to the offline product according to the configuration information, and deploying the product according to the dependency and startup sequence. In the present application, when deploying the offline product package, the operation and maintenance personnel do not need to modify the customized related service parameters at the service level, which has high flexibility, and can also limit the resources occupied by the product on the host by configuring cgroup in schema.yml, which has simple configuration and low labor cost. It also supports both k8s deployment and host deployment, and has good compatibility.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a method and system for deploying a custom offline product package based on the Go language. Background Art

[0002] In today's era of Internet penetration, network security is particularly important, especially in sensitive fields such as finance, where network security issues may bring immeasurable losses. In order to better provide services and effectively protect the security of internal networks, enterprises usually take measures to separate hosts open to the outside world from internal network devices and formulate security policies to limit Internet connections.

[0003] This approach can ensure the provision of friendly services to the outside world while protecting the internal network, but at the same time, it will also lead to a closed situation between the internal network and the Internet. Generally speaking, in a relatively closed intranet environment, operation and maintenance personnel need to use packaging tools to download the required resources from other environments before deploying them internally. This process may miss some dependent resources, resulting in failure of offline deployment. At the same time, cloud packaging requires cloud resource configuration, host deployment requires host configuration, and different product packages also require different dependencies. This also causes operation and maintenance personnel to spend a lot of time on resource configuration. With the popularization of Kubernetes (k8s for short), more and more companies are beginning to deploy their products on k8s, but the existing deployment methods are not compatible with hosts and k8s. Summary of the invention

[0004] The present application provides a custom offline product package deployment method based on the Go language, which aims to solve the problem in the prior art that offline product packages fail to be deployed offline due to missing some dependent resources during the packaging process, and resource configuration requires a lot of manpower.

[0005] To achieve the above objectives, this application adopts the following technical solutions:

[0006] The present application discloses a method for deploying a custom offline product package based on the Go language, comprising the following steps:

[0007] Obtaining a pre-defined first configuration file, wherein the first configuration file includes configuration information and related variable information of the offline product;

[0008] generating an offline product package according to the first configuration file, and transmitting the offline product package to a target environment;

[0009] Parsing the offline product package in the target environment to obtain the configuration information and related variable information, and rendering the related variable information according to the environment variables of the target environment;

[0010] Dependencies and a startup sequence of services corresponding to the offline product are determined according to the configuration information, and the product is deployed in the target environment according to the dependencies and the startup sequence.

[0011] Preferably, the configuration information includes product dependency information and environment dependency information;

[0012] The relevant variable information includes image tag information, cgroup parameters and environment variable parameters.

[0013] Preferably, generating an offline product package according to the first configuration file includes:

[0014] Download the product dependency package and the environment dependency package according to the product dependency information and the environment dependency information, and pull the target image from the private image library according to the image tag information;

[0015] If all are successful, detect whether there is a first configuration file and a second configuration file in the current working path, the second configuration file contains the configuration information of the cluster, and if both exist, merge the cluster configuration information in the second configuration file into the first configuration file to obtain the target configuration file, and if the second configuration file does not exist, use the first configuration file as the target configuration file;

[0016] Verify the integrity of the target configuration file under the current working path and whether the configuration therein complies with the specification, and if the verification passes, generate a first file package according to the product dependency package, the environment dependency package, the target image and the target configuration file;

[0017] Check whether the first file package contains a dangerous operation script, and when the checking result is no, package the first file package to obtain an offline product package.

[0018] Preferably, the checking of the integrity of the target configuration file in the current working path and whether the configuration therein complies with the specification includes:

[0019] The target configuration file is parsed by a configuration parser to obtain the configuration therein, and it is determined whether all configurations meet the corresponding specification requirements. The configuration parser is secondary developed based on the elastic / go-ucfg / yaml third-party package tool of the go language.

[0020] Preferably, the checking whether the first file package contains a dangerous operation script includes:

[0021] All shell scripts and structured query language files included in the first file package are determined according to the file extensions, and the shell scripts and structured query language files are checked for malicious codes.

[0022] Preferably, the step of parsing the offline product package to obtain the configuration information and related variable information includes:

[0023] Decompress the offline product package using a decompression module, wherein the decompression module is encapsulated by a go operating file system package and a zip three-party package;

[0024] Parsing the decompression result by the configuration parser to obtain the configuration information and related variable information;

[0025] A file parser is used to extract variables corresponding to the environment variable parameters in the relevant variable information from the environment variables of the target environment. The file parser is obtained by secondary development based on the file system operation library of the go language and the configuration parser.

[0026] Preferably, the method further comprises:

[0027] The shell command is rendered according to the cgroup parameter in the configuration information, and the shell command is sent to the target host through the grpc communication mechanism.

[0028] A custom offline product package deployment system based on Go language, including:

[0029] An acquisition module, used to acquire a pre-defined first configuration file, wherein the first configuration file includes configuration information and related variable information of an offline product;

[0030] A transmission module, configured to generate an offline product package according to the first configuration file, and transmit the offline product package to a target environment;

[0031] A parsing module, configured to parse the offline product package in the target environment to obtain the configuration information and related variable information, and render the related variable information according to the environment variables of the target environment;

[0032] The deployment module is used to determine the dependency relationship and startup sequence of the services corresponding to the offline product according to the configuration information, and to deploy the product in the target environment according to the dependency relationship and startup sequence.

[0033] A computer device comprises a memory, a processor and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of any one of the methods described above.

[0034] A computer-readable storage medium stores a computer program or instruction thereon, wherein the computer program or instruction, when executed by a processor, implements the steps of any one of the methods described above.

[0035] The present invention has the following beneficial effects:

[0036] In this application, when the operation and maintenance personnel deploy the offline product package, they no longer need to modify the customized related service parameters at the service level. It has high flexibility and can limit the resources occupied by the product on the host by configuring cgroup in schema.yml. It has simple configuration and low labor cost. It also supports both k8s deployment and host deployment and has good compatibility. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0038] Figure 1 This is a flowchart of a custom offline product package deployment method based on the Go language implemented in this application;

[0039] Figure 2 This application implements a computer device schematic diagram of a custom offline product package deployment method based on the Go language. DETAILED DESCRIPTION

[0040] The following will be combined with the accompanying drawings to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present application.

[0041] The terms "first", "second", etc. in the claims and specification of the present application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the terms used in this way are interchangeable under appropriate circumstances. This is merely a way of distinguishing objects with the same properties in the embodiments of the present application. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, so that a process, method, system, product or apparatus that includes a series of units is not necessarily limited to those units, but may include other units not expressly listed or inherent to these processes, methods, products or apparatus.

[0042] In one embodiment, Figure 1 As shown, a custom offline product package deployment method based on the Go language is provided, including the following steps:

[0043] S110, obtaining a pre-defined first configuration file, wherein the first configuration file includes configuration information and related variable information of an offline product;

[0044] S120, generating an offline product package according to the first configuration file, and transmitting the offline product package to a target environment;

[0045] S130, parsing the offline product package in the target environment to obtain the configuration information and related variable information, and rendering the related variable information according to the environment variables of the target environment;

[0046] S140: Determine the dependency relationship and startup sequence of the services corresponding to the offline product according to the configuration information, and deploy the product in the target environment according to the dependency relationship and startup sequence.

[0047] In this embodiment, the main purpose is to generate an offline product package. First, a first configuration file schema.yml is created. Of course, schema.yml can be currently created or pre-built. In schema.yml, the configuration information and related variable information of the offline product are customized, wherein the configuration information mainly includes product dependency information and environment dependency information, and the related variable information includes image tag information, Control Groups information and environment variable parameters. Control Groups, referred to as cgroup, is a function provided by the Linux kernel for limiting, controlling and isolating the use of resources such as CPU, memory, disk input and output of process groups. Preferably, the CPU limit core number is set to 1 core, and the memory limit size is set to 134217728 bytes. The image tag is a string used to identify the Docker image version, usually in the format of<image name> : <tag>It allows users to specify different names for different versions of the same image so that they can select the appropriate version during deployment and runtime. In addition, schema.yml also sets the offline product package type to distinguish between cloud packages and host packages. It also configures the operating system type product_os, dependent service depends_on, host parameter instance, the node IP of the service itself dtlog_ip_port, affinity affinity, anti-affinity anti_affinity, and health check healthcheck.

[0048] Further, download the product dependency package and the environment dependency package according to the product dependency information and the environment dependency information, and pull the target image from the private image library according to the image tag information;

[0049] If all are successful, detect whether there is a first configuration file and a second configuration file in the current working path, the second configuration file contains the configuration information of the cluster, and if both exist, merge the cluster configuration information in the second configuration file into the first configuration file to obtain the target configuration file, and if the second configuration file does not exist, use the first configuration file as the target configuration file;

[0050] Verify the integrity of the target configuration file under the current working path and whether the configuration therein complies with the specification, and if the verification passes, generate a first file package according to the product dependency package, the environment dependency package, the target image and the target configuration file;

[0051] Check whether the first file package contains a dangerous operation script, and when the checking result is no, package the first file package to obtain an offline product package.

[0052] Then, the corresponding resources, target configuration files and dependencies of the offline product are packaged. The first step is to download the product dependency package and environment dependency package according to the product dependency information and environment dependency information in schema.yml. At the same time, the target image is pulled from the private image library according to the image tag information. Among them, the private image library refers to the image warehouse deployed within the company or organization for the storage and distribution of its own application Docker images. Its main purpose is to provide image storage, management and distribution services in the internal network environment to ensure the security and controllability of the image. The packaged image of the application is generally only stored in the private image library. After all dependencies are downloaded successfully and the image is pulled successfully, the second step can be entered, otherwise the process ends; The second step is mainly implemented by mergeAndCreateSchema, which first detects whether schema.yml and the second configuration file schema_config.yml exist in the current working path. Schema_config.yml is used to set k8s configuration information, because some configurations are unique to k8s. If both files exist, the configuration information in schema_config.yml is merged into schema.yml to generate the target configuration file. If the configuration information is repeated during the merging process, it is overwritten, and the other parts are not processed. If schema_config.yml does not exist, schema.yml as the target configuration file, and enter the third step. If both files do not exist, the process ends; the third step is mainly implemented by verifyPackageDir, which first verifies the integrity of the target configuration file. If the target configuration file is complete, the custom configuration in the target configuration file is parsed by a custom configuration parser. Preferably, the configuration parser is a yaml parser, which is determined by the format of the configuration file, and the yaml parser is a component for customized adaptation of product packages based on the elastic / go-ucfg / yaml third-party package tool of the go language. The custom configuration includes configuration information such as environment variables, image tag information, and cgroup parameters. The parsing results are used to determine whether these custom configurations meet the specifications. If they meet the specifications, the first file package is generated according to the product dependency package, environment dependency package, target image, and target configuration file, and the process ends; otherwise, the fourth step is mainly to use CheckRisks to check Check whether the first file package contains dangerous operation scripts. First, retrieve all shell scripts and structured query language files configured in the first file package through the file extension. Shell scripts are shell scripts, and structured query language files are sql files. Then detect whether they contain sql injection, rm, drop, truncate or xss injection and other intrusive / destructive scripts or commands, i.e. malicious codes. If relevant commands are detected, an alarm risk prompt will be issued and relevant statements or file addresses will be thrown out. At the same time, the package will be interrupted and the process will be ended. However, when the relevant command is rm or truncate command, it is still necessary to manually determine whether the rm or truncate command is a normal operation, because some rm or truncate commands are normal operations. If they are normal operations, only an alarm risk prompt will be issued and the fifth step will be entered; the fifth step is to use createPackage to package the first file package to obtain package.tar, i.e. offline product package. .

[0053] Finally, deploy the product to the server according to the offline product package, which mainly includes the following steps:

[0054] Decompress the offline product package using a decompression module, wherein the decompression module is encapsulated by a go operating file system package and a zip three-party package;

[0055] Parsing the decompression result by the configuration parser to obtain the configuration information and related variable information;

[0056] A file parser is used to extract variables corresponding to the environment variable parameters in the relevant variable information from the environment variables of the target environment. The file parser is obtained by secondary development based on the file system operation library of the go language and the configuration parser.

[0057] Specifically, the offline product package is uploaded to the self-developed emr-engine engine for product deployment. The emr-engine engine is deployed on the target environment. Preferably, the UnzipParse module in the emr-engine engine first decompresses the offline product package. The UnzipParse module is a parsing module encapsulated by the os file system package of go and the zip third-party package. After the decompression is completed, the yaml parser is used to parse the content of schema.yml to obtain configuration information and related variable information, and then the self-developed parse file parser is used to extract the variables corresponding to the environment variable parameters from the environment variables of the current operating system, and then these variables are rendered to the location corresponding to the environment variable configuration placeholder in schema.yml, such as the deployed node IP address, host name, etc. Among them, the self-developed parse file parser is mainly obtained through the secondary development of the go file system operation library and the custom yaml parser. Because multiple offline product packages may be uploaded at the same time, each offline product package upload here will start a parse-worker coroutine to perform actual operation operations to upload offline product packages in parallel. After successful operation, the relevant data will be stored in the database and server. If the operation fails, an email alarm will be sent, and error information and possible reasons will be prompted.

[0058] After parsing, the depends on parameter contained in the configuration information is obtained. This parameter uses a directed cyclic graph to control the order of deployment of the corresponding services of the product and establishes the dependency relationship of the deployment. Only when the process in depends on runs successfully first, the subsequent processes in the offline product package can run, otherwise it will be blocked until timeout. At the same time, the cpu and memory resources occupied by the services restricted by the cgroup parameters configured in the target configuration file will be rendered into shell commands, and the shell commands for restricting services will be sent to the target host through the grpc communication mechanism. Finally, health checks are performed through the health check configuration in the target configuration file. All are successful and the product deployment is completed.

[0059] The above method is flexible and compatible: when deploying offline product packages, operation and maintenance personnel no longer need to modify the customized service parameters at the service level. At the same time, by configuring cgroup in schema.yml, the resources occupied by the product on the host can be limited, and both k8s deployment and host deployment are supported.

[0060] In one embodiment, a Linux machine with a Go environment is provided, and related environment dependencies are loaded. Then, the schema.yml file is configured according to the product package type, and then the related dependency packages are downloaded according to the schema.yml file, and the related images are pulled at the same time. Then, the configured product package is packaged through the built binary package, and the related tar offline product package is output. Finally, the offline product package is uploaded to the emr-engin engine, and the data in the offline product package is stored in the database and server after verification parsing and parameter rendering, and then deployed.

[0061] In one embodiment, Figure 2 As shown, a computer device is provided, including a memory, a processor and a computer program stored in the memory, and the processor executes the computer program to implement the steps of the above-mentioned custom offline product package deployment method based on the Go language.

[0062] The computer device can be a server or a terminal. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. Among them, the processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a custom offline product package deployment method based on the go language is implemented.

[0063] This embodiment also provides a computer-readable storage medium on which a computer program or instruction is stored. When the computer program or instruction is executed by a processor, the steps of the above-mentioned custom offline product package deployment method based on the Go language are implemented.

[0064] The computer-readable programs or instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmission, wireless transmission, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.

[0065] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions within the technical scope disclosed by the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.< / tag>

Claims

1. A custom offline product package deployment method based on go language, characterized in that: The following steps are involved: Obtain a pre-defined first configuration file, where the first configuration file contains configuration information and related variable information of an offline product, where the configuration information includes product dependency information and environment dependency information, and the related variable information includes image tag information, cgroup parameters, and environment variable parameters; generating an offline product package according to the first configuration file, and transmitting the offline product package to a target environment; Parsing the offline product package in the target environment to obtain the configuration information and related variable information, and rendering the related variable information according to the environment variables of the target environment; Determine the dependency relationship and startup sequence of the services corresponding to the offline product according to the configuration information, and deploy the product in the target environment according to the dependency relationship and startup sequence; The step of generating an offline product package according to the first configuration file includes: Download the product dependency package and the environment dependency package according to the product dependency information and the environment dependency information, and pull the target image from the private image library according to the image tag information; If all are successful, detect whether there is a first configuration file and a second configuration file in the current working path, the second configuration file contains the configuration information of the cluster, and if both exist, merge the cluster configuration information in the second configuration file into the first configuration file to obtain the target configuration file, and if the second configuration file does not exist, use the first configuration file as the target configuration file; Verify the integrity of the target configuration file under the current working path and whether the configuration therein complies with the specification, and if the verification passes, generate a first file package according to the product dependency package, the environment dependency package, the target image and the target configuration file; Check whether the first file package contains a dangerous operation script, and when the checking result is no, package the first file package to obtain an offline product package.

2. According to the method for deploying a custom offline product package based on the Go language in claim 1, it is characterized in that: The checking of the integrity of the target configuration file in the current working path and whether the configuration therein complies with the specification includes: The target configuration file is parsed by a configuration parser to obtain the configuration therein, and it is determined whether all configurations meet the corresponding specification requirements. The configuration parser is secondary developed based on the elastic / go-ucfg / yaml third-party package tool of the go language.

3. According to a method for deploying a custom offline product package based on the Go language according to claim 1, it is characterized in that: The step of checking whether the first file package contains a dangerous operation script includes: All shell scripts and structured query language files included in the first file package are determined according to the file extensions, and the shell scripts and structured query language files are checked for malicious codes.

4. According to a method for deploying a custom offline product package based on the Go language according to claim 1, it is characterized in that: The step of parsing the offline product package to obtain the configuration information and related variable information includes: Decompress the offline product package using a decompression module, wherein the decompression module is encapsulated by a go operating file system package and a zip three-party package; Parsing the decompression result by a configuration parser to obtain the configuration information and related variable information; A file parser is used to extract variables corresponding to the environment variable parameters in the relevant variable information from the environment variables of the target environment. The file parser is obtained by secondary development based on the file system operation library of the go language and the configuration parser.

5. According to a method for deploying a custom offline product package based on the Go language as claimed in claim 1, it is characterized in that: The method further comprises: The shell command is rendered according to the cgroup parameter in the configuration information, and the shell command is sent to the target host through the grpc communication mechanism.

6. A custom offline product package deployment system based on Go language, characterized in that: include: An acquisition module is used to acquire a pre-defined first configuration file, wherein the first configuration file contains configuration information and related variable information of an offline product, wherein the configuration information includes product dependency information and environment dependency information, and the related variable information includes image tag information, cgroup parameters, and environment variable parameters; A transmission module, configured to generate an offline product package according to the first configuration file, and transmit the offline product package to a target environment; A parsing module, configured to parse the offline product package in the target environment to obtain the configuration information and related variable information, and render the related variable information according to the environment variables of the target environment; A deployment module, used to determine the dependency relationship and startup sequence of the services corresponding to the offline product according to the configuration information, and to deploy the product in the target environment according to the dependency relationship and startup sequence; The step of generating an offline product package according to the first configuration file includes: Download the product dependency package and the environment dependency package according to the product dependency information and the environment dependency information, and pull the target image from the private image library according to the image tag information; If all are successful, detect whether there is a first configuration file and a second configuration file in the current working path, the second configuration file contains the configuration information of the cluster, and if both exist, merge the cluster configuration information in the second configuration file into the first configuration file to obtain the target configuration file, and if the second configuration file does not exist, use the first configuration file as the target configuration file; Verify the integrity of the target configuration file under the current working path and whether the configuration therein complies with the specification, and if the verification passes, generate a first file package according to the product dependency package, the environment dependency package, the target image and the target configuration file; Check whether the first file package contains a dangerous operation script, and when the checking result is no, package the first file package to obtain an offline product package.

7. A computer device comprising a memory, a processor and a computer program stored in the memory, characterized in that: The processor executes the computer program to implement the steps of the method according to any one of claims 1 to 5.

8. A computer-readable storage medium having a computer program or instruction stored thereon, characterized in that: When the computer program or instruction is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.