CN113703825A - Mirror image construction method and device, server and storage medium - Google Patents

Mirror image construction method and device, server and storage medium Download PDF

Info

Publication number
CN113703825A
CN113703825A CN202010434650.2A CN202010434650A CN113703825A CN 113703825 A CN113703825 A CN 113703825A CN 202010434650 A CN202010434650 A CN 202010434650A CN 113703825 A CN113703825 A CN 113703825A
Authority
CN
China
Prior art keywords
dockerfile
grammar
keyword
target
construction
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010434650.2A
Other languages
Chinese (zh)
Inventor
程庞钢
罗俊彪
蓝景全
李余良
刘君
陈秋浩
邹艳军
张媛
巫勇明
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
SF Technology Co Ltd
SF Tech Co Ltd
Original Assignee
SF Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by SF Technology Co Ltd filed Critical SF Technology Co Ltd
Priority to CN202010434650.2A priority Critical patent/CN113703825A/en
Publication of CN113703825A publication Critical patent/CN113703825A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/71Version control; Configuration management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/73Program documentation

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Security & Cryptography (AREA)
  • Library & Information Science (AREA)
  • Stored Programmes (AREA)

Abstract

The embodiment of the application discloses a mirror image construction method, which comprises the following steps: acquiring a preset program package containing parameter values; creating a construction strategy of the mirror image file, wherein the construction strategy comprises a dockerfile compiling strategy, a dockerfile analyzing strategy and a dockerfile checking strategy; compiling a dockerfile according to a dockerfile compiling strategy; analyzing the dockerfile according to a dockerfile analysis strategy to obtain a grammar keyword in the dockerfile, and performing grammar check on the grammar keyword to obtain a dynamic parameter in the grammar keyword; adjusting the dynamic parameters according to the program package to obtain target dynamic parameter values; updating the dockerfile according to the target dynamic parameter value to obtain a target dockerfile corresponding to the target dynamic parameter value; and constructing a mirror image according to the target dockerfile and preset configuration information. The method provided by the application can improve the success rate of mirror image construction. Meanwhile, dynamic parameter values in the dockerfile are dynamically changed in an external program package uploading mode, the dockerfile does not need to be written for many times, and manpower and material resources are reduced.

Description

