Mirror image tracing method and device, computer program product and electronic equipment
By generating and matching the historical construction record data of the container image, determining the parent image and storing it in the mirror traceability table, the problem of inaccurate traceability of container images is solved, and efficient and low-cost mirror traceability is achieved.
Patent Information
- Application Number
- CN202510670712.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-22
- Publication Date
- 2025-08-15
Smart Images

Figure CN120493225A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present disclosure relate to the field of computer technology, and more particularly, to an image tracing method and apparatus, a computer program product, and an electronic device. Background Art
[0002] With the continuous development of cloud-native and containerized technologies, Docker technology has become an indispensable basic technology in the software industry. However, as the scale of Docker container usage continues to increase, how to manage and operate more and more container images has become a major challenge in the cloud-native and security fields.
[0003] In related technologies, most determine the relationship between images by comparing multiple layers of hash values. However, many images execute shell commands or set environment variables during construction, which does not generate new image layers, resulting in low image traceability accuracy. Others rely on blockchain technology to determine the relationship between images. Regardless of traceability accuracy, achieving traceability requires deploying a blockchain application environment, which is relatively costly in both technical and resource costs. Furthermore, existing image traceability still faces the problem of large storage requirements. The traceability data relationships of all container images must be stored in data storage media to achieve traceability.
[0004] Therefore, a new image tracing method needs to be provided.
[0005] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present invention, and therefore may include information that does not constitute prior art known to ordinary technicians in this field. Summary of the Invention
[0006] The present disclosure provides an image tracing method, an image tracing device, a computer program product, and an electronic device, thereby overcoming, at least to a certain extent, the problems of low image tracing accuracy and large data storage volume in the related art caused by the limitations and defects of the related art.
[0007] According to one aspect of the present disclosure, a mirror traceability method is provided, comprising:
[0008] Obtaining a container image and a historical build command corresponding to the container image, generating image build history record data based on the historical build command, and generating image history data based on the image build history record data;
[0009] Matching the image history data of the first container image with the image history data of the container image to obtain a parent image of the first container image in the container image;
[0010] The first container image and the parent image of the first container image are stored in an image traceability table, and based on the image traceability table, bidirectional traceability is performed to obtain a traceability result of the container image to be traced.
[0011] According to one aspect of the present disclosure, there is provided an image traceability device, comprising:
[0012] An image history data generation module is configured to obtain a container image and a historical build command corresponding to the container image, generate image build history record data based on the historical build command, and generate image history data based on the image build history record data;
[0013] a parent image determination module, configured to match the image history data of the first container image with the image history data of the container image to obtain the parent image of the first container image in the container image;
[0014] The traceability module is used to store the first container image and the parent image of the first container image in an image traceability table, and perform bidirectional traceability based on the image traceability table to obtain a traceability result of the container image to be traced.
[0015] According to one aspect of the present disclosure, a computer program product is provided, on which a computer program is stored. When the computer program is executed by a processor, the method described in any one of the above exemplary embodiments is implemented.
[0016] According to one aspect of the present disclosure, there is provided an electronic device, including:
[0017] A processor; a memory for storing executable instructions of the processor; wherein the processor is configured to perform the method described in any one of the above exemplary embodiments by executing the executable instructions.
[0018] An embodiment of the present disclosure provides an image tracing method, which obtains a container image and a historical build command corresponding to the container image, generates image build history record data based on the historical build command, and generates image history data based on the image build history record data; matches the image history data of a first container image with the image history data of the container image to obtain the parent image of the first container image in the container image; stores the first container image and the parent image of the first container image in an image traceability table, and performs bidirectional traceability based on the image traceability table to obtain a traceability result of the container image to be traced. On the one hand, image build history record data is generated according to the historical build command of the container image, and image history data is generated according to the image build history record data, the image history data of different container images are matched, the parent image of the container image is determined, and the parent image is stored in the image traceability table. By using the image history data as the main traceability data source, the problem of inaccurate image traceability in related technologies is solved, the accuracy of container image traceability is improved, and the cost of container image traceability is reduced; on the other hand, after obtaining the image traceability table, the image traceability table can be used to perform bidirectional traceability on the traceable container to obtain the traceability result, thereby improving the efficiency of container image traceability.
[0019] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] The accompanying drawings are incorporated into and constitute a part of this specification, illustrate embodiments consistent with the present invention, and together with the description, serve to explain the principles of the present invention. Obviously, the drawings described below are only some embodiments of the present invention, and it is clear that those skilled in the art can derive other drawings based on these drawings without inventive effort.
[0021] Figure 1 The following schematically illustrates a flowchart of an image source tracing method according to an exemplary embodiment of the present disclosure.
[0022] Figure 2 A flowchart of a method for generating image building history record data based on the historical building command according to an exemplary embodiment of the present disclosure is schematically shown.
[0023] Figure 3 A flowchart of a method for generating the image history data according to the image name, the historical build command, the total number of historical build commands, and the first build command of the container image according to an exemplary embodiment of the present disclosure is schematically shown.
[0024] Figure 4A flowchart schematically illustrates a method for matching image history data of a first container image with image history data of the container image to obtain a parent image of the first container image in the container image according to an exemplary embodiment of the present disclosure.
[0025] Figure 5 A flowchart of a method for tracing an image after obtaining the parent image of the first container image in the container image according to an exemplary embodiment of the present disclosure is schematically shown.
[0026] Figure 6 A flowchart schematically illustrates a method for storing the first container image and the parent image of the first container image in an image traceability table, and performing bidirectional traceability based on the image traceability table to obtain a traceability result of the container image to be traced according to an example embodiment of the present disclosure.
[0027] Figure 7 A flowchart of an input item tracing method according to an exemplary embodiment of the present disclosure is schematically shown.
[0028] Figure 8 A block diagram schematically illustrates a mirror image tracing device according to an exemplary embodiment of the present disclosure.
[0029] Figure 9 An electronic device for implementing an image tracing method according to an exemplary embodiment of the present invention is schematically shown. DETAILED DESCRIPTION
[0030] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in many forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that the present invention will be more comprehensive and complete and the concepts of the example embodiments will be fully conveyed to those skilled in the art. The described features, structures, or characteristics may be combined in any suitable manner in one or more embodiments. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present invention. However, those skilled in the art will appreciate that the technical solutions of the present invention may be practiced while omitting one or more of the specific details, or that other methods, components, devices, steps, etc. may be employed. In other cases, well-known technical solutions are not shown or described in detail to avoid obscuring various aspects of the present invention.
[0031] In addition, the accompanying drawings are merely schematic illustrations of the present invention and are not necessarily drawn to scale. Identical reference numerals in the figures denote identical or similar parts, and thus repetitive descriptions thereof will be omitted. Some of the blocks shown in the accompanying drawings are functional entities that do not necessarily correspond to physically or logically separate entities. These functional entities may be implemented in software, in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0032] Docker has played a revolutionary role in cloud computing, completely changing the way software lifecycles are managed, improving development and maintenance efficiency, and promoting the widespread adoption and expansion of cloud computing services. With the continuous advancement of cloud native and containerization technologies, Docker has become an indispensable foundational technology in the software industry. However, as the scale of Docker container usage continues to increase, the management and operation of an increasing number of container images has become a major challenge in the cloud native and security fields. Therefore, a technology is needed that can quickly trace and manage container images, accurately identifying their child, parent, and grandparent images. This will help reduce the number of container images and quickly locate problems.
[0033] Existing image traceability technologies often compare hash values across image layers to determine the relationships between them. However, executing shell commands or setting environment variables during most image builds doesn't generate new image layers, making it impossible to accurately trace container images. Furthermore, existing container image traceability technologies rely on blockchain technology. However, these solutions, regardless of traceability accuracy, require deploying a blockchain application environment. This carries relatively high technical and resource costs, making it difficult to achieve low-cost, fast traceability.
[0034] Furthermore, existing container image traceability technology suffers from the problem of large data storage requirements. All container image traceability data must be stored on a data storage medium to achieve traceability. This leads to high storage costs and a large amount of junk data in the case of massive container images, hindering subsequent operations and maintenance, traceability speed, and accuracy. Furthermore, traceability can only be traced back to the parent image from the current image, not to the grandparent image or the child image of the current image.
[0035] Based on one or more of the above problems, this example embodiment first provides a mirror traceability method. Figure 1 As shown, the image tracing method may include the following steps:
[0036] Step S110. Obtain a container image and a historical build command corresponding to the container image, generate image build history record data based on the historical build command, and generate image history data based on the image build history record data;
[0037] Step S120: Match the image history data of the first container image with the image history data of the container image to obtain the parent image of the first container image in the container image;
[0038] Step S130: Store the first container image and the parent image of the first container image in an image traceability table, and perform bidirectional traceability based on the image traceability table to obtain a traceability result of the container image to be traced.
[0039] The above-mentioned image traceability method obtains a container image and a historical build command corresponding to the container image, generates image build history data based on the historical build command, and generates image history data based on the image build history data; matches the image history data of the first container image with the image history data of the container image to obtain the parent image of the first container image in the container image; stores the first container image and the parent image of the first container image in an image traceability table, and performs bidirectional traceability based on the image traceability table to obtain the traceability result of the container image to be traced. On the one hand, image build history data is generated based on the historical build command of the container image, and image history data is generated based on the image build history data, and the image history data of different container images are matched to determine the parent image of the container image, and the parent image is stored in the image traceability table. By using the image history data as the main traceability data source, the problem of inaccurate image traceability in the related art is solved, the accuracy of container image traceability is improved, and the cost of container image traceability is reduced; on the other hand, after obtaining the image traceability table, the image traceability table can be used to perform bidirectional traceability on the container to be traced to obtain the traceability result, thereby improving the efficiency of container image traceability.
[0040] Hereinafter, each step involved in the image traceability method according to an exemplary embodiment of the present disclosure will be explained and illustrated in detail.
[0041] In step S110 , a container image and a historical build command corresponding to the container image are obtained, image build historical record data is generated based on the historical build command, and image history data is generated according to the image build historical record data.
[0042] The container image can be a Docker image. Docker is open source software designed to enable application development, delivery, and execution through containerization technology. Using operating system-level virtualization technology, it provides an isolated environment, enabling applications and their dependencies to run consistently across multiple computing environments. Docker provides a complete toolchain, including image building, container management, and network configuration, simplifying software development and deployment. A Docker image is an immutable file system snapshot that contains all the components required to run a specific application. Each image includes the application code, runtime environment, system tools, system libraries, and necessary configuration files. Images are the foundation for building Docker containers. At runtime, containers execute applications by loading the image and creating a writable layer on top of it. Image build history data records the image build process and its evolution. Each image consists of a series of sequentially stacked layers. Image build history data details the creation commands, timestamps, and corresponding changes for each layer. This information is crucial for understanding the image build steps and version evolution, helping ensure software transparency and traceability. Image build history data can be queried using the command docker history {image name}.
[0043] In an exemplary embodiment, the container image and the historical build command corresponding to the container image can be collected by using docker commands, calling container sdk, etc. After obtaining the historical build command, the image build history record data can be generated according to the historical build command. Figure 2 As shown, the generating of image build history record data based on the historical build command includes:
[0044] Step S210. Sort the historical build commands according to the execution order of the historical build commands, and encode the historical build commands;
[0045] Step S220: Generate the image building history record data according to the sorted historical building commands and the codes of the historical building commands.
[0046] Below, step S210 and step S220 will be further explained and illustrated. Specifically, after obtaining the historical build commands corresponding to the container image, they can be sorted according to the execution order of the historical build commands. After sorting, each historical build command can be encoded. During encoding, the historical build command can be converted into a corresponding hash value, or other encoding can be performed. There is no specific limitation on this in this example embodiment. When encoding the historical build command, the encoding length of each historical build command is equal. After obtaining the encoding of the historical build command, the image build history record data is generated according to the historical build command and the encoding of the historical build command.
[0047] By converting each historical build command into a code of equal length, the code can be used directly when the same historical build command is subsequently obtained, avoiding repeated saving of the same historical build command.
[0048] For example, when the obtained container image is app:1.0, the historical build commands of the container image include: 1. COPY cp* / bin / , 2. EXPOSE map[2379 / tcp:{}]. During the build process of app:1.0, command 1 is executed first and then command 2. After converting the two historical build commands into hash values of equal length, the image build history record data obtained is shown in Table 1:
[0049] Table 1app:1.0 image build history data
[0050] Id Historical build commands Historical build command encoding 1 COPY cp* / bin / 6b3f9064b9e 2 EXPOSE map[2379 / tcp:{}] 55428f94ee7
[0051] In an exemplary embodiment, after obtaining the image construction history data, image history data may be generated based on the image construction history data. Generating the image history data based on the image construction history data includes:
[0052] The image history data is generated according to the image name of the container image, the historical build command, the total number of historical build commands, and the first build command; wherein the first build command is the first historical build command after the historical build commands are sorted.
[0053] Specifically, the image history data may be generated according to the image name, historical build command, the total number of historical build commands, and the historical build command ranked first in the historical build commands of the container image in the image build history data.
[0054] For further reference, Figure 3As shown, the image history data is generated according to the image name of the container image, the historical build command, the total number of historical build commands, and the first build command, including:
[0055] Step S310: Record the image name of the container image into the image field in the image history data;
[0056] Step S320: Based on the sorting result of the historical build commands, the unique identifiers of the historical build commands are spliced to obtain a splicing identifier, and the splicing identifier is recorded in the build history field of the image history data;
[0057] Step S330: Record the total number of historical build commands into the quantity field of the image history data;
[0058] Step S340: Record the unique identifier of the first build command into the first build history field of the image history data.
[0059] Below, steps S310 to S340 will be further explained and illustrated. Specifically, the image name of the container image is recorded in the image field i-image in the image history data; the sorting result of the historical build commands in the image build history record data is obtained, and the unique identifiers of the historical build commands are spliced according to the sorting result to obtain the splicing identifier, and the splicing identifier is recorded in the build history h_sign field of the image history data; the total number of historical build commands included in the image build history record data is obtained, and the total number of historical build commands is recorded in the number field h_count of the image history data; the build command that ranks first in the historical build commands of the image build history record data is obtained, and the unique identifier of the first build command is recorded in the first build history field h_0_sign of the image history data. Among them, when splicing the unique identifiers of the historical build commands, multiple unique identifiers can be spliced by splicing characters. In this example embodiment, the splicing identifier is not specifically limited.
[0060] Exemplarily, converting the image build history record data shown in Table 1 into image history data may include: first, obtaining the name of the container image included in the image build history record data, app:1.0, and recording app:1.0 in the image field i-image; app:1.0 includes two historical build commands, and the unique identifiers of the two historical build commands are spliced to obtain the splicing identifier 1@2, and the splicing identifier 1@2 is recorded in the build history field h_sign of the image history data; app:1.0 includes two historical build commands, so the total number of historical build commands 2 is recorded in the number field h_count of the image history data; in the two build history commands, the unique identifier 1 of the first build command is recorded in the first build history field h_0_sign of the image history data. The resulting image history data is shown in Table 2:
[0061] Table 2 app:1.0 image history data
[0062] id i-image h_sign h_count h_0_sign r_hash 1 app:1.0 1@2 2 1
[0063] In Table 2, id is the unique identifier of the obtained container image app:1.0, and r_hash is the parent image of the container image app:1.0.
[0064] After obtaining the image history data of the container image, the image history data of multiple container images can be matched to obtain the dependency relationship between the container images.
[0065] In step S120 , the image history data of the first container image is matched with the image history data of the container image to obtain a parent image of the first container image in the container image.
[0066] Among them, the parent image of the container image is the lower-layer image that it depends on during its layered construction process. All layers of the parent image are read-only. The new image is superimposed with a writable layer on top of the parent image by joint mounting to achieve functional expansion.
[0067] In an exemplary embodiment, referring to Figure 4 As shown, the image history data of the first container image is matched with the image history data of the container image to obtain the parent image of the first container image in the container image, including:
[0068] Step S410. Obtain a first quantity corresponding to the quantity field in the image history data corresponding to the first container image and a unique identifier of a first first build command corresponding to the first first build history field;
[0069] Step S420. Obtain image history data of a second container image whose number is less than the first number and whose first build history field is the unique identifier of the first first build command in the image history data of the container image;
[0070] Step S430: Match the build history field in the image history data of the first container image with the build history field of the second container image to obtain the parent image of the first container image included in the second container image.
[0071] Below, steps S410 to S430 will be further explained and illustrated. Specifically, when determining the parent image of the first container image, obtain the first quantity corresponding to the quantity field in the image history data corresponding to the first container image and the unique identifier of the first first build command corresponding to the first build history field; in the container image, when there is a second container image, the value corresponding to the quantity field in the image history data of the second container image is less than the first quantity and the value corresponding to the first build history field is the unique identifier of the first first build command, then the second container image may be the parent image of the first container image. To this end, it is also necessary to match the build history field of the second container image with the build history field of the first container image. When the build history field of the second container image matches the build history field of the first container image, it is determined that the second container image is the parent image of the first container image.
[0072] Table 3 app:3.0 image history data
[0073] id i-image h_sign h_count h_0_sign r_hash 3 app:3.0 1@2@3@4@5 5 1
[0074] For example, referring to the image history data shown in Table 3, when the first container image is app:3.0, the quantity field of the first container image is 5 and the first build history field is 1. Then, it is necessary to determine the second container image with h_count < 5 and h_0_sign = 1 in the image history data of the container image. The second container image that meets the conditions is shown in Table 4:
[0075] Table 4 Mirror history data
[0076] id i-image h_sign h_count h_0_sign r_hash 1 app:1.0 1@2 2 1 2 app:2.0 1@2@3 3 1 9 app:9.0 1@4@5 3 1
[0077] In the second container image, its build history field also needs to be matched with the build history field of the first container image. The build history field of the first container image is 1@2@3@4@5. Therefore, 1@2 and 1@2@3 match the build history field 1@2@3@4@5, and 1@4@5 does not match the build history field 1@2@3@4@5. App:9.0 is removed, and the remaining container images app:1.0 and app:2.0 are the parent container images of the first container image.
[0078] In an exemplary embodiment, referring to Figure 5 As shown, after obtaining the parent image of the first container image in the container image, the method further includes:
[0079] Step S510: Encode the parent image and concatenate the encoding of the parent image of the first container image;
[0080] Step S520: Store the code of the parent image of the spliced first container image into the parent image field of the image history data.
[0081] Below, step S510 and step S520 will be further explained and illustrated. Specifically, when the first container image has only one parent image, after obtaining the parent image of the container image, the parent image can be encoded, and the encoding of the parent image can be stored in the parent image field r_hash of the image history data of the first container image. When there are multiple parent images of the first container image, each parent image can be encoded first, and the encoding of each parent image can be spliced, and the encoding of the spliced parent image can be stored in the parent image field of the image history data of the first container image. Among them, when splicing the encoding of the parent image, the splicing character can be any symbol, and the splicing character is not specifically limited in this example embodiment. By encoding the parent image of the container image and storing the code in the parent image field of the container image's image history data, when the image traceability data is generated again, the parent image code is first compared with the code in the parent image field of the container image's image history data. When there is the same data, the code in the parent image field is directly used, avoiding the infinite growth of image traceability data and improving the efficiency of subsequent operation and maintenance and traceability.
[0082] For example, when the code corresponding to the parent image app:1.0 of the first container image is 83d3d9c8c3f8 and the code corresponding to the parent image app:2.0 is e0b9f3b5c7e9, the parent image app:1.0 and the parent image app:2.0 are concatenated to obtain 83d3d9c8c3f8-e0b9f3b5c7e9, and the concatenated code is stored in the parent image field of the image history data of the first container image. The image history data of the second container image is shown in Table 5:
[0083] Table 5 Image history data of the first container image
[0084]
[0085] In step S130, the first container image and the parent image of the first container image are stored in an image traceability table, and based on the image traceability table, bidirectional traceability is performed to obtain a traceability result of the container image to be traced.
[0086] In an exemplary embodiment, after obtaining the parent image of a first container image, the first container image and its parent image can be stored in an image traceability table. Based on this image traceability table, bidirectional traceability can be performed on any container image to obtain the parent image and child image of the container image. Bidirectional traceability means that the current container image can be traced not only to its child image, but also to its parent image and the parent image of the parent image.
[0087] In an exemplary embodiment, referring to Figure 6 As shown, the first container image and the parent image of the first container image are stored in the image traceability table, and based on the image traceability table, bidirectional traceability is performed to obtain the traceability result of the container image to be traced, including:
[0088] Step S610: Store the first container image in the child image field of the image traceability table, and store the parent image of the first container image in the parent image field of the image traceability table;
[0089] Step S620: Obtain the container image to be traced, search the parent image and the child image of the container image to be traced in the image traceability table, and determine the parent image and the child image as the traceability result.
[0090] Steps S610 and S620 are further explained and illustrated below. Specifically, the first container image is stored in the child image field child_i_name of the image traceability table, and the parent image of the first container image is stored in the parent image field parent_i_name of the image traceability table. The container image to be traced is determined, and data related to the container image to be traced is searched in the image traceability table. The parent image and child image of the container image to be traced are determined from this data.
[0091] For example, the parent images of the first container image app:3.0 are app:1.0 and app:2.0. The image traceability table is shown in Table 6:
[0092] Table 6 Mirror traceability table
[0093] parent_i_name child_i_name app:1.0 app:3.0 app:2.0 app:3.0
[0094] In an exemplary embodiment, referring to Figure 7 As shown, the method further includes:
[0095] Step S710. In response to the deletion of the third container image, determine the third parent image and the third child image associated with the third container image in the image traceability table;
[0096] Step S720: Update the parent image field in the image history data of the third child image;
[0097] Step S730: Delete the historical build command corresponding to the third container image, the image history data, and the data associated with the third container image in the image traceability table.
[0098] Below, step S710-step S730 will be further explained and illustrated. Specifically, for useless container images, it is necessary to delete the image build history record data, image history data and image traceability data of the container image to avoid affecting the accuracy of traceability. After deleting the third container image in the container image, determine the third parent image and the third child image associated with the third container image in the image traceability table. After obtaining the third parent image and the third child image, update the parent image field in the image history data of the third child image, and delete the historical build command of the third container image, the image history data and the data associated with the third container image in the image traceability table.
[0099] For example, when the container image app:2.0 is the third container image to be deleted, since the container image app:2.0 is the child image of the container image app:1.0, and the container image app:2.0 is the parent image of the container image app:3.0, after deleting the container image app:2.0, it is necessary to update the parent image field in the image history data of the container image app:3.0, and update the value in the parent image field to the code corresponding to the container image app:1.0. In addition, it is also necessary to delete the historical build commands, image history data and the data of app:2.0 in the traceability data table of the container image app:2.0.
[0100] The image traceability method provided by the example embodiments of the present disclosure has at least the following advantages: on the one hand, image build history record data is generated according to the historical build command of the container image, and image history data is generated according to the image build history record data, the image history data of different container images are matched, the parent image of the container image is determined, and the parent image is stored in the image traceability table. By using the image history data as the main source of traceability data, the problem of inaccurate image traceability in related technologies is solved, the accuracy of container image traceability is improved, and the cost of container image traceability is reduced; on the other hand, after obtaining the image traceability table, the image traceability table can be used to perform bidirectional traceability on the traceable container to obtain the traceability result, thereby improving the efficiency of container image traceability.
[0101] The exemplary embodiment of the present disclosure also provides a mirror traceability device, referring to Figure 8 As shown, it may include: an image history data generation module 810, a parent image determination module 820, and a source tracing module 830. Among them:
[0102] An image history data generation module 810 is configured to obtain a container image and a historical build command corresponding to the container image, generate image build history data based on the historical build command, and generate image history data based on the image build history data.
[0103] A parent image determination module 820 is configured to match the image history data of the first container image with the image history data of the container image to obtain the parent image of the first container image in the container image;
[0104] The traceability module 830 is configured to store the first container image and the parent image of the first container image in an image traceability table, and perform bidirectional traceability based on the image traceability table to obtain a traceability result of the container image to be traced.
[0105] The specific details of each module in the above-mentioned image traceability device have been described in detail in the corresponding image traceability method, so they will not be repeated here.
[0106] In an exemplary embodiment of the present disclosure, the image history data generation module includes:
[0107] A construction command encoding module, configured to sort the historical construction commands according to the execution order of the historical construction commands and encode the historical construction commands;
[0108] The historical record data generating module is used to generate the image building historical record data according to the sorted historical building commands and the codes of the historical building commands.
[0109] In an exemplary embodiment of the present disclosure, the image history data generation module includes:
[0110] A historical data generation module is used to generate the image history data according to the image name of the container image, the historical build command, the total number of historical build commands and the first build command; wherein the first build command is the first historical build command after sorting the historical build commands.
[0111] In an exemplary embodiment of the present disclosure, the historical data generation module includes:
[0112] An image field recording module, configured to record the image name of the container image into the image field in the image history data;
[0113] A construction history field recording module is used to splice the unique identifiers of the historical construction commands according to the sorting results of the historical construction commands to obtain a splicing identifier, and record the splicing identifier in the construction history field of the image history data;
[0114] A quantity field recording module, configured to record the total number of the historical build commands into the quantity field of the image history data;
[0115] The first build history field recording module is used to record the unique identifier of the first build command into the first build history field of the image history data.
[0116] In an exemplary embodiment of the present disclosure, the parent image determination module includes:
[0117] A first container image data acquisition module is configured to acquire a first quantity corresponding to a quantity field in the image history data corresponding to the first container image and a unique identifier of a first first build command corresponding to the first first build history field;
[0118] A second container image determination module is configured to obtain image history data of a second container image whose number is less than the first number and whose first build history field is a unique identifier of the first first build command in the image history data of the container image;
[0119] A build history field matching module is used to match the build history field in the image history data of the first container image with the build history field of the second container image to obtain the parent image of the first container image included in the second container image.
[0120] In an exemplary embodiment of the present disclosure, the parent image determination module further includes:
[0121] A parent image encoding module, configured to encode the parent image and concatenate the encoding of the parent image of the first container image;
[0122] The parent image code storage module is configured to store the code of the parent image of the spliced first container image into the parent image field of the image history data.
[0123] In an exemplary embodiment of the present disclosure, the traceability module includes:
[0124] An image traceability table generation module, configured to store the first container image in the child image field of the image traceability table, and store the parent image of the first container image in the parent image field of the image traceability table;
[0125] The bidirectional tracing module is used to obtain the container image to be traced, search the parent image and the child image of the container image to be traced in the image tracing table, and determine the parent image and the child image as the tracing result.
[0126] In an exemplary embodiment of the present disclosure, the traceability module includes:
[0127] a container image deletion module, configured to respond to deletion of a third container image and determine, in the image traceability table, a third parent image and a third child image associated with the third container image;
[0128] An image history data updating module, configured to update the parent image field in the image history data of the third child image;
[0129] The associated data deletion module is used to delete the historical build command corresponding to the third container image, the image history data, and the data associated with the third container image in the image traceability table.
[0130] It should be noted that, although several modules or units of the device for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to an embodiment of the present invention, the features and functions of two or more modules or units described above can be concretized in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided into multiple modules or units to be concretized.
[0131] Furthermore, although the steps of the method of the present invention are described in a particular order in the accompanying drawings, this does not require or imply that the steps must be performed in this particular order, or that all steps must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps.
[0132] In an exemplary embodiment of the present invention, an electronic device capable of implementing the above method is also provided.
[0133] Those skilled in the art will appreciate that various aspects of the present invention may be implemented as systems, methods, or program products. Therefore, various aspects of the present invention may be implemented in the following forms: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or a combination of hardware and software implementations, which may be collectively referred to herein as "circuits," "modules," or "systems."
[0134] Refer to the following Figure 9 An electronic device 900 according to this embodiment of the present invention will be described. Figure 9 The electronic device 900 shown is merely an example and should not limit the functions and scope of use of the embodiments of the present invention.
[0135] like Figure 9 As shown, electronic device 900 is implemented as a general-purpose computing device. Components of electronic device 900 may include, but are not limited to, the aforementioned at least one processing unit 910, the aforementioned at least one storage unit 920, a bus 930 connecting various system components (including storage unit 920 and processing unit 910), and a display unit 940.
[0136] The storage unit stores program codes that can be executed by the processing unit 910, so that the processing unit 910 performs the steps according to various exemplary embodiments of the present invention described in the "Exemplary Method" section above. For example, the processing unit 910 can perform the following steps: Figure 1Step S110 shown in: obtain a container image and a historical build command corresponding to the container image, generate image build history record data based on the historical build command, and generate image history data based on the image build history record data; S120: match the image history data of the first container image with the image history data of the container image to obtain the parent image of the first container image in the container image; S130: store the first container image and the parent image of the first container image in the image traceability table, and perform bidirectional traceability based on the image traceability table to obtain the traceability result of the container image to be traced.
[0137] The storage unit 920 may include a readable medium in the form of a volatile storage unit, such as a random access memory unit (RAM) 9201 and / or a cache memory unit 9202 , and may further include a read-only memory unit (ROM) 9203 .
[0138] The storage unit 920 may also include a program / utility 9204 having a set (at least one) of program modules 9205, such program modules 9205 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.
[0139] Bus 930 may represent one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.
[0140] The electronic device 900 can also communicate with one or more external devices 1000 (e.g., a keyboard, a pointing device, a Bluetooth device, etc.), one or more devices that enable a user to interact with the electronic device 900, and / or any device that enables the electronic device 900 to communicate with one or more other computing devices (e.g., a router, a modem, etc.). This communication can occur via an input / output (I / O) interface 950. Furthermore, the electronic device 900 can communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network such as the Internet) via a network adapter 960. As shown, the network adapter 960 communicates with other modules of the electronic device 900 via a bus 930. It should be understood that, although not shown in the figure, other hardware and / or software modules can be used in conjunction with the electronic device 900, including but not limited to microcode, device drivers, redundant processing units, external disk drive arrays, RAID (Redundant Arrays of Independent Disks) systems, tape drives, and data backup storage systems.
[0141] Through the description of the above embodiments, it is easy for those skilled in the art to understand that the example embodiments described herein can be implemented by software or by combining software with necessary hardware. Therefore, the technical solution according to the embodiments of the present invention can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, and includes a number of instructions to enable a computing device (which can be a personal computer, a server, a terminal device, or a network device, etc.) to execute the method according to the embodiments of the present invention.
[0142] In exemplary embodiments of the present invention, a computer-readable storage medium is also provided, storing a program product capable of implementing the methods described above. In some possible implementations, various aspects of the present invention may also be implemented in the form of a program product comprising program code. When the program product is executed on a terminal device, the program code is configured to cause the terminal device to perform the steps according to various exemplary embodiments of the present invention described in the "Exemplary Methods" section above.
[0143] According to an embodiment of the present invention, a program product for implementing the above-mentioned method can be a portable compact disc read-only memory (CD-ROM) and include program code, and can be run on a terminal device, such as a personal computer. However, the program product of the present invention is not limited thereto. In this document, a readable storage medium can be any tangible medium containing or storing a program, and the program can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0144] The program product may be implemented in any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or any combination thereof. More specific examples (a non-exhaustive list) of readable storage media include: an electrical connection having one or more wires, a portable disk, a hard disk, a random access memory (RAM), a memory card, ... )、 Read-only memory (ROM), erasable programmable read-only memory ( EPROM or flash memory )、 Fiber optics, portable compact disk read only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination of the above.
[0145] A computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A readable signal medium may also be any readable medium other than a readable storage medium that can transmit, propagate, or transfer a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0146] The program code contained on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical cable, RF (Radio Frequency), etc., or any suitable combination thereof.
[0147] The program code for performing the operations of the present invention may be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computing device, partially on the user's computing device, as a stand-alone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the server via any type of network, including a local area network (LAN) or a wide area network (WAN). , The connection is to a user computing device, or alternatively, may be to an external computing device (eg, via the Internet using an Internet service provider).
[0148] Furthermore, the above-described figures are merely illustrative of the processes included in the method according to exemplary embodiments of the present invention and are not intended to be limiting. It is readily understood that the processes illustrated in the above-described figures do not indicate or limit the temporal order of these processes. Furthermore, it is readily understood that these processes may be executed synchronously or asynchronously, for example, in multiple modules.
[0149] Other embodiments of the present invention will readily occur to those skilled in the art after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the invention that follow from the general principles of the invention and include common knowledge or customary techniques in the art not invented herein. The specification and examples are to be considered as exemplary only, with the true scope and spirit of the invention being indicated by the claims.
Claims
1. A mirror traceability method, characterized in that: include: Obtaining a container image and a historical build command corresponding to the container image, generating image build history record data based on the historical build command, and generating image history data based on the image build history record data; Matching the image history data of the first container image with the image history data of the container image to obtain a parent image of the first container image in the container image; The first container image and the parent image of the first container image are stored in an image traceability table, and based on the image traceability table, bidirectional traceability is performed to obtain a traceability result of the container image to be traced.
2. The method according to claim 1, characterized in that The generating of image build history record data based on the historical build command includes: sorting the historical build commands according to the execution order of the historical build commands, and encoding the historical build commands; The image building history record data is generated according to the sorted historical building commands and the codes of the historical building commands.
3. The method according to claim 2, characterized in that The generating of the image history data according to the image building history data includes: The image history data is generated according to the image name of the container image, the historical build command, the total number of historical build commands, and the first build command; wherein the first build command is the first historical build command after the historical build commands are sorted.
4. The method according to claim 3, characterized in that The generating of the image history data according to the image name of the container image, the historical build command, the total number of historical build commands, and the first build command includes: Recording the image name of the container image into the image field in the image history data; splicing the unique identifiers of the historical build commands according to the sorting result of the historical build commands to obtain a splicing identifier, and recording the splicing identifier in the build history field of the image history data; Record the total number of historical build commands into the quantity field of the image history data; The unique identifier of the first build command is recorded in the first build history field of the image history data.
5. The method according to claim 4, characterized in that The matching of the image history data of the first container image with the image history data of the container image to obtain the parent image of the first container image in the container image includes: Obtaining a first quantity corresponding to a quantity field in the image history data corresponding to the first container image and a unique identifier of a first first build command corresponding to the first first build history field; Obtain image history data of a second container image whose quantity is less than the first quantity and whose first build history field is the unique identifier of the first first build command in the image history data of the container image; A build history field in the image history data of the first container image is matched with a build history field of the second container image to obtain a parent image of the first container image included in the second container image.
6. The method according to claim 1, characterized in that After obtaining the parent image of the first container image in the container image, the method further includes: Encoding the parent image and concatenating the encoding of the parent image of the first container image; The code of the spliced parent image of the first container image is stored in the parent image field of the image history data.
7. The method according to claim 1, characterized in that The storing the first container image and the parent image of the first container image in the image traceability table, and performing bidirectional traceability based on the image traceability table to obtain a traceability result of the container image to be traced, includes: The first container image is stored in the child image field of the image traceability table, and the parent image of the first container image is stored in the parent image field of the image traceability table; The container image to be traced is obtained, a parent image and a child image of the container image to be traced are searched in the image traceability table, and the parent image and the child image are determined as the traceability result.
8. The method according to claim 1, characterized in that The method further comprises: In response to the deletion of the third container image, determining, in the image traceability table, a third parent image and a third child image associated with the third container image; Updating the parent image field in the image history data of the third child image; Delete the historical build command corresponding to the third container image, the image history data, and the data associated with the third container image in the image traceability table.
9. A mirror traceability device, characterized in that: include: An image history data generation module is configured to obtain a container image and a historical build command corresponding to the container image, generate image build history record data based on the historical build command, and generate image history data based on the image build history record data; a parent image determination module, configured to match the image history data of the first container image with the image history data of the container image to obtain the parent image of the first container image in the container image; The traceability module is used to store the first container image and the parent image of the first container image in an image traceability table, and perform bidirectional traceability based on the image traceability table to obtain a traceability result of the container image to be traced.
10. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processing unit, the method according to any one of claims 1 to 8 is implemented.
11. An electronic device, characterized in that: include: processing unit; a storage unit, configured to store executable instructions of the processing unit; The processing unit is configured to perform the method according to any one of claims 1 to 8 by executing the executable instructions.