Image building method, device, electronic device and storage medium
By obtaining and using the target basic image after deleting the intermediate file from the cache, the problem of increasing time caused by the deletion of intermediate files during the image construction process is solved, and the speed and efficiency of image construction are improved.
Patent Information
- Application Number
- CN202010250610.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-04-01
- Publication Date
- 2025-03-18
- Estimated Expiration
- 2040-04-01
AI Technical Summary
In cloud computing, during the mirror construction process, intermediate files need to be deleted based on each mirror layer in the basic mirror, resulting in an increase in the time to build the mirror and reducing the speed and efficiency of mirror construction.
By obtaining the identification of the basic image, the target basic image is obtained from the cache. The target basic image is the basic image after deleting the intermediate file, and the target image is built based on the target basic image.
Directly using the target basic image after deleting the intermediate file for mirror construction, which improves the speed and efficiency of mirror construction and reduces the time required to build the mirror.
Smart Images

Figure CN113495870B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method, device, electronic device and storage medium for mirror image construction. Background Art
[0002] Currently, in cloud computing, mirroring is a common delivery method. The image is built in a container through Dockerfile. When building an image, the base image used for construction is usually pulled from the image repository, and then the instructions in the Dockerfile are executed sequentially to build it. Multiple base images can be stored in the image repository, and the content of each base image can be updated. The update method is to add a mirror layer based on the original base image. The added mirror layer indicates the content added and / or deleted from the original base image, indicating that when building the image, it is necessary to add and / or delete the corresponding content on the basis of the original base image before building the image. These contents that are indicated to be deleted can be called intermediate files.
[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:
[0004] Since the base image is updated by adding image layers, the base image obtained from the image repository when building the image sometimes includes the image layers added during the update. If the added image layer indicates the intermediate files to be deleted in the base image, then when building the image, it is necessary to first delete the intermediate files according to the image layers in the base image and then build the image, which increases the time used to build the image and reduces the speed and efficiency of image building. Summary of the invention
[0005] In view of this, the embodiments of the present invention provide a method, device, system and storage medium for image construction, which can solve the problem that when building an image, it is necessary to first delete intermediate files according to each image layer in the base image and then build the image, which increases the time used to build the image and reduces the speed and efficiency of image construction.
[0006] To achieve the above objective, according to one aspect of an embodiment of the present invention, a method for image building is provided.
[0007] A method for building an image according to an embodiment of the present invention includes: obtaining, from an image repository, an identifier of a base image corresponding to the base image name according to the base image name; obtaining, from a cache, a target base image corresponding to the identifier of the base image, the target base image being the base image after deleting intermediate files, the intermediate files representing files marked for deletion; and building a target image according to the target base image.
[0008] In one embodiment, before obtaining the target base image corresponding to the identifier of the base image, the method further includes:
[0009] Obtaining a layer file of the base image and an identifier of the base image from the image repository;
[0010] Deleting the files marked for deletion in the layer file, and determining the remaining files in the layer file as the target base image;
[0011] The corresponding relationship between the target base image and the identifier of the base image is stored in the cache.
[0012] In yet another embodiment, deleting the files marked for deletion in the layer file and determining the remaining files in the layer file as the target base image includes:
[0013] Determine the image layers of the base image in ascending order as current image layers, and for each current image layer, delete the files marked for deletion in the layer files of the current image layer;
[0014] The remaining files in the layer files of the base image are determined as the target base image.
[0015] In yet another embodiment, deleting the marked deleted file in the layer file of the current image layer includes:
[0016] Obtain a file name of an indication file in layer files of all image layers above the current image layer, wherein the file name of the indication file includes a deletion mark and a target file name;
[0017] In the layer files of the current image layer, files with the same file name as the target file are screened out as files marked for deletion, and the marked for deletion files are deleted.
[0018] In yet another embodiment, deleting the files marked for deletion in the layer file and determining the remaining files in the layer file as the target base image includes:
[0019] Determine the image layers of the base image in ascending order as target image layers, and obtain, for the target image layer, a file name of an indication file in a layer file of the target image layer, where the file name of the indication file includes a deletion flag and a target file name, and select files with the same file name as the target file name from the layer files of all image layers below the target image layer as files marked for deletion, and delete the files marked for deletion;
[0020] The remaining files in the layer files of the base image are determined as the target base image.
[0021] In yet another embodiment, obtaining a target base image corresponding to the identifier of the base image includes:
[0022] Determining whether a target base image corresponding to the identifier of the base image is stored in the cache;
[0023] If so, the target base image is obtained from the cache.
[0024] To achieve the above objective, according to another aspect of an embodiment of the present invention, a device for mirroring is provided.
[0025] An image building device of the present invention includes: an acquisition unit, which is used to acquire an identifier of a base image corresponding to the base image name from an image repository according to the base image name; the acquisition unit is also used to acquire a target base image corresponding to the identifier of the base image from a cache, the target base image being the base image after deleting intermediate files, and the intermediate files representing files marked for deletion; and a construction unit, which is used to construct a target image according to the target base image.
[0026] In one embodiment, the acquisition unit is further used to acquire the layer file of the base image and the identifier of the base image from the image repository;
[0027] Also includes:
[0028] A determination unit, configured to delete the files marked for deletion in the layer file, and determine the remaining files in the layer file as the target base image;
[0029] The storage unit is used to store the corresponding relationship between the target base image and the identifier of the base image in a cache.
[0030] In yet another embodiment, the determining unit is specifically configured to:
[0031] Determine the image layers of the base image in ascending order as current image layers, and for each of the current image layers, determine a file including a deletion mark in the current image layer, determine a file marked for deletion according to the file including the deletion mark, and delete the file marked for deletion;
[0032] The remaining files in the layer files of the base image are determined as the target base image.
[0033] In yet another embodiment, the determining unit is specifically configured to:
[0034] Obtain a file name of an indication file in layer files of all image layers above the current image layer, wherein the file name of the indication file includes a deletion mark and a target file name;
[0035] In the layer files of the current image layer, files with the same file name as the target file are screened out as files marked for deletion, and the files marked for deletion are deleted.
[0036] In yet another embodiment, the determining unit is specifically configured to:
[0037] Determine the image layers of the base image in ascending order as target image layers, and obtain, for the target image layer, a file name of an indication file in a layer file of the target image layer, where the file name of the indication file includes a deletion flag and a target file name, and select files with the same file name as the target file name from the layer files of all image layers below the target image layer as files marked for deletion, and delete the files marked for deletion;
[0038] The remaining files in the layer files of the base image are determined as the target base image.
[0039] In yet another embodiment, further comprising:
[0040] A determination unit, configured to determine whether a target base image corresponding to the identifier of the base image is stored in the cache;
[0041] The obtaining unit is specifically configured to obtain the target base image from the cache if yes.
[0042] To achieve the above objective, according to another aspect of an embodiment of the present invention, an electronic device is provided.
[0043] An electronic device according to an embodiment of the present invention includes: one or more processors; a storage device for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement the image building method provided by the embodiment of the present invention.
[0044] To achieve the above objective, according to another aspect of an embodiment of the present invention, a computer readable medium is provided.
[0045] A computer-readable medium according to an embodiment of the present invention stores a computer program, and when the program is executed by a processor, the image building method provided by the embodiment of the present invention is implemented.
[0046] One embodiment of the above invention has the following advantages or beneficial effects: In the embodiment of the present invention, after obtaining the identifier of the base image, the target base image corresponding to the identifier of the base image can be obtained from the cache according to the identifier of the base image, and then the image can be constructed according to the target base image. In the embodiment of the present invention, since the target base image is the base image after deleting the intermediate files that are instructed to be deleted, it can be directly used for image construction, thereby improving the speed and efficiency of image construction. At the same time, in the embodiment of the present invention, the target base image can be directly obtained from the cache, which can further improve the speed and efficiency of image construction compared to the method of obtaining the base image from the image warehouse. In addition, since the target base image is the base image after deleting the intermediate files that are instructed to be deleted, the amount of content in the obtained target base image is relatively small, which can also improve the speed and efficiency of image construction compared to the method of obtaining the base image including the intermediate files.
[0047] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0049] Figure 1 is a schematic diagram of a main process of a method for building an image according to an embodiment of the present invention;
[0050] Figure 2 is a schematic diagram of another main process of the method for building an image according to an embodiment of the present invention;
[0051] Figure 3 is a schematic diagram of another main process of the method for building an image according to an embodiment of the present invention;
[0052] Figure 4 is a schematic diagram of main units of a mirror-building device according to an embodiment of the present invention;
[0053] Figure 5 is another exemplary system architecture diagram to which the embodiments of the present invention can be applied;
[0054] Figure 6 It is a schematic diagram of the structure of a computer system suitable for implementing the embodiment of the present invention. DETAILED DESCRIPTION
[0055] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0056] It should be pointed out that the embodiments of the present invention and the features in the embodiments may be combined with each other if there is no conflict.
[0057] The embodiment of the present invention provides a method for image construction, which can be used in the scene of image construction. Generally, the base image used for image construction will be uploaded to the image warehouse for storage, so that the user can directly obtain the required base image from the image warehouse to build a new image. Multiple base images, as well as the name, form, identification, etc. of each base image can be stored in the image warehouse. The identification of the base image can specifically be the value of sha256. Each base image can be updated with content, and the update method of the base image is to add an image layer on the basis of the original base image, and the added image layer includes a modification indication of the original base image, such as indicating the files to be added and / or deleted from the original base image. When it is necessary to add files to the original base image, the files to be added can be directly stored in the added image layer; when it is necessary to delete files in the original base image, the files to be deleted can be indicated by the indication file, and the files to be deleted can be called files marked for deletion. Specifically, the indication file can indicate the files to be deleted by the file name. For example, a deletion flag is set in advance, and the name of the file to be deleted and the deletion flag are combined as the name of the indication file. In this way, the indication file can be determined based on the deletion flag, and then the name of the file to be deleted can be obtained based on the name of the indication file and the deletion flag, and then the file to be deleted, that is, the file marked for deletion, can be determined. The deletion flag can be set to: .wh. In an embodiment of the present invention, the name of the indication file can be set to a name obtained by adding the deletion flag before the name of the file marked for deletion.
[0058] The embodiment of the present invention provides a method for image building, which can be executed by a terminal device, such as Figure 1 As shown, the method includes the following steps.
[0059] S101: According to the base image name, obtain an identifier of the base image corresponding to the base image name from an image repository.
[0060] Among them, the base image name is pre-set, and in this step, a name list of base images in the image warehouse can be pre-stored, and then the base image name required for building the image can be selected according to the name list, and then the identifier of the base image corresponding to the base image name can be obtained from the image warehouse based on the base image name. At the same time, parameters such as the file list of the base image corresponding to the base image name can also be obtained from the image warehouse.
[0061] In the embodiment of the present invention, the sha256 value of the base image is used to represent the identification of the base image. In the image repository, each base image includes a corresponding sha256 value. For updates to the same base image, the sha256 value of each updated base image will also be different, so the base image can be uniquely identified by sha256.
[0062] It should be noted that, since the building of the image is usually performed in a container, a container for building the image may be built before building the image.
[0063] S102: Obtain a target base image corresponding to the identifier of the base image from the cache.
[0064] The target base image is the base image after deleting the intermediate files, and the intermediate files represent the files marked for deletion.
[0065] The files marked for deletion are deleted from the target base image, and the target base image is pre-stored in the cache. When the image is rebuilt, the base image excluding the intermediate files can be directly obtained from the cache, so that the image building process can be directly executed, improving the efficiency of image building.
[0066] In order to obtain the target base image from the cache, in an embodiment of the present invention, before executing this step, the following steps may also be performed: obtaining the layer files of the base image and the identifier of the base image from the image repository; deleting the files marked for deletion in the layer files, and determining the remaining files in the layer files as the target base image; and storing the correspondence between the target base image and the identifier of the base image in the cache.
[0067] The layer files of the base image are obtained from the image repository. The layer files include files of each image layer in the base image. Some image layers of the base image may include files marked for deletion. In the embodiment of the present invention, after obtaining the base image, the files marked for deletion in the layer files can be deleted, and the remaining files in the layer files can be determined as the target base image. Then, the correspondence between the target base image and the identifier of the base image is stored in the cache, so that the target base image can be obtained from the cache according to the identifier of the base image when executing this step.
[0068] To delete the files marked for deletion in the layer files of the current image layer, the following can be performed: the image layers of the base image are determined as the current image layers in order from small to large, and for each current image layer, the files marked for deletion in the layer files of the current image layer are deleted; the remaining files in the layer files of the base image are determined as the target base image.
[0069] A base image usually includes multiple image layers, each of which may include files marked for deletion. Therefore, an embodiment of the present invention can traverse each image layer and delete the files marked for deletion in each image layer, and then the remaining files in the layer files of the base image can be determined as the target base image.
[0070] Since the base image is updated by adding image layers, the added image layers may indicate files marked for deletion in the original image layers, so in the embodiment of the present invention, the image layers of the base image can be traversed in order from small to large. The specific method is to determine the image layers of the base image as the current image layers in order from small to large, and execute for each base image layer: delete the files marked for deletion in the layer file of the current image layer.
[0071] For the step of deleting the files marked for deletion in the layer files of the current image layer, the embodiment of the present invention can be specifically performed as follows: obtaining the file name of the indicating file in the layer files of all image layers above the current image layer, where the file name of the indicating file includes a deletion mark and a target file name; in the layer files of the current image layer, filtering out the files with the same file name as the target file name as the files marked for deletion, and deleting the files marked for deletion.
[0072] In an embodiment of the present invention, the file to be deleted is indicated by the file name of the indicator file, and based on the update method of the base image, all image layers above the current image layer may include an indicator file indicating that the file in the current image layer is a file marked for deletion, so in this step, it is necessary to search for the indicator file from the layer files of all image layers above the current image layer, and obtain the name of the indicator file. Since the file name of the indicator file includes a deletion mark and a target file name, the indicator file can be found through the deletion mark, and then the target file name, that is, the file name of the file indicated for deletion, can be obtained. If a file name is the same as the target file name, it can be determined that it is a file indicated for deletion. Therefore, in the layer file of the current image layer, files with the same target file name can be screened as files marked for deletion, and the files marked for deletion can be deleted. After traversing each image layer in this way, all files marked for deletion in the base image can be deleted.
[0073] Specifically, assuming that the layer files of the base image include N layers of files, if the current image layer is the Mth layer, then all the image layers above the current image layer refer to the M+1th layer to the Nth layer of the base image, where N is an integer greater than 0, and M is an integer greater than 0 and less than or equal to N. First, the first layer of the base image is determined as the current image layer, and the files whose file names include deletion marks are determined from the second layer to the Nth layer of the base image, that is, the indicator files; then the file name of the indicator file is obtained, and the file name includes the deletion mark and the target file name, so that the target file name included in the file name of the indicator file can be determined, that is, the file name of the file marked for deletion; then, according to the target file name, the files with the same file name as the target file name are screened out in the layer files of the current image layer as the files marked for deletion, and deleted. Then determine the second layer of the base image as the current image layer, and determine the files whose file names include deletion marks from the third to the Nth layers of the base image, that is, the indicator files, and then obtain the file name of the indicator file, which includes the deletion mark and the target file name, so that the target file name included in the file name of the indicator file can be determined, that is, the file name of the file marked for deletion; then, according to the target file name in the layer file of the current image layer, filter out the files with the same target file name as the files marked for deletion and delete them. In this way, the image layers of the base image are determined in order from small to large through the above process, and the process of deleting the files marked for deletion in the current image layer is executed, so as to obtain the target base image.
[0074] It should be noted that, in the embodiment of the present invention, an indicator file usually indicates a file marked for deletion. For example, the deletion mark is: .wh., and the name of the file marked for deletion is: ABC, then the name of the indicator file can be .wh.ABC, so the indicator file can be determined according to the deletion mark, and then the target file name, that is, ABC, can be determined by the remaining part of the name of the indicator file except the deletion mark. This target file name is the name of a file marked for deletion, so that the file marked for deletion can be determined. Therefore, when there are multiple indicator files, the file names of the indicator files obtained also include multiple, and then the target file names obtained also include multiple. For example, it is determined that the indicator files include two, namely .wh.ABC and .wh.DEF, then the target file names can be obtained as ABC and DEF, indicating that the file names of the files marked for deletion are ABC and DEF, then the files with the same file names as ABC or DEF can be screened from the current image layer, if there are files with the same file names as ABC, then they are treated as files marked for deletion and deleted, if not, then they can be ignored; if there are files with the same file names as DEF, then they are treated as files marked for deletion and deleted, if not, then they can be ignored.
[0075] It should be noted that in an embodiment of the present invention, for each current image layer, after deleting the files marked for deletion in the base image, if the current image layer includes an indication file, the indication file in the current image layer can also be deleted, thereby further reducing the size of the target base image and improving the efficiency of image construction.
[0076] S103: Build a target image according to the target base image.
[0077] After the target base image is obtained, since the files marked for deletion have been deleted in the target base image, the image can be directly built to build the target image.
[0078] It should be noted that after the image is built, the layer files of the image can be packaged, and then the packaged image can be uploaded to the corresponding image center, and the container used to build the image can be deleted.
[0079] In an embodiment of the present invention, after obtaining the identifier of the base image, the target base image corresponding to the identifier of the base image can be obtained from the cache according to the identifier of the base image, and then the image can be constructed according to the target base image. In an embodiment of the present invention, since the target base image is the base image after deleting the intermediate files that are instructed to be deleted, it can be directly used for image construction, thereby improving the speed and efficiency of image construction. At the same time, in an embodiment of the present invention, the target base image can be directly obtained from the cache, which can further improve the speed and efficiency of image construction compared to the method of obtaining the base image from the image warehouse. In addition, since the target base image is the base image after deleting the intermediate files that are instructed to be deleted, the amount of content in the obtained target base image is relatively small, which can also improve the speed and efficiency of image construction relative to the method of obtaining the base image including the intermediate files.
[0080] As an implementation method of an embodiment of the present invention, after obtaining the layer files of the base image, the files marked for deletion in the layer files are deleted, and the method for determining the target base image can also be executed as follows: the image layers of the base image are determined as target image layers in order from small to large; for each target image layer, the file name indicating the file in the layer file of the target image layer is obtained, and the file name indicating the file includes a deletion mark and a target file name, and in the layer files of all image layers below the target image layer, the files with the same target file name are screened out as files marked for deletion, and the files marked for deletion are deleted; the remaining files in the layer files of the base image are determined as the target base image.
[0081] Specifically, assuming that the layer files of the base image include N layers of files, if the target image layer is the Mth layer, then all image layers above the target image layer refer to the M-1th layer to the 1st layer of the base image, where N is an integer greater than 0, and M is an integer greater than 0 and less than or equal to N.
[0082] Since the updated image layer is an update of the original base image, if each image layer includes an indicator file, the corresponding file marked for deletion should be a file in the image layer below the image layer in the base image. Therefore, in an embodiment of the present invention, the image layers of the base image are determined as target image layers in order from small to large, and the corresponding files marked for deletion in all image layers below the target image layer are determined through the indicator file in the target image layer, and deleted. In this way, all files marked for deletion in the base image are deleted iteratively.
[0083] It should be noted that, since the base image is updated to modify the content of the base image before the update, the image layer includes files with preset deletion marks, indicating the deletion of corresponding files in the content of the base image within this image layer.
[0084] For example, it is assumed that the layer files of the base image include N layers of files, where N is an integer greater than 0. When the Mth image layer is the target image layer, the Mth layer file indicates the file, and then the target file name is obtained according to the name of the indicating file, and then the files with the same target file name are screened out from the layer files of the 1st layer to the M-1th layer as the files marked for deletion, and the marked files for deletion are deleted.
[0085] Combine the following Figure 1 In the embodiment shown, the process of determining and storing the target base image in the above implementation mode is described by taking the preset deletion mark as .wh. and the base image mark as the corresponding sha256 value as an example. Figure 2 As shown, the method includes the following steps.
[0086] S201: Obtain the layer file and sha256 value of the base image from the image repository.
[0087] Among them, the base image that needs to be preprocessed can be obtained from the image warehouse, and the layer file is the file in each image layer of the base image. In this step, the file list and sha256 value of the base image can also be obtained from the image warehouse.
[0088] S202: Create a / base directory and a / next directory in the container and initialize the layer identifier.
[0089] The container may be pre-established, and may be a container for building an image. The layer identifier is used to indicate each image layer in the base image. In the embodiment of the present invention, the base image is set to include N layers. Initializing the layer identifier is to set the layer identifier to an initial value, and the initial value may be 1.
[0090] Create the / base directory and the / next directory, filter the intermediate files of the base image through the two targets, and delete the intermediate files.
[0091] S203: Decompress the first layer file in the base image to the / base directory.
[0092] Among them, the image layer that updates the content of the base image may only exist from the second layer onwards, so in this step, the layer files of the first layer can be directly decompressed to the / base directory. Since the files in the base image are usually compressed files, they need to be decompressed when processing.
[0093] S204: The layer identifier is incremented by a preset value to determine whether the layer identifier is greater than N. If so, execute step 211; if not, execute step S205.
[0094] The preset value can be set according to the requirements, and the preset value can be set to 1. The number of image layers of the base image is N, and the layer identifier is incremented by the preset value to determine whether it is greater than N. If the layer identifier is greater than N, it means that the base image has been processed, and step S211 is executed; if the layer identifier is not greater than N, it means that the base image has an image layer that has not been processed, and step S205 is executed.
[0095] It should be noted that some base images include only one layer, which means that the base image is for content update, and N is equal to 1. After executing step S203, step S211 can be directly executed.
[0096] S205: Decompress the layer file of the image layer corresponding to the layer identifier in the base image to the / next directory.
[0097] Among them, the image layer corresponding to the layer identifier represents the image layer that needs to be processed currently, that is, the target image layer. The layer file of the layer corresponding to the layer identifier in the base image is decompressed to the / next directory for easy processing.
[0098] S206: Determine whether the / next directory includes the instruction file, if so, execute step S207; if not, execute step S210.
[0099] Among them, the layer files of the target image layer are in the / next directory. The target image layer may be an image layer that updates the content of the base image, so it may include a file indicating the deletion of the file. In the embodiment of the present invention, the deletion mark is set to .wh., and the file name of the indicating file is set to the deletion mark + the target file name. Therefore, in this step, it can be determined whether the / next directory includes a file with a file name prefix of .wh., that is, the indicating file. If it is included, it means that the target image layer includes the indicating file, and step S207 is executed; if not, it means that the target image layer does not include the indicating file, and step S210 is executed.
[0100] S207: Determine the target file name by deleting the portion of the file name indicated by the mark .
[0101] In the embodiment of the present invention, .wh.+target file name is set as the file name of the indication file, so the part of the file name of the indication file except the prefix .wh. is the target file name, that is, the name of the file marked for deletion.
[0102] S208: Delete the file whose name is the target file name in the / base directory.
[0103] After the target file name is determined in S207, the file marked for deletion can be determined from the / base directory according to the target file name and then deleted, that is, the intermediate file is deleted.
[0104] It should be noted that the files stored in the / base directory are files of all image layers below the target image layer, and the indicator files in the target image layer are updates for files of all image layers below the target image layer. Therefore, in this step, the files marked for deletion can be directly determined from the / base directory according to the target file name and deleted.
[0105] S209: Move the remaining files except the indicated file in the / next directory to the / base directory, and clear the / next directory.
[0106] The indicator files in the / next directory are used to indicate the files to be deleted, that is, the files marked for deletion, and the files to be added are directly stored, so the remaining files in the / next directory except the indicator files are the files to be added in the base image, so this file can be directly moved to the / base directory. Move the remaining files except the indicator files to the / base directory, and the remaining indicator files in the / next directory are useless files and can be directly cleared.
[0107] It should be noted that in this step, the remaining files in the / next directory except the indicator file are moved to the / base directory, so that the files in the / base directory are the layer files from the first layer to the corresponding layer of the target image layer in the base image, and do not include intermediate files and indicator files.
[0108] After this step is completed, execute step S204.
[0109] S210: Move the files in the / next directory to the / base directory.
[0110] If the / next directory does not contain the indicator file, it means that the files in it are all files to be added to the base image, so the files in the / next directory can be directly moved to the / base directory. After the files in the / next directory are moved to the / base directory, the / next directory is cleared.
[0111] It should be noted that in this step, the files in the / next directory are moved to the / base directory, so that the files in the / base directory are the layer files from the first layer to the target image layer in the base image, and do not include intermediate files and indicator files.
[0112] After this step is completed, execute step S204.
[0113] S211: compress and package the files in the / base directory and store them, and store the sha256 value corresponding to the base image.
[0114] When the layer identifier is greater than N, it means that the files of each layer in the base image have been processed, the intermediate files have been deleted, and the files in the / base directory are all the files of the base image, so the files in the / base directory can be compressed and packaged and stored. The storage method of the base image can be kv format, k is the sha256 value of the base image, and v is the compressed and packaged file of the base image.
[0115] In the embodiment of the present invention, the files to be deleted in the base image are deleted to obtain a target base image that does not include the files marked for deletion, thereby achieving direct construction based on the obtained base image and improving the speed and efficiency of image construction.
[0116] for Figure 2 The base image obtained by deleting the intermediate files in the embodiment shown can be directly stored in the cache. When the image needs to be built, the corresponding target base image can be obtained from the cache according to the sha256 value. If it is not stored in the cache, it can be obtained from the image warehouse. Because the base image obtained from the image warehouse may include intermediate files, the obtained base image can be obtained through Figure 2The method of the embodiment shown in the figure is used to process and store it in the cache so that it can be directly used in the subsequent image building to improve the efficiency of image building. The specific process can be as follows Figure 3 As shown, the following steps are included.
[0117] S301: Create a container for building an image.
[0118] S302: Obtain a list of the base image and a sha256 value of the base image from the image repository.
[0119] S303: Determine whether the corresponding target base image is stored in the cache according to the sha256 value. If so, execute step S306; if not, execute step S304.
[0120] S304: Obtain a basic image from an image repository.
[0121] S305: Delete the intermediate files in the base image and compress and store them in the cache, and build an image according to the base image with the intermediate files deleted.
[0122] In this step, you can use the method of deleting the intermediate files in the base image and compressing and storing them in the cache. Figure 1 or Figure 2 The method described in the embodiment shown in the figure. After executing step S307 is executed.
[0123] S306: Decompress the target base image and then build the image.
[0124] S307: compress the built image and upload it to the image repository, and delete the container.
[0125] In the embodiment of the present invention, the target basic image can be directly obtained from the cache, which can further improve the speed and efficiency of building the image compared to the method of obtaining the basic image from the image warehouse.
[0126] In order to solve the problems existing in the prior art, an embodiment of the present invention provides a device 400 for image building, such as Figure 4 As shown, the device 400 includes:
[0127] The acquisition unit 401 is used to acquire, according to the base image name, an identifier of the base image corresponding to the base image name from the image repository;
[0128] The acquisition unit 401 is further configured to acquire a target base image corresponding to the identifier of the base image from a cache, wherein the target base image is the base image after deleting intermediate files, wherein the intermediate files represent files marked for deletion;
[0129] The building unit 402 is used to build a target image according to the target basic image.
[0130] It should be understood that the manner of implementing the embodiments of the present invention is different from the Figure 1 The method of the illustrated embodiment is the same and will not be repeated here.
[0131] In an implementation of the embodiment of the present invention, the acquisition unit is further used to acquire the layer file of the base image and the identifier of the base image from the image repository;
[0132] Also includes:
[0133] A determination unit, configured to delete the files marked for deletion in the layer file, and determine the remaining files in the layer file as the target base image;
[0134] The storage unit is used to store the corresponding relationship between the target base image and the identifier of the base image in a cache.
[0135] In another implementation of the embodiment of the present invention, the determining unit is specifically configured to:
[0136] Determine the image layers of the base image in ascending order as current image layers, and for each of the current image layers, determine a file including a deletion mark in the current image layer, determine a file marked for deletion according to the file including the deletion mark, and delete the file marked for deletion;
[0137] The remaining files in the layer files of the base image are determined as the target base image.
[0138] In another implementation of the embodiment of the present invention, the determining unit is specifically configured to:
[0139] Obtain a file name of an indication file in layer files of all image layers above the current image layer, wherein the file name of the indication file includes a deletion mark and a target file name;
[0140] In the layer files of the current image layer, files with the same file name as the target file are screened out as files marked for deletion, and the files marked for deletion are deleted.
[0141] In another implementation of the embodiment of the present invention, the determining unit is specifically configured to:
[0142] Determine the image layers of the base image in ascending order as target image layers, and obtain, for the target image layer, a file name of an indication file in a layer file of the target image layer, where the file name of the indication file includes a deletion flag and a target file name, and select files with the same file name as the target file name from the layer files of all image layers below the target image layer as files marked for deletion, and delete the files marked for deletion;
[0143] The remaining files in the layer files of the base image are determined as the target base image.
[0144] In another implementation of the embodiment of the present invention, the apparatus 400 further includes:
[0145] A determination unit, configured to determine whether a target base image corresponding to the identifier of the base image is stored in the cache;
[0146] The acquisition unit 401 is specifically configured to, if yes, acquire the target base image from the cache.
[0147] It should be understood that the manner of implementing the embodiments of the present invention is different from the Figure 1 , Figure 2 or Figure 3 The method of the illustrated embodiment is the same and will not be repeated here.
[0148] In an embodiment of the present invention, after obtaining the identifier of the base image, the target base image corresponding to the identifier of the base image can be obtained from the cache according to the identifier of the base image, and then the image can be constructed according to the target base image. In an embodiment of the present invention, since the target base image is the base image after deleting the intermediate files that are instructed to be deleted, it can be directly used for image construction, thereby improving the speed and efficiency of image construction. At the same time, in an embodiment of the present invention, the target base image can be directly obtained from the cache, which can further improve the speed and efficiency of image construction compared to the method of obtaining the base image from the image warehouse. In addition, since the target base image is the base image after deleting the intermediate files that are instructed to be deleted, the amount of content in the obtained target base image is relatively small, which can also improve the speed and efficiency of image construction relative to the method of obtaining the base image including the intermediate files.
[0149] According to an embodiment of the present invention, the present invention also provides an electronic device and a readable storage medium.
[0150] The electronic device of the present invention comprises: at least one processor; and a memory connected to the at least one processor in communication; wherein the memory stores instructions that can be executed by the one processor, and the instructions are executed by the at least one processor so that the at least one processor executes the image building method provided by the embodiment of the present invention.
[0151] Figure 5 An exemplary system architecture 500 is shown to which the image building method or image building apparatus according to the embodiments of the present invention may be applied.
[0152] like Figure 5 As shown, the system architecture 500 may include at least one terminal device ( Figure 5 501, terminal device 502 and terminal device 503 are shown in FIG. 502). The terminal device 501 is used as an example for explanation. The terminal device 501 can be various electronic devices with an image building function, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers, etc. The image building function can be realized by installing a client or application for image building in the terminal device 501. When the terminal device 501 is running, it can obtain the required information, such as basic image information, from the server 505 according to user needs, and build a new image according to the obtained information.
[0153] The system architecture 500 may also include a server 505, which may be a server that provides various image information. For example, an image warehouse may be set up in the server 505, and the image warehouse stores basic image information used for image construction, so that the user can access the server 505 through the terminal device 501, the terminal device 502 or the terminal device 503, and obtain the required basic image from the image warehouse of the server 505 to build a new image.
[0154] like Figure 5 As shown, the system architecture 500 may further include a network 504. The network 504 is used to provide a medium for communication links between the terminal devices 501, 502, 503 and the server 505. The network 504 may include various connection types, such as wired, wireless communication links or optical fiber cables.
[0155] It should be noted that the image building method provided in the embodiment of the present invention is generally executed by one of the terminal devices 501 , 502 , 503 , and accordingly, the image building apparatus is generally disposed in one of the terminal devices 501 , 502 , 503 .
[0156] It should be understood that Figure 5 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0157] Reference below Figure 6 , which shows a schematic diagram of the structure of a computer system 600 suitable for implementing an embodiment of the present invention. Figure 6The computer system shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0158] like Figure 6 As shown, the computer system 600 includes a central processing unit (CPU) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage part 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the system 600 are also stored. The CPU 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0159] The following components are connected to the I / O interface 605: an input section 606 including a keyboard, a mouse, etc.; an output section 607 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN card, a modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the I / O interface 605 as needed. A removable medium 611, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 610 as needed, so that a computer program read therefrom is installed into the storage section 608 as needed.
[0160] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 609, and / or installed from the removable medium 611. When the computer program is executed by the central processing unit (CPU) 601, the above-mentioned functions defined in the system of the present invention are executed.
[0161] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0162] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a unit, a program segment, or a part of a code, and the above-mentioned unit, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0163] The units involved in the embodiments of the present invention may be implemented by software or hardware. The units described may also be set in a processor, for example, it may be described as: a processor includes an acquisition unit and a construction unit. The names of these units do not constitute a limitation on the units themselves in some cases, for example, the acquisition unit may also be described as a "unit of the function of the acquisition unit".
[0164] As another aspect, the present invention further provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device executes the image building method provided by the present invention.
[0165] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for mirroring, characterized in that: include: According to the base image name, obtain the identifier of the base image corresponding to the base image name from the image repository; Obtaining a target base image corresponding to the identifier of the base image from a cache, wherein the target base image is the base image after deleting an intermediate file, wherein the intermediate file represents a file marked for deletion; Building a target image based on the target base image; Before obtaining the target base image corresponding to the identifier of the base image, the method further includes: Obtaining a layer file of the base image and an identifier of the base image from the image repository; Deleting the files marked for deletion in the layer file, and determining the remaining files in the layer file as the target base image; Storing the corresponding relationship between the target base image and the identifier of the base image in the cache; The deleting the files marked for deletion in the layer file and determining the remaining files in the layer file as the target basic image includes: Determine the image layers of the base image in ascending order as target image layers, and obtain, for the target image layer, a file name of an indication file in a layer file of the target image layer, where the file name of the indication file includes a deletion flag and a target file name, and select files with the same file name as the target file name from the layer files of all image layers below the target image layer as files marked for deletion, and delete the files marked for deletion; The remaining files in the layer files of the base image are determined as the target base image.
2. The method according to claim 1, characterized in that The obtaining of a target base image corresponding to the identifier of the base image includes: Determining whether a target base image corresponding to the identifier of the base image is stored in the cache; If so, the target base image is obtained from the cache.
3. A method for mirroring, characterized in that: include: According to the base image name, obtain the identifier of the base image corresponding to the base image name from the image repository; Obtaining a target base image corresponding to the identifier of the base image from a cache, wherein the target base image is the base image after deleting an intermediate file, wherein the intermediate file represents a file marked for deletion; Building a target image based on the target base image; Before obtaining the target base image corresponding to the identifier of the base image, the method further includes: Obtaining a layer file of the base image and an identifier of the base image from the image repository; Deleting the files marked for deletion in the layer file, and determining the remaining files in the layer file as the target base image; Storing the corresponding relationship between the target base image and the identifier of the base image in the cache; The deleting the files marked for deletion in the layer file and determining the remaining files in the layer file as the target basic image includes: Determine the image layers of the base image in ascending order as current image layers, and for each current image layer, delete the files marked for deletion in the layer files of the current image layer; Determine the remaining files in the layer files of the base image as the target base image; The deleting the marked deleted file in the layer file of the current image layer includes: Obtain a file name of an indication file in the layer files of all image layers above the current image layer, where the file name of the indication file includes a deletion mark and a target file name; In the layer files of the current image layer, files with the same file name as the target file are screened out as files marked for deletion, and the files marked for deletion are deleted.
4. The method according to claim 3, characterized in that The obtaining of a target base image corresponding to the identifier of the base image includes: Determining whether a target base image corresponding to the identifier of the base image is stored in the cache; If so, the target base image is obtained from the cache.
5. A mirror image building device, characterized in that: include: An acquisition unit, configured to acquire, from an image repository, an identifier of a base image corresponding to the base image name according to the base image name; The acquisition unit is further used to acquire a target base image corresponding to the identifier of the base image from the cache, wherein the target base image is the base image after deleting an intermediate file, and the intermediate file represents a file marked for deletion; A construction unit, configured to construct a target image according to the target base image; The acquisition unit is further used to acquire the layer file of the base image and the identifier of the base image from the image repository; The device also includes: A determination unit, configured to delete the files marked for deletion in the layer file, and determine the remaining files in the layer file as the target base image; A storage unit, configured to store the corresponding relationship between the target base image and the identifier of the base image in a cache; The determining unit is specifically configured to: Determine the image layers of the base image in ascending order as target image layers, and obtain, for the target image layer, a file name of an indication file in a layer file of the target image layer, where the file name of the indication file includes a deletion flag and a target file name, and select files with the same file name as the target file name from the layer files of all image layers below the target image layer as files marked for deletion, and delete the files marked for deletion; The remaining files in the layer files of the base image are determined as the target base image.
6. A mirror image building device, characterized in that: include: An acquisition unit, configured to acquire, from an image repository, an identifier of a base image corresponding to the base image name according to the base image name; The acquisition unit is further used to acquire a target base image corresponding to the identifier of the base image from the cache, wherein the target base image is the base image after deleting an intermediate file, and the intermediate file represents a file marked for deletion; A construction unit, configured to construct a target image according to the target base image; The acquisition unit is further used to acquire the layer file of the base image and the identifier of the base image from the image repository; The device also includes: A determination unit, configured to delete the files marked for deletion in the layer file, and determine the remaining files in the layer file as the target base image; A storage unit, configured to store the corresponding relationship between the target base image and the identifier of the base image in a cache; The determining unit is specifically configured to: Determine the image layers of the base image in ascending order as current image layers, and for each of the current image layers, determine a file including a deletion mark in the current image layer, determine a file marked for deletion according to the file including the deletion mark, and delete the file marked for deletion; Determine the remaining files in the layer files of the base image as the target base image; The determining unit is specifically configured to: Obtain a file name of an indication file in layer files of all image layers above the current image layer, wherein the file name of the indication file includes a deletion mark and a target file name; In the layer files of the current image layer, files with the same file name as the target file are screened out as files marked for deletion, and the files marked for deletion are deleted.
7. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 4.
8. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Method and device for generating mirror image files
CN106843976A
Method and device for modifying mirror image document
CN107015995A