Mirror image construction method and device, server and storage medium
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method and an apparatus for constructing a mirror image, a server, and a storage medium.
Background
With the rapid development of cloud computing, the virtualization era has come. In the virtualization era, the cost can be reduced by adopting the configuration hardware, the requirement of using resources by a user according to needs can be met by adopting the virtualization technology, and the availability and the isolation of the resources can be ensured. Among them, the docker (application container engine) technology is popular for its lightweight, high performance, and convenience. The Docker image (image) is a core concept of Docker, is a read-only template required for starting a container, and is a file required for starting the container. An image may comprise a complete operating system environment in which only the applications needed by the user are installed, and the image may be used to create a Docker container.
In the existing docker image construction scheme, after a docker file is written, no syntax check exists, so that repeated modification is performed in the construction process of executing the image, and the construction failure rate is high. For different mirror image creation scenes, different docker file files need to be written for multiple times to create different docker mirror images, and a large amount of manpower and material resources are wasted.
Disclosure of Invention
The embodiment of the application provides a mirror image construction method, a mirror image construction device, a server and a storage medium, and aims to solve the problems that in the prior art, the mirror image construction method is high in failure rate, and a dockerfile file needs to be repeatedly compiled for many times, so that manpower and material resources are wasted.
In a first aspect, the present application provides a mirror image construction method, including:
acquiring a preset program package containing parameter values;
creating a construction strategy of the image file, wherein the construction strategy comprises a dockerfile compiling strategy, a dockerfile analyzing strategy and a dockerfile checking strategy;
writing the dockerfile according to the dockerfile writing strategy;
analyzing the dockerfile according to the dockerfile analysis strategy to obtain a grammar keyword in the dockerfile, and performing grammar check on the grammar keyword to obtain a dynamic parameter in the grammar keyword;
adjusting the dynamic parameters according to the program package to obtain the target dynamic parameter values;
updating the dockerfile according to the target dynamic parameter value to obtain a target dockerfile corresponding to the target dynamic parameter value;
and constructing the mirror image according to the target dockerfile and preset configuration information.
Further, writing the dockerfile according to the dockerfile writing policy includes: acquiring a dockerfile template file; and compiling the dockerfile according to the dockerfile template file.
Further, the parsing the dockerfile according to the dockerfile parsing strategy to obtain a syntax keyword in the dockerfile, and performing syntax check on the syntax keyword to obtain a dynamic parameter in the syntax keyword includes:
analyzing the docker file by using a preset docker analyzer to obtain the grammar keywords;
acquiring a preset keyword verifier corresponding to the grammar keyword;
verifying whether the grammar keyword is legal or not by using the keyword verifier;
and if the grammar key words are legal, analyzing to obtain the dynamic parameters in the grammar key words.
Further, before a preset docker parser is used for parsing the docker file to obtain the grammar keywords, the method further includes:
initializing an initial grammar keyword in the dockerfile according to preset first configuration information to obtain the grammar keyword.
Further, the parsing the docker file by using a preset docker parser to obtain the grammar keyword includes:
reading each line of the dockerfile file from top to bottom in sequence according to a preset analysis rule;
intercepting the grammar keywords in each line of the dockerfile.
Further, if the grammar keyword is legal, analyzing to obtain the dynamic parameter in the grammar keyword, including:
if the grammar keyword is legal, intercepting command content corresponding to the grammar keyword;
and analyzing the command content to obtain the dynamic parameters in the command content.
Further, the parsing the dockerfile according to the dockerfile parsing strategy to obtain a syntax keyword in the dockerfile to obtain a dynamic parameter in the syntax keyword, further includes: and if the grammar keyword is illegal, rewriting the dockerfile.
Further, the updating the dockerfile according to the target dynamic parameter value to obtain a target dockerfile corresponding to the target dynamic parameter value includes:
judging whether to update the program package;
if the target program package is updated, uploading and storing a new target program package needing to be updated;
updating the dynamic parameters according to the target program package to obtain a construction instruction;
and updating the dockerfile according to the construction instruction to obtain a target dockerfile.
Further, the method further comprises:
and executing a construction instruction in the target dockerfile according to the target dockerfile to obtain the mirror image.
Further, the method further comprises:
creating a mirror image construction log in the construction process of the mirror image;
after the mirror image construction is finished, outputting a construction result of the mirror image;
and storing the construction log and the construction result.
In a second aspect, the present application provides an image creating apparatus, including:
the device comprises an acquisition unit, a processing unit and a processing unit, wherein the acquisition unit is used for acquiring a preset program package containing parameter values;
the file creating unit is used for creating a construction strategy of the mirror image file, and the construction strategy comprises a dockerfile compiling strategy, a dockerfile analyzing strategy and a dockerfile checking strategy;
the compiling unit is used for compiling the dockerfile according to the dockerfile compiling strategy;
the analysis and verification unit is used for analyzing the dockerfile according to the dockerfile analysis strategy to obtain a grammar keyword in the dockerfile, and carrying out grammar verification on the grammar keyword to obtain a dynamic parameter in the grammar keyword;
the adjusting unit is used for adjusting the dynamic parameters according to the program package to obtain the target dynamic parameter values;
the updating unit is used for updating the dockerfile according to the target dynamic parameter value to obtain a target dockerfile corresponding to the target dynamic parameter value;
and the mirror image construction unit is used for constructing the mirror image according to the target dockerfile and preset configuration information.
In a third aspect, the present application further provides a server, including:
one or more processors;
a memory; and
one or more application programs, wherein the one or more application programs are stored in the memory and configured to be executed by the processor to implement the steps in the image construction method of any of claims 1 to 10.
In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, the computer program being loaded by a processor to perform the steps in the image construction method according to any one of claims 1 to 9.
The embodiment of the application provides a mirror image construction method, a mirror image construction device, a server and a storage medium, wherein in the mirror image creation process, syntax keywords in a dockerfile are checked; only when the grammar keyword is legal, the construction process can be executed according to the dockerfile, and the success rate of mirror image construction is improved. Meanwhile, dynamic parameter values in the dockerfile are dynamically changed in an external program package uploading mode, the dockerfile does not need to be rewritten for many times, and manpower and material resources are greatly reduced.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a schematic view of a scenario of a host monitoring system according to an embodiment of the present disclosure;
fig. 2 is a schematic flowchart of an embodiment of a mirror image construction method provided in the present application;
FIG. 3 is a schematic flow chart illustrating an embodiment of parsing a dockerfile using a parsing policy according to the present application;
FIG. 4 is a schematic flow chart illustrating an embodiment of updating a dockerfile file provided by the present application;
FIG. 5 is a diagram illustrating one embodiment of a full image creation policy provided herein;
FIG. 6 is a schematic diagram of an embodiment of a mirror image construction apparatus provided in the present application;
fig. 7 is a schematic structural diagram of a server according to an embodiment of the present application.
DETAILED DESCRIPTION OF EMBODIMENT (S) OF INVENTION
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
In the description of the present application, it is to be understood that the terms "center", "longitudinal", "lateral", "length", "width", "thickness", "upper", "lower", "front", "rear", "left", "right", "vertical", "horizontal", "top", "bottom", "inner", "outer", and the like indicate orientations or positional relationships based on those shown in the drawings, and are used merely for convenience of description and for simplicity of description, and do not indicate or imply that the referenced device or element must have a particular orientation, be constructed in a particular orientation, and be operated, and thus should not be considered as limiting the present application. Furthermore, the terms "first", "second" and "first" are used for descriptive purposes only and are not to be construed as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more features. In the description of the present application, "a plurality" means two or more unless specifically limited otherwise.
In this application, the word "exemplary" is used to mean "serving as an example, instance, or illustration. Any embodiment described herein as "exemplary" is not necessarily to be construed as preferred or advantageous over other embodiments. The following description is presented to enable any person skilled in the art to make and use the application. In the following description, details are set forth for the purpose of explanation. It will be apparent to one of ordinary skill in the art that the present application may be practiced without these specific details. In other instances, well-known structures and processes are not set forth in detail in order to avoid obscuring the description of the present application with unnecessary detail. Thus, the present application is not intended to be limited to the embodiments shown, but is to be accorded the widest scope consistent with the principles and features disclosed herein.
Embodiments of the present application provide a method and an apparatus for creating an image, a server, and a storage medium, which are described below.
As shown in fig. 1, a schematic view of a scenario of a host monitoring system according to an embodiment of the present application is provided, where the host monitoring system may include a plurality of hosts 100 and a server 200, the hosts 100 and the server 20 are connected through a network, and a host monitoring apparatus, such as the server in fig. 1, is integrated in the server 200, and the hosts 100 may access the server 200.
In the embodiment of the present invention, the server 200 is mainly configured to obtain a preset program package containing parameter values; creating a construction strategy of the mirror image, wherein the construction strategy comprises a dockerfile compiling strategy, a dockerfile analyzing strategy and a dockerfile checking strategy; compiling a dockerfile according to a dockerfile compiling strategy; analyzing the dockerfile according to a dockerfile analysis strategy to obtain a grammar keyword in the dockerfile so as to obtain a dynamic parameter in the grammar keyword; adjusting the dynamic parameters according to the program package to obtain target dynamic parameter values; and updating the dockerfile according to the target dynamic parameter value to obtain a target dockerfile corresponding to the target dynamic parameter value.
In this embodiment of the present invention, the server 200 may be an independent server, or may be a server network or a server cluster composed of servers, for example, the server 200 described in this embodiment of the present invention includes, but is not limited to, a computer, a network host, a single network server, a plurality of network server sets, or a cloud server composed of a plurality of servers. Among them, the Cloud server is constituted by a large number of computers or web servers based on Cloud Computing (Cloud Computing). In the embodiment of the present invention, the server and the host may implement communication through any communication manner, including but not limited to mobile communication based on the third Generation Partnership Project (3 GPP), Long Term Evolution (LTE), Worldwide Interoperability for Microwave Access (WiMAX), or computer network communication based on the TCP/IP Protocol Suite (TCP/IP), User Datagram Protocol (UDP) Protocol, and the like.
It will be appreciated that the host 100 used in embodiments of the present invention may be a device that includes both receiving and transmitting hardware, i.e., a device having receiving and transmitting hardware capable of performing two-way communications over a two-way communications link. Such a host may include: a cellular or other communication device having a single line display or a multi-line display or a cellular or other communication device without a multi-line display. The host 100 may specifically be a desktop terminal or a mobile terminal, and the host 100 may also specifically be one of a mobile phone, a tablet computer, a notebook computer, and the like.
Those skilled in the art will appreciate that the application environment shown in fig. 1 is only one application scenario related to the present invention, and does not constitute a limitation to the application scenario of the present invention, and that other application environments may further include more or less servers than those shown in fig. 1, or a network connection relationship of servers, for example, only 1 server and 2 hosts are shown in fig. 1, and it will be understood that the host monitoring system may further include one or more other servers, or/and one or more hosts connected to a server network, and is not limited herein.
In addition, as shown in fig. 1, the host monitoring system may further include a memory 300 for storing data, such as host data, for example, host status data during host operation.
It should be noted that the scenario diagram of the host monitoring system shown in fig. 1 is merely an example, and the host monitoring system and the scenario described in the embodiment of the present invention are for more clearly illustrating the technical solution of the embodiment of the present invention, and do not form a limitation on the technical solution provided in the embodiment of the present invention.
The embodiment of the application provides a mirror image construction method, which comprises the following steps: and acquiring a preset program package containing parameter values. Creating a construction strategy of the image file, wherein the construction strategy comprises a dockerfile compiling strategy, a dockerfile analyzing strategy and a dockerfile checking strategy. And compiling the dockerfile according to the dockerfile compiling strategy. And analyzing the dockerfile according to the dockerfile analysis strategy to obtain a grammar keyword in the dockerfile, and performing grammar check on the grammar keyword to obtain the dynamic parameter in the grammar keyword. And adjusting the dynamic parameters according to the program package to obtain target dynamic parameter values. And updating the dockerfile according to the target dynamic parameter value to obtain a target dockerfile corresponding to the target dynamic parameter value. And constructing a mirror image according to the target dockerfile and preset configuration information. The following are detailed below.
The Docker image is a read-only template, an independent file system, which provides files of programs, libraries, resources, configuration, etc. required by the container runtime, and also includes some configuration parameters (such as anonymous volumes, environment variables, users, etc.) prepared for the runtime, which can be used to create new containers. The Docker image is actually composed of system files one layer by one layer, and the file system of this hierarchy is called a unified file system (Union file system, Union FS), and the image can be constructed based on a Docker file, which is a description file and includes a plurality of commands, and each command creates a new hierarchical structure for the base file system.
Docker provides a simpler mechanism to create or update existing images. The user can directly download a finished mirror image from other people for direct use. Docker runs applications or packages with containers; the docker container is a running instance created by a docker image, and is similar to a virtual machine and can execute actions including starting, stopping, deleting and the like. The container will run a specific application, including the code of the specific application and the required dependency files. The container can be regarded as a simple version of linux environment (containing root user rights, process space, user space, network space, etc.) and the application running therein. The container is dynamic with respect to mirroring, and creates a writable level as the top level at startup.
As shown in fig. 2, a schematic flowchart of an embodiment of a mirror image constructing method provided by the present application is shown, where the method includes:
21. and acquiring a preset program package containing parameter values.
22. Creating a construction strategy of the image file, wherein the construction strategy comprises a dockerfile compiling strategy, a dockerfile analyzing strategy and a dockerfile checking strategy.
23. And compiling the dockerfile according to the dockerfile compiling strategy.
24. And analyzing the dockerfile according to the dockerfile analysis strategy to obtain a grammar keyword in the dockerfile, and performing grammar check on the grammar keyword to obtain the dynamic parameter in the grammar keyword.
25. And adjusting the dynamic parameters according to the program package to obtain target dynamic parameter values.
26. Updating the dockerfile according to the target dynamic parameter value to obtain a target dockerfile corresponding to the target dynamic parameter value;
27. and constructing a mirror image according to the target dockerfile and preset configuration information.
According to the mirror image construction method, in the mirror image creation process, the grammar keywords in the dockerfile are checked; only when the grammar keyword is legal, the construction process can be executed according to the dockerfile, and the success rate of mirror image construction is improved. Meanwhile, dynamic parameter values in the dockerfile are dynamically changed in an external program package uploading mode, the dockerfile does not need to be rewritten for many times, and manpower and material resources are greatly reduced.
If the mirror image is to be created, the construction rule of the mirror image needs to be created first. In some embodiments of the present application, the construction rules of the image may include a package, wherein the package needs to be run in the image. The system also comprises an image file, namely a dockerfile file, wherein the dockerfile file is a text document containing commands for combining images, any command can be called in a command line, and the docker automatically generates images by reading the commands in the dockerfile file. I.e., the dockerfile file includes some step instructions of the image in the build process that are applied to the base image and ultimately create a new image. The construction rule of the image can also include some basic configuration information of the image in the construction process, such as preset configuration information of environment variables, scripts before the container stops, after the container starts, container health check and the like.
In some embodiments of the present application, the method for constructing the image may include obtaining a preset package containing parameter values, where the package is a file that needs to be run in the image. Specifically, in the embodiment of the application, a user can upload a package in any format through a web page and store the uploaded package. When storing an uploaded package, the upload time of the package may be added to a suffix of the package name to ensure uniqueness of the package name.
And mirror image information such as a mirror image name, a mirror image version and the like of the current mirror image is required to be acquired while the program package is uploaded. Because for different versions of images, the different versions of images cause the problem that the network walls cannot intercommunicate and the images cannot be compatible.
After the program package is uploaded, a construction strategy of the image file is also required to be created, and the construction strategy of the image file can also comprise a compiling strategy of the dockerfile, an analyzing strategy of the dockerfile and a checking strategy of the dockerfile.
Specifically, in some embodiments of the present application, writing a dockerfile according to a dockerfile writing policy may include: acquiring a dockerfile template file; and compiling the dockerfile according to the dockerfile template file. The dockerfile is generally divided into four parts, including: basic mirror image information, maintainer information, mirror image operation instructions and execution instructions when the container is started. For the purposes of the present application, writing a dockerfile mainly refers to writing a plurality of instructions in the dockerfile.
In the embodiment of the application, a user writes a dockerfile, so that a dockerfile template file can be directly obtained, and the required dockerfile is written on the basis of the template file. The method comprises the steps of obtaining Jetty, Dubbo and Nginx types of dockerfile template files, enabling a user to select one type of dockerfile template file as a target template file in a self-organizing mode, and writing the dockerfile file with the target template file. The specific writing process may be performed in a dockerfile editing tool, which is not limited herein.
In an embodiment of the present application, the dockerfile includes a plurality of syntax keys, and the syntax keys may be self-paraphrased, supporting annotations. In particular, the grammar key may be composed of two parts, including comments and commands, and parameters.
In embodiments of the present application, the grammar keywords may include not only official-specified keyword commands but also keyword commands that are considered custom. For example, a custom keyword command is provided in the present application, and the custom keyword command may be a keyword command corresponding to a function for implementing an add, subtract, multiply and divide algorithm.
There are many common dockerfile commands, where the first bar of the dockerfile file must be a "FROM" command that specifies which base image the dockerfile file is based on, and only one base image is specified to perform other operations on this image basis. If multiple images are created with the same dockerfile file, then multiple "FROM" commands can be used, one image for each command.
Wherein, the format of the "FROM" command is: FROM < image > Or FROM < image > Constructed of tag & gt. Specifically, a "FROM" command may be:
FROM centos
FROM centos:latest
the "MAINTAINER" command is primarily used to specify author information, and the format of the "MAINTAINER" command is: MAINTAIN < name >
Specifically, one "MAINTAINER" command may be: MAINTAINER test test @ example.
The "CMD" command is used to specify the commands used to start the container, and has three formats, respectively:
CMD["executable","param1","param2"]
CMD command param1 param2
CMD["param1","param2"]
in the dockerfile, since the "CMD" command is used to specify a command used when the container is started, only one "CMD" command exists in one dockerfile. The Dockerfile file further includes a plurality of other commands, each of which has a different role in the creation of the image, and reference may be made to the prior art, which is not limited herein.
After a dockerfile which needs to be subjected to mirror image creation is compiled by using a dockerfile template file, the dockerfile needs to be analyzed according to a dockerfile analysis strategy to obtain a grammar keyword in the dockerfile, and then a dynamic parameter in the grammar keyword is obtained. Specifically, after the dockerfile is written, the dockerfile is checked and detected to ensure that the dockerfile is written legally, and a mirror image can be created by using the written dockerfile.
As shown in fig. 3, a schematic flow diagram of an embodiment of parsing a dockerfile by using a parsing policy provided by the present application is provided, and in some embodiments of the present application, parsing the dockerfile according to the dockerfile parsing policy to obtain a syntax keyword in the dockerfile so as to obtain a dynamic parameter in the syntax keyword, where the parsing policy includes:
31. and analyzing the docker file by using a preset docker analyzer to obtain the grammar keywords.
32. Acquiring a preset keyword verifier corresponding to the grammar keyword;
33. and verifying whether the grammar keyword is legal or not by using the keyword verifier.
34. And if the grammar key words are legal, analyzing to obtain the dynamic parameters in the grammar key words.
Before the docker file is verified, a docker parser needs to be created, and the docker parser is used for parsing the docker file. Specifically, the parsing the dockerfile file by using the docker parser to obtain the syntax keyword may include: reading each line of the dockerfile file from top to bottom in sequence according to a preset analysis rule; and intercepting the grammar key words of each line in the dockerfile.
The preset rule can be analyzed regularly, that is, the dockerfile file is analyzed by using the regular analysis. Specifically, the docker parser reads the content of each line of the docker file sequentially from top to bottom by using the regular parsing, and the docker parser may be a regular parser. The specific process of analyzing the dockerfile by using the regular analysis may refer to the prior art, which is not limited herein.
It should be noted that, in the process of parsing the docker file, in a specific docker file, the content after "#" is treated as an annotation, that is, all the content between "#" and the line feed character is treated as an annotation text and is not executed, which is one of the grammatical requirements of the docker official. And in the analysis process, the regular analysis can automatically filter the empty rows in the dockerfile.
When each line in the dockerfile file is read in sequence by regular parsing, a keyword command before a first blank character of each line and content corresponding to the keyword command are intercepted. If an exception occurs during the reading process, the parsing of the dockerfile is also automatically terminated. Specifically, an exception may mean that a command in the dockerfile is not written according to an existing syntax rule. Such as: RUNecho 'hello', wherein RUN and echo are linked together.
In some embodiments of the present application, before parsing the dockerfile, it is also necessary to initialize syntax keywords in the dockerfile. Specifically, an initial syntax keyword in the dockerfile file is initialized according to preset first configuration information to obtain the syntax keyword. Because different grammar keywords have different writing rules and different corresponding purposes, the initial grammar keywords in the dockerfile file need to be initialized to obtain a format that can be analyzed by the docker analyzer. The specific process of initializing the initial syntax key can refer to the prior art, and is not limited herein.
After the parser is used to obtain the grammar keywords, the grammar keywords also need to be checked to judge whether the grammar keywords are legal. If the grammar key words are legal, the dynamic parameters in the grammar key words can be analyzed. Specifically, a keyword verifier corresponding to a preset grammar keyword may be obtained, and the keyword verifier may be used to verify whether the grammar keyword is legal.
And verifying whether the grammar keywords are legal, namely verifying whether the writing of the grammar keywords accords with a general grammar keyword writing rule. That is, whether the grammar keywords meet the grammar format requirements defined by the docker official, the detailed requirements can be found in the docker official, and the detailed description is omitted here.
In the embodiment of the application, if the syntax keyword obtained by analysis is verified to be legal, the syntax keyword can be analyzed to obtain the dynamic parameter in the syntax keyword. Specifically, if the grammar keyword is legal, the command content corresponding to the grammar keyword can be intercepted; and analyzing the command content to obtain the dynamic parameters in the command content. Meanwhile, if the grammar keyword is illegal, the dockerfile file needs to be rewritten and analyzed and verified again. The analysis method provided by the application is based on regular analysis, can support the compatibility between subsequent expansion and different versions, and is high in analysis speed. In a specific embodiment of the present application, when a dockerfile is analyzed, the content of 100 rows of dockerfile is analyzed, and the analysis time is about 1ms, which meets the requirement of commercial use.
In the embodiment of the application, while the dockerfile is analyzed to obtain the grammar keywords, the ARG parameter value corresponding to the dockerfile can be analyzed from the dockerfile. The ARG is an instruction of the docker authority, which may allow the replacement of the replacement symbol in the docker file with an actual parameter value, i.e. with a specific ARG parameter value, during the creation of the docker image.
The format of the ARG instruction may be: "ARG < key > [ < default value > ]". Wherein the ARG and the key are separated by a blank symbol; and the part of [ < default value > ] can be changed, if existing, the default value is set, and in the process of building the image, if no new value is introduced, the image can be built by using the default value. In the dockerfile, an ARG command may also exist, so after the ARG command is resolved, the ARG command and a corresponding parameter value need to be saved, where key represents an ARG key, and value is a specific parameter value of the ARG. After the ARG command is analyzed, the specific ARG parameter value, that is, the specific parameter value corresponding to the value, may be stored according to the rule that key is equal to value.
Specifically, the analysis to obtain the ARG parameter may be that the regular analysis matches a first variable and a second variable in the ARG parameter in the dockerfile, and stores the second variable. Wherein, the first variable may be ﹩ { variable }, which is a replacement symbol; the second variable may be the ﹩ variable, which is the actual ARG parameter value. In one particular embodiment, replacing the first variable with a second variable may be replacing the first variable ﹩ { name } representing a name with the actual name Bob, i.e., the second variable, which is also the specific ARG parameter value. I.e. the ARG parameter value is not necessarily a single value.
In the embodiment of the application, a program package is uploaded, and the program package comprises specific parameter values; the dockerfile can be rewritten by using the program package without rewriting the dockerfile every time, so that manpower and material resources are saved. Thus, in the present application, a complete image creation policy may include: uploading a program package, compiling a dockerfile file, and acquiring preset configuration information during mirror image creation. The preset configuration information may include environment variables, scripts before and after the container is stopped, and health checks of the container.
As shown in fig. 4, which is a schematic flow chart of an embodiment of updating a dockerfile provided by the present application, in some embodiments of the present application, updating the dockerfile according to a target dynamic parameter value to obtain a target dockerfile corresponding to the target dynamic parameter value may include:
41. it is determined whether the package is to be updated.
42. And if so, uploading and storing a new target program package needing to be updated.
43. And updating the dynamic parameters according to the target program package to obtain a construction instruction.
44. And updating the dockerfile file according to the construction instruction to obtain the target dockerfile.
If a new mirror image needs to be created, the dynamic parameters in the dockerfile file can be updated by using an externally uploaded target program package to obtain a new construction instruction. And updating the dockerfile according to the new construction instruction to obtain the target dockerfile.
On the basis of the above embodiment, after the target dockerfile is obtained, the construction instruction in the target dockerfile may be executed according to the dockerfile to obtain the mirror image.
FIG. 5 is a diagram illustrating one embodiment of a full image creation policy provided herein. When the mirror image creating strategy is created, if a user uploads a program package for the first time or updates the program package, the user can select to click to upload on the operation interface, the operation interface pops up a pop-up box, and at the moment, the user can select a local program package to upload and click to confirm on the operation interface. When the program package is uploaded, the current uploading time can be added to the suffix of the program package so as to ensure the uniqueness of the program package name. After uploading is successful, the operation page can have successful icon prompt, and meanwhile, the program package can be stored. In one embodiment of the present application, the uploaded package may be stored in a designated Object Storage Service (OSS). The object storage OSS is a cloud storage service which is high in mass, safe, low in cost and reliable, and is suitable for storing any type of files. The capacity and the processing capacity are flexibly expanded, a plurality of storage types are selected, and the storage cost is comprehensively optimized.
Meanwhile, if the user needs to replace the original program package, the user moves the mouse to the name of the program package on the operation interface, a deleted icon appears, the user can click 'delete' at the moment, the program package in the object storage OSS is deleted, and then the user uploads a new program package.
When uploading the program package, the user can also acquire the name of the current mirror image, the version of the mirror image and other mirror image information so as to ensure that the problems of incompatibility of the mirror image version and the like can not occur.
In this embodiment, after uploading the package and obtaining the information such as the name and version of the mirror image, the user needs to write a dockerfile. Wherein, the dockerfile template file can be used for writing the required dockerfile. After the compilation is finished, the grammar of the dockerfile is checked to verify whether the dockerfile is legal or not, namely whether the compilation of the dockerfile meets the existing compilation rule or not is verified; if the compiled dockerfile is legal, the dockerfile can be analyzed, the ARG parameters in the dockerfile are analyzed, the dockerfile is stored in an object storage OSS (object storage system), and the analyzed ARG parameters are stored in a basic Database (DB).
In the embodiment of the application, after the program package is uploaded and the dockerfile file is written, other optional configuration items in the mirror image creation process, such as environment variables, a script before the container is stopped, a script after the container is started, and preset configuration information of container health check, need to be acquired. The preset configuration information is some information necessary in the process of image creation. And the information is also stored in the object store OSS.
In some embodiments of the present application, after the build policy for image creation is created, an image may be created using the policy. And triggering execution operation on an operation interface by a user, wherein the operation interface pops up a pop-up box to prompt the user of the current latest program package, the current latest mirror image version and the unassigned ARG parameters. If the user does not update the program package, the default program package in the mirror image construction strategy is utilized to convert the default program package into a construction instruction; if the user updates the program package, the dynamic parameter value, namely the ARG parameter value, in the dockerfile file is updated according to the newly uploaded program package, namely the construction instruction is converted into the participatory construction instruction. Therefore, the dockerfile is updated by means of the externally uploaded program package, so that frequent dockerfile modification can be avoided, and manpower and material resources are saved.
In the mirror image construction process, a remote operation platform tool can be used for downloading the dockerfile and the preset configuration information from the object storage OSS to the specified directory of the remote mirror image construction machine, and the construction machine is specified to execute the construction instruction in the dockerfile.
In some embodiments of the present application, in the building process of the mirror image, the method for building the mirror image further includes: in the construction process of the mirror image, creating a mirror image construction log; after the mirror image construction is finished, outputting a construction result of the mirror image; and storing the construction log and the construction result.
Specifically, in the process of constructing the mirror image, a mirror image construction log needs to be created and temporarily stored locally; regardless of whether the mirror construction is successful, it is necessary to output the construction result of the mirror to the construction log. After the mirror image construction is completed, the construction log containing the construction result needs to be stored in the object storage OSS, and meanwhile, the expired log needs to be deleted regularly, so that the situation that more and more construction logs in the object storage OSS are not convenient to search is avoided.
After the mirror image is constructed, the front-end server can also conveniently inquire and construct the log and display the log according to the construction serial number through the construction service.
The present application further provides a mirror image constructing apparatus, as shown in fig. 6, which is a schematic diagram of an embodiment of the mirror image constructing apparatus provided in the present application, and the mirror image constructing apparatus 60 includes:
an obtaining unit 601, where the obtaining unit 601 is configured to obtain a preset program package containing parameter values.
The file creating unit 602, the file creating unit 602 is configured to create a construction policy of the image, where the construction policy includes a dockerfile writing policy, a dockerfile parsing policy, and a dockerfile checking policy.
And the compiling unit 603 is used for compiling the dockerfile according to the dockerfile compiling strategy by the compiling unit 603.
And the parsing and checking unit 604 is configured to parse the dockerfile according to the dockerfile parsing strategy to obtain a syntax keyword in the dockerfile, and perform syntax checking on the syntax keyword to obtain a dynamic parameter in the syntax keyword.
And an adjusting unit 605, where the adjusting unit 605 is configured to adjust the dynamic parameter according to the program package to obtain a target dynamic parameter value.
And the updating unit 606, where the updating unit 606 is configured to update the dockerfile file according to the target dynamic parameter value, and obtain a target dockerfile file corresponding to the target dynamic parameter value.
And the mirror image construction unit 607, the mirror image construction unit 607 is configured to construct a mirror image according to the target dockerfile and the preset configuration information.
The mirror image creating device provided by the application checks the grammar keywords in the dockerfile file in the mirror image creating process; only when the grammar keyword is legal, the construction process can be executed according to the dockerfile, and the success rate of mirror image construction is improved. Meanwhile, dynamic parameter values in the dockerfile are dynamically changed in an external program package uploading mode, the dockerfile does not need to be rewritten for many times, and manpower and material resources are greatly reduced.
In some embodiments of the present application, the writing unit 603 may be specifically configured to obtain a dockerfile template file; and compiling the dockerfile according to the dockerfile template file.
In some embodiments of the present application, the parsing and checking unit 604 may be specifically configured to parse a docker file by using a preset docker parser to obtain a syntax keyword; acquiring a preset keyword verifier corresponding to the grammar keyword; verifying whether the grammar keyword is legal or not by using a keyword verifier; and if the grammar key words are legal, analyzing to obtain the dynamic parameters in the grammar key words.
The parsing and checking unit 604 may be further configured to initialize an initial syntax keyword in the dockerfile file according to preset first configuration information to obtain the syntax keyword.
The parsing and checking unit 604 parses the docker file by using a preset docker parser to obtain the syntax keywords, which may specifically include: the parsing and checking unit 604 reads each line of the dockerfile file from top to bottom in sequence according to a preset parsing rule; and intercepting the grammar key words in each line of the dockerfile.
The parsing and checking unit 604 may be further configured to, if the syntax keyword is legal, intercept command content corresponding to the syntax keyword; and analyzing the command content to obtain the dynamic parameters in the command content.
The parsing and checking unit 604 may be further configured to: and if the grammar keywords are illegal, rewriting the dockerfile. Specifically, if the syntax keyword is illegal, the parsing and checking unit 604 sends a signal for rewriting to the writing unit 603, so that the writing unit 603 rewrites the dockerfile.
In some embodiments of the present application, the adjusting unit 605 may specifically be configured to determine whether to update the package; if the target program package needs to be updated, uploading and storing the target program package; and updating the dynamic parameters according to the target program package to obtain a construction instruction.
The updating unit 606 may be specifically configured to update the dockerfile file according to the building instruction, so as to obtain the target dockerfile file.
The present application further provides a server that integrates any one of the image creating apparatuses provided in the embodiments of the present application, as shown in fig. 7, which shows a schematic structural diagram of the server related to the embodiments of the present application, specifically:
the server may include components such as a processor 701 of one or more processing cores, memory 702 of one or more computer-readable storage media, a power supply 703, and an input unit 704. Those skilled in the art will appreciate that the server architecture shown in FIG. 7 is not meant to be limiting, and may include more or fewer components than those shown, or some components may be combined, or a different arrangement of components.
Wherein:
the processor 701 is a control center of the server, connects various parts of the entire server using various interfaces and lines, and performs various functions of the server and processes data by running or executing software programs and/or modules stored in the memory 702 and calling data stored in the memory 702, thereby performing overall monitoring of the server. Optionally, processor 701 may include one or more processing cores; preferably, the processor 701 may integrate an application processor, which mainly handles operating systems, user interfaces, application programs, etc., and a modem processor, which mainly handles wireless communications. It will be appreciated that the modem processor described above may not be integrated into the processor 701.
The memory 702 may be used to store software programs and modules, and the processor 701 executes various functional applications and data processing by operating the software programs and modules stored in the memory 702. The memory 702 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application program required by at least one function (such as a sound playing function, an image playing function, etc.), and the like; the storage data area may store data created according to the use of the server, and the like. Further, the memory 702 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other volatile solid state storage device. Accordingly, the memory 702 may also include a memory controller to provide the processor 701 with access to the memory 702.
The server further includes a power source 703 for supplying power to each component, and preferably, the power source 703 may be logically connected to the processor 701 through a power management system, so as to implement functions of managing charging, discharging, and power consumption through the power management system. The power supply 703 may also include any component including one or more of a dc or ac power source, a recharging system, a power failure detection circuit, a power converter or inverter, a power status indicator, and the like.
The server may also include an input unit 704, and the input unit 704 may be used to receive input numeric or character information and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control.
Although not shown, the server may further include a display unit and the like, which will not be described in detail herein. Specifically, in this embodiment, the processor 701 in the server loads the executable file corresponding to the process of one or more application programs into the memory 702 according to the following instructions, and the processor 701 runs the application program stored in the memory 702, thereby implementing various functions as follows:
acquiring a preset program package containing parameter values; creating a construction strategy of the mirror image, wherein the construction strategy comprises a dockerfile compiling strategy, a dockerfile analyzing strategy and a dockerfile checking strategy; compiling a dockerfile according to a dockerfile compiling strategy; analyzing the dockerfile according to a dockerfile analysis strategy to obtain a grammar keyword in the dockerfile, and checking the grammar keyword to obtain a dynamic parameter in the grammar keyword; adjusting the dynamic parameters according to the program package to obtain target dynamic parameter values; and updating the dockerfile according to the target dynamic parameter value to obtain a target dockerfile corresponding to the target dynamic parameter value. The following are detailed below.
The present application also provides a computer-readable storage medium, which may include: read Only Memory (ROM), Random Access Memory (RAM), magnetic or optical disks, and the like. The storage medium stores a computer program, and the computer program is loaded by the processor to execute the steps in any one of the methods for training a character recognition model provided in the embodiments of the present application. For example, the computer program may be loaded by a processor to perform the steps of:
acquiring a preset program package containing parameter values; creating a construction strategy of the mirror image, wherein the construction strategy comprises a dockerfile compiling strategy, a dockerfile analyzing strategy and a dockerfile checking strategy; compiling a dockerfile according to a dockerfile compiling strategy; analyzing the dockerfile according to a dockerfile analysis strategy to obtain a grammar keyword in the dockerfile, and checking the grammar keyword to obtain a dynamic parameter in the grammar keyword; adjusting the dynamic parameters according to the program package to obtain target dynamic parameter values; and updating the dockerfile according to the target dynamic parameter value to obtain a target dockerfile corresponding to the target dynamic parameter value. The following are detailed below.
In the above embodiments, the descriptions of the respective embodiments have respective emphasis, and parts that are not described in detail in a certain embodiment may refer to the above detailed descriptions of other embodiments, and are not described herein again.
In a specific implementation, each unit or structure may be implemented as an independent entity, or may be combined arbitrarily to be implemented as one or several entities, and the specific implementation of each unit or structure may refer to the foregoing method embodiment, which is not described herein again.
The mirror image construction method, device, server and storage medium provided by the embodiments of the present application are introduced in detail above, and a specific example is applied in the present application to explain the principle and the embodiments of the present application, and the description of the above embodiments is only used to help understanding the method and the core idea of the present application; meanwhile, for those skilled in the art, according to the idea of the present application, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present application.

