Mirror image construction method and device, equipment and storage medium
By separating the list of deleted and added files during the image building process, constructing image layers, and arranging them reasonably in the image stacking structure, the problem of wasted cache space in image building is solved, cache reuse across image building is realized, and cache space is saved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- BEIJING QIYI CENTURY SCI & TECH CO LTD
- Filing Date
- 2026-03-03
- Publication Date
- 2026-05-15
AI Technical Summary
During the image building process, users add the same large files to different base images but delete different small files, resulting in the generation of different image layers and wasting cache space.
In response to the image layer building instruction, the file change list is obtained, and the first image layer corresponding to the deleted file list and the second image layer corresponding to the added file list are built respectively. In the image stacking structure, the first image layer is located below the second image layer, and the second image layer that is not cached is cached.
It enables cache reuse across image builds, effectively saving cache space. By keeping the image layers of the newly added file list consistent, it avoids the impact of differences in the deleted file list.
Smart Images

Figure CN122044604A_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of image technology, and in particular to an image construction method, apparatus, device, and storage medium. Background Technology
[0002] Images (such as Docker images) use a layered storage mechanism. Each image layer records changes made to the previous image layer, including the addition and deletion of files. When storing images in a repository, each image layer corresponds to a tar file, which contains markers for newly added and / or deleted files. The image repository uses the contents of this tar file for addressing and storage.
[0003] However, in the actual process of building images, the following situation often occurs: when users build new images on different base images, if they add the same large files but delete different small files, it will result in the generation of two different image layers, wasting cache space. Summary of the Invention
[0004] To solve the above-mentioned technical problems, or at least partially solve them, this disclosure provides a method, apparatus, device, and storage medium for image construction.
[0005] A first aspect of this disclosure provides an image building method applied to a client, wherein the method includes: In response to the image layer build command, obtain the file change list corresponding to the image layer build command; If the file change list includes a list of deleted files and a list of added files, a mirror layer is constructed according to the list of deleted files and the list of added files respectively to obtain a first mirror layer corresponding to the list of deleted files and a second mirror layer corresponding to the list of added files. In the stacked structure of the mirrors, the first mirror layer is located below the second mirror layer. Cache the first image layer. If the second image layer has not been cached, cache the second image layer.
[0006] A second aspect of this disclosure provides an image building apparatus applied to a client, wherein the apparatus includes: The first acquisition module is used to acquire the file change list corresponding to the image layer build instruction in response to the image layer build instruction; The first construction module is configured to, if the file change list includes a list of deleted files and a list of added files, construct mirror layers according to the list of deleted files and the list of added files respectively, to obtain a first mirror layer corresponding to the list of deleted files and a second mirror layer corresponding to the list of added files, wherein, in the stacked structure of the mirrors, the first mirror layer is located below the second mirror layer; The first caching module is used to cache the first image layer, and if the second image layer has not been cached, it caches the second image layer.
[0007] A third aspect of this disclosure provides an electronic device comprising: a processor and a memory, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor performs the method described in the first aspect.
[0008] A fourth aspect of this disclosure provides a computer-readable storage medium storing a computer program that, when executed by a processor, can implement the method of the first aspect described above.
[0009] The technical solution provided in this disclosure has the following advantages compared with the prior art: This embodiment of the disclosure is capable of responding to a file change list corresponding to a mirror layer construction instruction. If the file change list includes a list of deleted files and a list of added files, mirror layers are constructed according to the deleted file list and the added file list respectively, resulting in a first mirror layer corresponding to the deleted file list and a second mirror layer corresponding to the added file list. In the stacked structure of the mirrors, the first mirror layer is located below the second mirror layer. The first mirror layer is cached; if the second mirror layer has not yet been cached, it is cached. Therefore, by adopting the above technical solution, when constructing a mirror, the deleted file list and the added file list corresponding to the same mirror layer construction instruction can be automatically split into different mirror layers, instead of placing them in the same mirror layer as in the prior art. This ensures that the mirror layer containing the added file list remains stable in content and is not affected by differences in the deleted file list. In this way, when a user builds a new image on different base images, even if different small files are deleted (i.e., the list of deleted files is different), as long as the same large files are added (i.e., the list of added files is the same), the image layer of the added file list can remain consistent. Thus, only one copy needs to be cached in the cache space, thereby achieving cache reuse across image builds and effectively saving cache space. Attached Figure Description
[0010] The accompanying drawings, which are incorporated in and form a part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure.
[0011] To more clearly illustrate the technical solutions in the embodiments of this disclosure or the prior art, the accompanying drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, those skilled in the art can obtain other drawings based on these drawings without creative effort.
[0012] Figure 1 This is a flowchart of an image construction method provided in an embodiment of this disclosure; Figure 2 This is a flowchart illustrating an example of image building provided in this disclosure. Figure 3 This is a storage diagram of a mirror warehouse provided in an embodiment of this disclosure; Figure 4 This is a storage diagram of another mirror warehouse provided in this embodiment of the disclosure; Figure 5 This is a schematic diagram of the structure of a mirror construction device provided in an embodiment of this disclosure; Figure 6 This is a schematic diagram of the structure of an electronic device according to an embodiment of this disclosure. Detailed Implementation
[0013] To better understand the above-mentioned objectives, features, and advantages of this disclosure, the solutions disclosed herein will be further described below. It should be noted that, unless otherwise specified, the embodiments and features described herein can be combined with each other.
[0014] Numerous specific details are set forth in the following description in order to provide a full understanding of this disclosure, but this disclosure may also be implemented in other ways different from those described herein; obviously, the embodiments in the specification are only some, and not all, of the embodiments of this disclosure.
[0015] Figure 1 This is a flowchart illustrating an image creation method provided in this disclosure, which can be executed by an electronic device. The electronic device can be exemplarily understood as a client electronic device such as a mobile phone, tablet computer, laptop computer, or desktop computer. Figure 1 As shown, the method provided in this embodiment includes the following steps: S110. In response to the image layer build command, obtain the file change list corresponding to the image layer build command.
[0016] Specifically, an image (such as a Docker image) consists of multiple image layers, and each image layer records changes made based on the previous image layer, including the addition and deletion of files.
[0017] Specifically, an image layer build instruction is an executable instruction used to add and / or delete files, such as Dockerfile instructions like RUN, COPY, and ADD. An image is typically built by executing at least one image layer build instruction sequentially, stacking image layers one by one.
[0018] Specifically, the file change list records the files whose content changed when a particular image layer build instruction was executed. The file change list includes a list of deleted files and / or a list of newly added files.
[0019] The newly added file list records files added during the execution of a specific image layer build instruction (i.e., new files), which did not exist in the previous image layer. For example, the newly added file list records the file identifiers (such as filenames) of the new files, describing the set of files added relative to the previous image layer.
[0020] The deleted file list records files that were deleted during the execution of a specific image layer build instruction (i.e., deleted files), which existed in the previous image layer. For example, the deleted file list records the file identifiers (such as filenames) of the deleted files, describing the set of files deleted relative to the previous image layer.
[0021] S120. If the file change list includes a list of deleted files and a list of added files, construct mirror layers according to the list of deleted files and the list of added files respectively to obtain a first mirror layer corresponding to the list of deleted files and a second mirror layer corresponding to the list of added files. In the stacked structure of the mirrors, the first mirror layer is located below the second mirror layer.
[0022] Specifically, the first mirror layer is located directly below the second mirror layer. That is, in the mirror stacking structure, the first mirror layer is built first as the foundation of the second mirror layer, and then the second mirror layer is superimposed on it.
[0023] Optionally, S120 includes: first, S121, constructing a corresponding first image layer based on the list of deleted files, and then, S122, constructing a corresponding second image layer based on the list of newly added files.
[0024] Specifically, if the deleted file list and the added file list contain the same file (e.g., the same file identifier), it indicates that the user intends to modify that file. Modifying the file essentially involves deleting the old file and then writing a new file with the same file identifier. Therefore, it is necessary to first build a corresponding first mirror layer based on the deleted file list, and then build a corresponding second mirror layer based on the added file list.
[0025] Specifically, if the deleted file list and the added file list do not contain the same files (such as files with the same file identifier), it means that the user wants to simply delete some files and simply add some files. Since the deleted files are relative to the previous mirror layer, it is necessary to first build the corresponding first mirror layer based on the deleted file list, and then build the corresponding second mirror layer based on the added file list.
[0026] Specifically, building the first image layer based on the list of deleted files means writing the deletion markers (excluding the content of the deleted files) into the first image layer. These deletion markers can include, for example, `.wh.filename`, but are not limited to these. Of course, metadata such as the storage path, file permissions, owner, and / or timestamps of the deleted files can also be written into the first image layer.
[0027] Specifically, building a second mirror layer based on the list of newly added files means writing the contents of the newly added files into the second mirror layer. Of course, metadata such as the storage path, file permissions, owner, and / or timestamps of the newly added files can also be written into the second mirror layer.
[0028] Understandably, when a build command for an image layer contains both deletions and additions of the same file, it indicates that the user intends to modify that file. This must be done in the order of deletion first, then addition. This is because deletion actually masks the old file from the previous image layer by creating a deletion marker in the current image layer, rather than physically erasing it. If addition is done before deletion, the newly created file will also be marked as deleted, causing it to not appear in the image. Only by deleting the old file first and then adding the new file can the effect of modifying the file be achieved.
[0029] It's also understandable that when a mirror layer build instruction involves deleting some files and adding others, the order of deletion must be followed, then addition. This is because deletion actually masks old files from the previous mirror layer by generating a deletion marker in the current mirror layer. If addition is done before deletion, the corresponding mirror layer for the newly added file will not contain the file to be deleted, making accurate deletion impossible. Only by deleting first and then adding can the effect of accurately deleting some files and adding others be achieved based on the previous mirror layer.
[0030] Optionally, S122 includes: S1221, if the list of newly added files includes at least two newly added files, split the list of newly added files into at least two sub-lists of newly added files.
[0031] Specifically, there are various ways to implement the new file list. The following are typical examples, but they do not constitute a limitation of this disclosure.
[0032] In some embodiments, the list of newly added files includes dependency files and application files. Dividing the list of newly added files into at least two sub-lists of newly added files includes assigning dependency files to one sub-list and application files to another sub-list. Alternatively, each dependency file can be assigned to its own corresponding sub-list of newly added files, and the application files can be assigned to a separate sub-list of newly added files.
[0033] Specifically, dependency files refer to external libraries, frameworks, toolchains, and / or environment configuration files that are necessary for the application to run.
[0034] Specifically, application files refer to the core source code that implements specific business logic.
[0035] It's understandable that the same dependency file can often be used to build different images, and the application files in different images are usually different. Based on this, by splitting the dependency file and application files into different sub-lists of newly added files, and then building a corresponding second image layer for each sub-list, the dependency file and application files are distributed across different second image layers. Thus, when different images use the same dependency file for building, cross-image caching reuse and storage deduplication of the image layer corresponding to the dependency file can be achieved. Specifically, during the image building process, the image layer generated by the dependency file can be shared by multiple images. The image repository can eliminate duplicate image layers during storage, significantly saving storage space. Furthermore, when uploading an image to the image repository, the image layer corresponding to the dependency file only needs to be transmitted once, effectively reducing network bandwidth consumption.
[0036] In other embodiments, the list of newly added files is split into at least two sub-lists of newly added files, including: assigning each newly added file with a reuse tag to a corresponding sub-list of newly added files, and assigning the remaining newly added files without reuse tags to another list of newly added files, wherein the reuse tag is used to indicate that the newly added file is reused in the process of building other images. Alternatively, all newly added files with reuse tags can be assigned to a sub-list of newly added files, and the remaining newly added files without reuse tags can be assigned to another list of newly added files.
[0037] Specifically, sometimes the same file can be used to build different images, and users can mark the file as reusable.
[0038] Understandably, the same file can sometimes be used to build different images. Based on this, by splitting newly added files with and without reuse tags into different sub-lists of newly added files, and then building a corresponding second image layer for each sub-list, the newly added files with and without reuse tags are distributed across different second image layers. Thus, when different images are built using the same newly added file with reuse tags, cross-image cache reuse of the image layer corresponding to the newly added file with reuse tags can be achieved. Furthermore, the reuse tag distinguishes between reused and unreused files, allowing users to flexibly differentiate the reuse attributes of different files during the image building process.
[0039] In some other embodiments, the list of newly added files is split into at least two sub-lists of newly added files, including assigning each newly added file to a corresponding sub-list of newly added files.
[0040] S1222. Construct the corresponding second image layer according to each sub-new file list, wherein in the image stacking structure, the previously constructed second image layer is located below the second image layer constructed later.
[0041] Specifically, building a corresponding second mirror layer for each sub-list of newly added files means that for each sub-list of newly added files, the content of the newly added files in that sub-list is written into a corresponding second mirror layer. Of course, metadata such as the storage path, file permissions, owner, and / or timestamp of the newly added files can also be written into the second mirror layer.
[0042] Specifically, based on the corresponding first mirror layer, multiple second mirror layers are constructed sequentially using each newly added sub-file list. The later constructed second mirror layer takes the earlier constructed second mirror layer as its direct lower layer, and the first second mirror layer takes the corresponding first mirror layer as its direct lower layer. Optionally, after S120, the method further includes: calculating the content addresses of the first and second mirror layers respectively to obtain the first content address corresponding to the first mirror layer and the second content address corresponding to the second mirror layer. In accordance with the construction order of the first and second image layers, the first content address and the second content address are recorded in the image layer list of the image in sequence.
[0043] Specifically, for each first image layer, the content written in the first image layer is addressed (such as a hash value) to obtain the corresponding first content address.
[0044] Specifically, for each second image layer, the content written in the second image layer is addressed (such as a hash value) to obtain the corresponding second content address.
[0045] Specifically, during image building, a unique content address is calculated for each image layer. Then, according to the actual generation order of these image layers during the building process, their corresponding content addresses are recorded sequentially into the image layer list of that image.
[0046] Understandably, by calculating the first and second content addresses corresponding to the first and second mirror layers respectively, and recording these addresses sequentially in the mirror layer list, it becomes easier to determine whether an existing second mirror layer with the same content exists based on the second content address. If a second mirror layer with a matching second content address is found in the local cache, the data for that layer can be directly reused without repeated caching, effectively saving cache space.
[0047] Optionally, the method further includes: if the file change list only includes a list of deleted files, directly constructing the corresponding first mirror layer based on the list of deleted files; if the file change list only includes a list of added files, directly constructing the corresponding second mirror layer based on the list of added files.
[0048] S130. Cache the first image layer. If the second image layer has not been cached, cache the second image layer.
[0049] Specifically, if the second image layer has not yet been cached, the second image layer is stored, including: based on the second content address of the second image layer, querying whether an image layer with the same content address has been cached; if not, the second image layer is cached.
[0050] Optionally, the method further includes: after the image is built, uploading the first image layer, the second image layer that has not yet been uploaded, and the list of image layers to the image repository.
[0051] Specifically, if the second content address of the second mirror layer is the same as the content address of a previously uploaded mirror layer, it indicates that the second mirror layer has been uploaded; otherwise, it indicates that the second mirror layer has not been uploaded.
[0052] Understandably, after the image is built, the first image layer generated, the second image layer that has not yet been uploaded (i.e., the layer whose content addressing does not exist in the image repository), and the list of image layers are uploaded to the image repository. Duplicate second image layers are identified through content addressing, and only second image layers not stored in the image repository are uploaded, avoiding duplicate transmission and storage, thereby saving bandwidth and storage space.
[0053] Optionally, the method further includes: after the image is built, uploading all first image layers, all second image layers, and a list of image layers to the image repository. The image repository then performs deduplication storage based on content addressing.
[0054] In this embodiment of the disclosure, when building an image, the list of deleted files and the list of added files corresponding to the same image layer build instruction can be automatically split into different image layers, instead of placing them in the same image layer as in the prior art. This ensures that the image layer containing the list of added files remains stable in content, unaffected by differences in the list of deleted files. Thus, when a user builds a new image on different base images, even if different small files are deleted (i.e., different lists of deleted files), as long as the same large files are added (i.e., the same list of added files), the image layer containing the list of added files remains consistent, requiring only one copy for storage and transmission. This achieves cache reuse across image builds, effectively saving cache space.
[0055] To illustrate the image building method provided in this disclosure in detail, a specific example is given below. Figure 2 This is a flowchart illustrating an example of image building provided in this disclosure, such as... Figure 2 As shown, during the image building process, for each image layer to be created, the entire file change list is scanned, dividing the file change list into a deleted file list and a new file list. If the deleted file list is not empty, a first image layer is created first to store the deletion markers of the deleted file list, and then a second image layer is created to store the new file list. The second image layer is located above the first image layer, and the content addresses of both the first and second image layers are recorded in the image layer list. If the deleted file list is empty, a second image layer is created to store the new file list, and the content addresses of the second image layer are recorded in the image layer list. After all images are built, all image layers (or image layers that have not been uploaded) and the image layer list are uploaded to the image repository. Figure 3 This is a storage diagram of a mirror repository provided in an embodiment of this disclosure. Figure 4 This is a storage diagram of another mirror repository provided in an embodiment of this disclosure. For example... Figure 3 and Figure 4 As shown, the present invention splits the list of changed files, which helps to reduce unnecessary image layers, reduce storage space and transmission bandwidth, and improve the cache utilization efficiency of the distribution system. This can significantly improve the efficiency of image storage and distribution in actual production scenarios.
[0056] Figure 5This is a schematic diagram of a mirror image building device provided in an embodiment of this disclosure. This mirror image building device can be understood as the aforementioned electronic device or a functional module within the aforementioned electronic device. For example... Figure 5 As shown, the image building apparatus includes: The first acquisition module 510 is used to acquire the file change list corresponding to the image layer build instruction in response to the image layer build instruction; The first construction module 520 is configured to, if the file change list includes a list of deleted files and a list of added files, construct mirror layers according to the list of deleted files and the list of added files respectively, to obtain a first mirror layer corresponding to the list of deleted files and a second mirror layer corresponding to the list of added files, wherein, in the stacked structure of the mirrors, the first mirror layer is located below the second mirror layer.
[0057] The first construction module 520 is specifically used to, if the file change list includes a list of deleted files and a list of added files, first construct the corresponding first mirror layer according to the list of deleted files, and then construct the corresponding second mirror layer according to the list of added files; The first caching module is used to cache the first image layer, and if the second image layer has not been cached, it caches the second image layer.
[0058] Optionally, the first build module 520 includes a first build submodule, used to build the corresponding second image layer based on the newly added file list, wherein the first build submodule includes: The first splitting unit is used to split the list of newly added files into at least two sub-lists of newly added files if the list of newly added files includes at least two newly added files. The first building unit is used to build the corresponding second image layer according to each of the sub-new file lists, wherein in the stacked structure of the images, the previously built second image layer is located below the second image layer that has been built later.
[0059] Optionally, the list of newly added files includes dependency files and application files, wherein the first splitting unit is specifically used to divide the dependency files into one of the sub-lists of newly added files and the application files into another of the sub-lists of newly added files.
[0060] Optionally, the first splitting unit is specifically used to divide each of the newly added files with a reuse mark into a corresponding sub-list of newly added files, and to divide the remaining newly added files without a reuse mark into another list of newly added files, wherein the reuse mark is used to indicate that the newly added file is reused in the process of building other images.
[0061] Optionally, the device further includes: a first addressing module, configured to, after constructing mirror layers according to the deleted file list and the added file list respectively to obtain a first mirror layer corresponding to the deleted file list and a second mirror layer corresponding to the added file list, calculate the content addresses of the first mirror layer and the second mirror layer respectively to obtain a first content address corresponding to the first mirror layer and a second content address corresponding to the second mirror layer; The first recording module is used to record the first content address and the second content address in the image layer list of the image in the order of the construction of the first image layer and the second image layer.
[0062] Optionally, the device further includes an upload module, used to upload the first image layer, the second image layer that has not yet been uploaded, and the list of image layers to the image repository after the image is built.
[0063] The apparatus provided in this embodiment can execute the methods of any of the above embodiments, and its execution method and beneficial effects are similar, so they will not be described again here.
[0064] This disclosure also provides an electronic device, which includes: a memory storing a computer program; and a processor for executing the computer program, wherein when the computer program is executed by the processor, it can implement the methods of any of the above embodiments.
[0065] Example, Figure 6 This is a schematic diagram of the structure of an electronic device according to an embodiment of this disclosure. See below for details. Figure 6 The diagram illustrates a structural schematic suitable for implementing the electronic device 600 in the embodiments of this disclosure. The electronic device 600 in the embodiments of this disclosure may include, but is not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), in-vehicle terminals (e.g., in-vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers. Figure 6 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments disclosed herein.
[0066] like Figure 6As shown, electronic device 600 may include a processing device (e.g., a central processing unit, a graphics processor, etc.) 601, which can perform various appropriate actions and processes according to a program stored in read-only memory (ROM) 602 or a program loaded from storage device 608 into random access memory (RAM) 603. RAM 603 also stores various programs and data required for the operation of electronic device 600. Processing device 601, ROM 602, and RAM 603 are interconnected via bus 604. Input / output (I / O) interface 605 is also connected to bus 604.
[0067] Typically, the following devices can be connected to I / O interface 605: input devices 606 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 607 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 608 including, for example, magnetic tapes, hard disks, etc.; and communication devices 609. Communication device 609 allows electronic device 600 to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 6 An electronic device 600 with various devices is shown; however, it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed alternatively.
[0068] In particular, according to embodiments of this disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this disclosure include a computer program product comprising a computer program carried on a non-transitory computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device 609, or installed from a storage device 608, or installed from a ROM 602. When the computer program is executed by the processing device 601, it performs the functions defined in the methods of embodiments of this disclosure.
[0069] It should be noted that the computer-readable medium described in this disclosure can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this disclosure, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this disclosure, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium can be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (radio frequency), etc., or any suitable combination thereof.
[0070] In some implementations, clients and servers can communicate using any currently known or future-developed network protocol such as HTTP (Hypertext Transfer Protocol) and can interconnect with digital data communication (e.g., communication networks) of any form or medium. Examples of communication networks include local area networks (“LANs”), wide area networks (“WANs”), the Internet (e.g., the Internet of Things), and peer-to-peer networks (e.g., ad hoc peer-to-peer networks), as well as any currently known or future-developed networks.
[0071] The aforementioned computer-readable medium may be included in the aforementioned electronic device; or it may exist independently and not assembled into the electronic device.
[0072] The aforementioned computer-readable medium carries one or more programs, which, when executed by the electronic device, cause the electronic device to perform the method described in any of the above embodiments.
[0073] Computer program code for performing the operations of this disclosure can be written in one or more programming languages or a combination thereof, including but not limited to object-oriented programming languages such as Java, Smalltalk, and C++, as well as conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0074] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0075] The units described in the embodiments of this disclosure can be implemented in software or in hardware. The names of the units are not, in some cases, intended to limit the specific unit.
[0076] The functions described above in this document can be performed at least in part by one or more hardware logic components. For example, exemplary types of hardware logic components that can be used, without limitation, include: field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), system-on-a-chip (SoCs), complex programmable logic devices (CPLDs), and so on.
[0077] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0078] This disclosure also provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it can implement the methods of any of the above embodiments. The execution method and beneficial effects are similar, and will not be described again here.
[0079] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0080] The above description is merely a specific embodiment of this disclosure, enabling those skilled in the art to understand or implement it. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this disclosure. Therefore, this disclosure is not to be limited to the embodiments described herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for constructing an image, characterized in that, Applied to a client, the method includes: In response to the image layer build command, obtain the file change list corresponding to the image layer build command; If the file change list includes a list of deleted files and a list of added files, a mirror layer is constructed according to the list of deleted files and the list of added files respectively to obtain a first mirror layer corresponding to the list of deleted files and a second mirror layer corresponding to the list of added files. In the stacked structure of the mirrors, the first mirror layer is located below the second mirror layer. Cache the first image layer. If the second image layer has not been cached, cache the second image layer.
2. The method according to claim 1, characterized in that, The step of constructing mirror layers based on the deleted file list and the added file list to obtain a first mirror layer corresponding to the deleted file list and a second mirror layer corresponding to the added file list includes: First, construct the first mirror layer based on the list of deleted files, and then construct the second mirror layer based on the list of newly added files.
3. The method according to claim 2, characterized in that, The step of constructing the corresponding second mirror layer based on the newly added file list includes: If the list of newly added files includes at least two newly added files, the list of newly added files shall be split into at least two sub-lists of newly added files. The corresponding second image layer is constructed according to each of the sub-new file lists, wherein in the stacked structure of the images, the previously constructed second image layer is located below the subsequently constructed second image layer.
4. The method according to claim 3, characterized in that, The list of newly added files includes dependency files and application files, wherein splitting the list of newly added files into at least two sub-lists of newly added files includes: The dependency files are assigned to one of the sub-new file lists, and the application files are assigned to another of the sub-new file lists.
5. The method according to claim 3, characterized in that, The step of splitting the newly added file list into at least two sub-lists of newly added files includes: Each newly added file with a reuse tag is assigned to a corresponding sub-list of newly added files, and the remaining newly added files without reuse tags are assigned to another list of newly added files. The reuse tag is used to indicate that the newly added file is reused in the process of building other images.
6. The method according to claim 1, characterized in that, After constructing mirror layers based on the deleted file list and the added file list respectively, to obtain the first mirror layer corresponding to the deleted file list and the second mirror layer corresponding to the added file list, the method further includes: Calculate the content addressing of the first mirror layer and the second mirror layer respectively to obtain the first content addressing of the first mirror layer and the second content addressing of the second mirror layer; In accordance with the construction order of the first image layer and the second image layer, the first content address and the second content address are recorded in the image layer list of the image in sequence.
7. The method according to claim 6, characterized in that, Also includes: After the image is built, the first image layer, the second image layer that has not yet been uploaded, and the list of image layers are uploaded to the image repository.
8. A mirror construction apparatus, characterized in that, Applied to a client, wherein the device includes: The first acquisition module is used to acquire the file change list corresponding to the image layer build instruction in response to the image layer build instruction; The first construction module is configured to, if the file change list includes a list of deleted files and a list of added files, construct mirror layers according to the list of deleted files and the list of added files respectively, to obtain a first mirror layer corresponding to the list of deleted files and a second mirror layer corresponding to the list of added files, wherein, in the stacked structure of the mirrors, the first mirror layer is located below the second mirror layer; The first caching module is used to cache the first image layer, and if the second image layer has not been cached, it caches the second image layer.
9. An electronic device, characterized in that, include: A processor and a memory, wherein the memory stores a computer program that, when executed by the processor, performs the method of any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The storage medium stores a computer program that, when executed by a processor, implements the method as described in any one of claims 1-7.