Claims (10)

1. A method of image construction, the method comprising:
acquiring a preset program package containing parameter values;
creating a construction strategy of the image file, wherein the construction strategy comprises a dockerfile compiling strategy, a dockerfile analyzing strategy and a dockerfile checking strategy;
writing the dockerfile according to the dockerfile writing strategy;
analyzing the dockerfile according to the dockerfile analysis strategy to obtain a grammar keyword in the dockerfile, and performing grammar check on the grammar keyword to obtain a dynamic parameter in the grammar keyword;
adjusting the dynamic parameters according to the program package to obtain the target dynamic parameter values;
updating the dockerfile according to the target dynamic parameter value to obtain a target dockerfile corresponding to the target dynamic parameter value;
and constructing the mirror image according to the target dockerfile and preset configuration information.
2. An image construction method according to claim 1, wherein said authoring of said dockerfile according to said dockerfile authoring policy comprises: acquiring a dockerfile template file; and compiling the dockerfile according to the dockerfile template file.
3. The image construction method according to claim 1, wherein the parsing the dockerfile according to the dockerfile parsing policy to obtain a syntax keyword in the dockerfile, and performing syntax checking on the syntax keyword to obtain a dynamic parameter in the syntax keyword includes:
analyzing the docker file by using a preset docker analyzer to obtain the grammar keywords;
acquiring a preset keyword verifier corresponding to the grammar keyword;
verifying whether the grammar keyword is legal or not by using the keyword verifier;
and if the grammar key words are legal, analyzing to obtain the dynamic parameters in the grammar key words.
4. An image construction method according to claim 3, wherein before parsing the dockerfile file to obtain the syntax key by using a preset docker parser, the method further comprises:
initializing an initial grammar keyword in the dockerfile according to preset first configuration information to obtain the grammar keyword.
5. An image construction method according to claim 3, wherein the parsing the docker file by using a preset docker parser to obtain the syntax key includes:
reading each line of the dockerfile file from top to bottom in sequence according to a preset analysis rule;
intercepting the grammar keywords in each line of the dockerfile.
6. A method according to claim 3, wherein if the syntax key is legal, parsing to obtain the dynamic parameters in the syntax key comprises:
if the grammar keyword is legal, intercepting command content corresponding to the grammar keyword;
and analyzing the command content to obtain the dynamic parameters in the command content.
7. The docker image construction method according to claim 3, wherein the parsing the docker file according to the docker file parsing policy to obtain a syntax key in the docker file so as to obtain a dynamic parameter in the syntax key, further comprises: and if the grammar keyword is illegal, rewriting the dockerfile.
8. A mirror image construction method according to claim 1, wherein the updating the dockerfile according to the target dynamic parameter value to obtain a target dockerfile corresponding to the target dynamic parameter value comprises:
judging whether to update the program package;
if the target program package is updated, uploading and storing a new target program package needing to be updated;
and updating the dynamic parameters according to the target program package to obtain a construction instruction.
And updating the dockerfile according to the construction instruction to obtain a target dockerfile.
9. The image construction method of claim 8, further comprising:
and executing a construction instruction in the target dockerfile according to the target dockerfile to obtain the mirror image.
10. The image construction method of claim 1, further comprising:
creating a mirror image construction log in the construction process of the mirror image;
after the mirror image construction is finished, outputting a construction result of the mirror image;
and storing the construction log and the construction result.
CN202010434650.2A 2020-05-21 2020-05-21 Mirror image construction method and device, server and storage medium Pending CN113703825A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010434650.2A CN113703825A (en) 2020-05-21 2020-05-21 Mirror image construction method and device, server and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010434650.2A CN113703825A (en) 2020-05-21 2020-05-21 Mirror image construction method and device, server and storage medium

Publications (1)

Publication Number Publication Date
CN113703825A true CN113703825A (en) 2021-11-26

Family

ID=78645751

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010434650.2A Pending CN113703825A (en) 2020-05-21 2020-05-21 Mirror image construction method and device, server and storage medium

Country Status (1)

Country Link
CN (1) CN113703825A (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107885551A (en) * 2017-11-27 2018-04-06 山东浪潮商用系统有限公司 A kind of service arrangement method, apparatus, computer-readable recording medium and storage control
CN108255675A (en) * 2018-01-10 2018-07-06 北京知道创宇信息技术有限公司 A kind of port diagnostic extracting method, device and computing device
CN109683901A (en) * 2018-11-28 2019-04-26 武汉烽火信息集成技术有限公司 A kind of Dockerfile checks optimization system and method
CN110688137A (en) * 2019-09-27 2020-01-14 支付宝(杭州)信息技术有限公司 Application delivery method and device and storage medium

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107885551A (en) * 2017-11-27 2018-04-06 山东浪潮商用系统有限公司 A kind of service arrangement method, apparatus, computer-readable recording medium and storage control
CN108255675A (en) * 2018-01-10 2018-07-06 北京知道创宇信息技术有限公司 A kind of port diagnostic extracting method, device and computing device
CN109683901A (en) * 2018-11-28 2019-04-26 武汉烽火信息集成技术有限公司 A kind of Dockerfile checks optimization system and method
CN110688137A (en) * 2019-09-27 2020-01-14 支付宝(杭州)信息技术有限公司 Application delivery method and device and storage medium

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
耿朋1, 2;陈伟2;魏峻2: "面向Dockerfile的容器镜像构建工具", 《 计算机系统应用》, vol. 25, no. 11, pages 14 - 21 *

Similar Documents

Publication Publication Date Title
CN107766126B (en) Container mirror image construction method, system and device and storage medium
US9465590B2 (en) Code generation framework for application program interface for model
CN111901294A (en) Method for constructing online machine learning project and machine learning system
US11016785B2 (en) Method and system for mirror image package preparation and application operation
CN111309335B (en) Compiling method and device of plug-in application and computer readable storage medium
US20100281463A1 (en) XML based scripting framework, and methods of providing automated interactions with remote systems
US20100205604A1 (en) Systems and methods for efficiently running multiple instances of multiple applications
JP2004013903A (en) Mechanism for downloading software component from remote source for using local software application
JP2005182809A (en) Creating file system within file in storage technology-abstracted manner
US7246224B2 (en) System and method to enable platform personality migration
US20230036357A1 (en) Method and apparatus for authority control, computer device and storage medium
US9513762B1 (en) Static content updates
CN112698921A (en) Logic code operation method and device, computer equipment and storage medium
CN114281653B (en) Application program monitoring method and device and computing equipment
CN115268879A (en) Code processing method and device, electronic equipment and storage medium
WO2023039741A1 (en) Online development method and apparatus based on microservice system, device, and storage medium
CN111984300B (en) Code copying method and device, electronic equipment and computer readable storage medium
US9244706B2 (en) Command line shell command generation based on schema
CN111290740B (en) Application program development method and device, computer equipment and storage medium
CN110874220B (en) Function integration method, apparatus and storage medium in game application
CN113703825A (en) Mirror image construction method and device, server and storage medium
CN115794253A (en) Application integration method and device, electronic equipment and computer readable storage medium
WO2011157105A2 (en) Method and device for component expansion
US20220012049A1 (en) Synchronization of Source Code Under Development in Multiple Concurrent Instances of an Integrated Development Environment
CN113901025A (en) Database management method, device, equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination