Container configuration reconstruction quantitative analysis method fusing file semantics and cross-stage dependence

By generating single-stage and multi-stage syntax trees, and combining depth-first search and multi-dimensional quantization models, the problem of the inability to quantify and evaluate Dockerfile refactoring in existing technologies is solved, and accurate quantitative evaluation and automated decision support for container configuration refactoring are achieved.

CN121523693AActive Publication Date: 2026-02-13NAT UNIV OF DEFENSE TECH
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202610061368.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-01-16
Publication Date
2026-02-13
Estimated Expiration
2046-01-16

AI Technical Summary

Technical Problem

Existing technologies struggle to automate and quantify the effects of refactoring Dockerfiles from a single-stage build mode to a multi-stage build mode. They also fail to accurately identify cross-stage dependencies and file operation changes, leading to refactoring decisions relying on human experience and hindering large-scale application.

Method used

By generating single-stage and multi-stage syntax trees, utilizing depth-first search algorithms and multi-dimensional quantization models, configuration change patterns are identified and quantified, generating refactoring analysis reports and providing data-driven decision support.

Benefits of technology

It enables precise quantitative assessment of container configuration refactoring, automatically identifies instruction migration, dependency chain introduction, and redundant file deletion, and improves the automation level and reliability of large-scale container configuration migration and optimization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121523693A_ABST
    Figure CN121523693A_ABST
Patent Text Reader

Abstract

The invention relates to a container configuration reconstruction quantitative analysis method fusing file semantics and cross-stage dependence. The method comprises the steps that on the basis of an obtained single-stage initial syntax tree, construction stages are divided according to an FROM instruction, a cross-stage dependency edge is established according to a COPY-from instruction, and a multi-stage dependency syntax tree is constructed; respectively traversing the single-stage initial syntax tree and the multi-stage dependent syntax tree by adopting a depth-first search algorithm to generate a single-stage path set and a multi-stage path set, performing comparative analysis on the single-stage path set and the multi-stage path set based on a multi-dimensional quantitative model, and identifying and quantitatively configuring a change mode; and according to the quantitative analysis result, realizing container configuration change mode analysis and outputting a reconstruction analysis report. By adopting the method, refined analysis and change mode classification of the multi-stage Docker file can be realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data processing technology, and in particular to a quantitative analysis method for container configuration refactoring that integrates file semantics and cross-stage dependencies. Background Technology

[0002] Containers are a lightweight virtualization technology that packages an application and its dependencies (such as libraries, system tools, and runtime environments) into an isolated process, achieving standardization and consistency of the application environment. They have become a core infrastructure of modern cloud computing and microservice architectures. A Dockerfile is a declarative, automated build script for container environments. It precisely describes how to start from the base operating system, progressively install software, configure the environment, deploy the application, and ultimately generate a custom image that meets specific needs. A single-stage Dockerfile describes a linear, single build process. It typically starts with a base image and progressively installs dependencies, compiles code, and configures the environment through a series of instructions (such as RUN and COPY), ultimately generating a single, often bloated image containing all build tools and the runtime environment. In contrast, a multi-stage Dockerfile breaks down a complex build process into multiple discrete stages. For example, a large image containing a full set of compilation tools might be used in the build stage to compile the source code into binaries, while a minimal base image might be used in the runtime stage, copying only the compiled binaries from the first stage. In this way, the final image contains only the necessary elements for operation, thus significantly reducing the image size and the potential security attack surface.

[0003] Given the significant advantages of multi-stage Dockerfiles in terms of efficiency and security, refactoring existing single-stage Dockerfiles into multi-stage structures has become a common and important optimization practice. Accurate evaluation of such refactoring is a core prerequisite for data-driven container image optimization. It upgrades refactoring decisions from a trial-and-error process relying on human experience to a quantifiable and predictable scientific process, thereby systematically improving the security and operational efficiency of application deployments. However, deeply understanding and accurately evaluating such refactorings faces significant challenges: existing parsing tools (such as the dockerfile_parse library) only support single-stage instruction parsing and lack the ability to structurally express inter-stage dependencies (especially the cross-stage file copy semantics defined by the COPY --from instruction), making it difficult to capture key contexts during refactoring analysis; traditional difference comparison methods (such as text diff) cannot understand the syntax and semantics of Dockerfiles, cannot identify logical operations such as "instruction movement," "file path change," and "dependency import," and cannot quantify these changes; existing methods heavily rely on human experience to analyze refactoring effects (such as image size reduction), making it difficult to automatically and quantitatively evaluate refactoring benefits and dependency complexity, and failing to provide data-driven decision support for large-scale refactoring. Summary of the Invention

[0004] The purpose of this application is to overcome the shortcomings of the prior art and provide a container configuration refactoring quantitative analysis method that integrates file semantics and cross-stage dependencies. This method can automatically and finely analyze refactoring changes and is suitable for automated refactoring analysis, change impact quantification, and optimization guidance during the migration of Dockerfile from a single-stage build mode to a multi-stage build mode.

[0005] A quantitative analysis method for container configuration refactoring that integrates file semantics and cross-stage dependencies, the method comprising: Obtain the original single-stage Dockerfile and the refactored multi-stage Dockerfile; preprocess the original single-stage Dockerfile and the refactored multi-stage Dockerfile respectively to obtain the initial syntax tree for the single stage; Based on the single-stage initial syntax tree, the construction stages are divided according to the FROM instruction, and cross-stage dependency edges are established according to the COPY --from instruction to construct a multi-stage dependency syntax tree. A depth-first search algorithm is used to traverse the single-stage initial syntax tree and the multi-stage dependency syntax tree respectively, record the path from the root node to the leaf node, generate the single-stage path set and the multi-stage path set, and construct a global file mapping table; the single-stage path set and the multi-stage path set are compared and analyzed based on a multi-dimensional quantization model to identify and quantify the configuration change mode; based on the quantization analysis results, container configuration change mode analysis is implemented, and a refactoring analysis report is output.

[0006] The aforementioned quantitative analysis method for container configuration refactoring, which integrates file semantics and cross-stage dependencies, first generates original single-stage syntax trees (SDAST) and multi-stage dependency syntax trees (MDAST) through preprocessing. MDAST delineates construction stage boundaries based on the FROM instruction and establishes explicit cross-stage dependency edges using the COPY --from instruction, achieving a structured expression of multi-stage construction semantics and overcoming the limitation of traditional parsing tools in representing inter-stage dependencies. Based on this, the DFS algorithm traverses SDAST and MDAST, extracting complete paths from root nodes to leaf nodes to generate path sets, and constructs a global file mapping table to track file lifecycles, transforming the abstract syntactic structure into quantifiable data objects. Through a multi-dimensional quantitative comparison model, the path edit distance is calculated to analyze the degree of instruction position changes, file path similarity is used to assess file operation semantic changes, and cross-stage dependency complexity is quantified through stage dependency strength. This transforms abstract container configuration changes into objective quantitative indicators, shifting the analysis results from qualitative to quantitative, supporting data-driven decision-making, and achieving accurate quantitative evaluation of refactoring changes. Ultimately, based on the quantitative analysis results, it automatically identifies advanced refactoring patterns such as instruction cross-stage migration, dependency chain introduction, and redundant file deletion, and outputs key indicators such as estimated image size reduction and dependency strength change values. This provides data-driven decision support for Dockerfile refactoring from single-stage to multi-stage, significantly improving the automation level and reliability of large-scale container configuration migration and optimization. Attached Figure Description

[0007] Figure 1 This is a flowchart illustrating a quantitative analysis method for container configuration refactoring that integrates file semantics and cross-stage dependencies in one embodiment. Figure 2 This is a schematic diagram of the framework for a container configuration refactoring quantitative analysis method that integrates file semantics and cross-stage dependencies in one embodiment. Detailed Implementation

[0008] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0009] In one embodiment, such as Figure 1 and Figure 2 As shown, a quantitative analysis method for container configuration refactoring that integrates file semantics and cross-stage dependencies is provided, including the following steps: 101: Obtain the original single-stage Dockerfile and the refactored multi-stage Dockerfile; preprocess the original single-stage Dockerfile and the refactored multi-stage Dockerfile respectively to obtain the initial single-stage syntax tree.

[0010] Input the original single-stage Dockerfile and the refactored multi-stage Dockerfile; preprocess the two Dockerfiles respectively, including removing comments and whitespace characters, parse the instructions and generate the corresponding single-stage initial syntax tree (SDAST, Single-stage Dockerfile AST) and multi-stage dependency syntax tree (MDAST, Multi-stage Dockerfile AST).

[0011] 102: Based on the single-stage initial syntax tree, the build stages are divided according to the FROM instruction, and cross-stage dependency edges are established according to the COPY --from instruction to build a multi-stage dependency syntax tree: The construction of SDAST includes: using a Dockerfile parser (such as the dockerfile_parse library) to parse the preprocessed text line by line, identify various instructions and generate corresponding syntax nodes; finally, with "Dockerfile" as the root node and all instruction nodes as direct children of the root node, a flat tree structure is constructed according to their declaration order. This structure fully preserves the instruction semantics and execution sequence of the single-stage construction, providing a benchmark model for subsequent multi-stage reconstruction quantitative analysis.

[0012] 103: A depth-first search algorithm is used to traverse the single-stage initial syntax tree and the multi-stage dependency syntax tree respectively, record the path from the root node to the leaf node, generate the single-stage path set and the multi-stage path set, and construct a global file mapping table; the single-stage path set and the multi-stage path set are compared and analyzed based on a multi-dimensional quantization model to identify and quantify the configuration change mode; based on the quantization analysis results, container configuration change mode analysis is implemented, and a refactoring analysis report is output.

[0013] Based on the initial syntax tree generated by parsing, the stage boundaries are determined according to the FROM instruction, and each build stage is treated as a child node. The COPY / ADD instructions are parsed, and their source and target paths are extracted as node attributes. The COPY --from instruction is parsed to establish cross-stage dependency edges and bind the source stage alias and source path information. At the same time, source and target path attributes are assigned to all file operation instruction nodes. Finally, a hierarchical tree structure with "Dockerfile" as the root node, each stage as a child node, and dependencies between nodes is constructed. This structure realizes a structured expression of the semantics of multi-stage builds and provides a core model foundation for cross-stage path comparison and dependency quantification analysis.

[0014] A depth-first search algorithm is used to traverse SDAST and MDAST, recording the paths from the root node to each leaf node, generating single-stage and multi-stage path sets. Simultaneously, a global file mapping table is constructed during the traversal. M This mapping is used to precisely track the complete lifecycle of each file during the build process. The mapping table consists of multiple triples: M = {<f,op, stage_source → stage_destination>}, where: f represents the file identifier (usually a file path), op represents the file operation type (such as CREATE, COPY, DELETE), and stage_source → stage_destination represents the stage context in which the operation occurs.

[0015] Based on this mapping table, the change in penetration of file f before and after reconstruction can be quantitatively calculated. The calculation formula is as follows: ; Where (f) represents the set of all stages involved in file f. When A value less than 0 indicates that the file is restricted to fewer stages after reconstruction, which is an important quantitative indicator of improved security.

[0016] The single-stage path set and the multi-stage path set are compared and analyzed based on a multi-dimensional quantification model to identify and quantify configuration change patterns; the multi-dimensional quantification model includes: Path structure change quantification assesses the degree of positional change of instructions in the build process. The edit distance algorithm is used to calculate the edit distance (LD) between two path sequences, which is the minimum number of single-character editing operations (insertion, deletion, replacement) required. This quantifies the degree of positional change of the instructions; a larger LD value indicates a higher degree of rearrangement of the instruction sequence and a more significant structural change resulting from the reconstruction. Semantic change quantification of file operations reflects adjustments to resource dependencies through changes in path parameters. For file operation commands, file path similarity (FPS) based on the longest common subsequence (LCS) is used to quantify this change. The FPS value ranges from [0, 1], with a value closer to 1 indicating a smaller semantic change in the file path; a lower value indicates a significant change in the path.

[0017] Cross-stage dependency strength quantification (SDI) introduces clear inter-stage dependencies. To assess the complexity of the restructured dependency network, SDI measures the ratio of the actual number of cross-stage dependency edges to the maximum possible number of dependency edges required for a minimum spanning tree structure. A higher SDI value indicates tighter inter-stage coupling and a more complex dependency network.

[0018] Based on the above multidimensional quantitative analysis results, the system automatically summarizes high-level refactoring patterns. For the instruction cross-stage migration pattern, its core characteristic is that the instruction sequence undergoes a significant structural shift but remains semantically stable. This pattern is determined by two indicators: path edit distance (LD) and file path similarity (FPS). When the path LD value corresponding to an instruction is high, and the file path FPS value it operates on is close to 1, it can be determined that the instruction has undergone cross-stage migration. The successful implementation of this pattern means that heavy operations such as compilation are isolated in the early stages, avoiding pollution of the final runtime image.

[0019] For the dependency chain introduction pattern, a `COPY --from` dependency edge is explicitly added to the refactored multi-stage syntax tree. This pattern uses stage dependency strength... The changes in dependence intensity are quantitatively assessed. = SDI(G_multi) - SDI(G_single) directly reflects the dependency complexity introduced by the refactoring. While some dependencies are necessary, If the value is too high, it indicates that the network dependency may be too complex and needs to be reviewed and optimized.

[0020] For the redundant file removal mode, stage isolation ensures that tools and intermediate files needed only during the build phase will not appear in the final image. This mode utilizes a global file mapping table. M The process involves identifying and deleting a file f that exists in the final image of a single-stage build but not in the final image of a multi-stage build. The resulting benefit is estimated through image size reduction. The quantification is performed using the formula that calculates the sum of the sizes of all deleted files: = ∑size(f)|fin F_deleted. This metric directly measures the benefits of refactoring in reducing storage overhead and attack surface. Through file mapping tables and data derivation, the image size reduction can be automatically estimated. ), assess changes in dependency complexity ( This allows for direct quantification of the performance benefits of container configuration refactoring, greatly enhancing the practical value of the analysis results.

[0021] Finally, by combining the above patterns and quantitative indicators, an analysis report is generated, indicating what kind of restructuring has occurred and precisely answering questions about the degree of restructuring (LD) and how complex the dependencies have become (…). And how much profit () This provides solid data support for optimizing decision-making on key issues such as (…).

[0022] The aforementioned quantitative analysis method for container configuration refactoring, which integrates file semantics and cross-stage dependencies, first generates an original syntax tree through preprocessing. It then divides stage boundaries based on the FROM instruction and identifies cross-stage dependencies using the COPY --from instruction. This constructs a multi-stage abstract syntax tree with "Dockerfile" as the root and each stage as its child nodes. This overcomes the limitation of traditional tools that only support single-stage parsing, achieving a structured representation of multi-stage dependencies and resolving the context omission problem caused by incomplete dependency extraction. Based on this, the DFS algorithm traverses the syntax tree and records the path from the root to the leaf nodes, transforming the abstract syntax structure into quantifiable and comparable path information, providing a unified comparison benchmark for change analysis. Subsequently, a cross-stage dependency parsing algorithm clarifies the stage relationships of instructions such as COPY --from, and a path difference classification algorithm automatically identifies logical change types such as additions, deletions, moves, and modifications, replacing traditional text comparison and manual annotation methods, and achieving accurate classification of change patterns. Ultimately, based on the path difference analysis results, it can automatically identify the configuration change patterns in multi-stage builds, provide dependency guidance for Dockerfile migration from single-stage to multi-stage, and provide data support for optimizing image size, significantly improving the automation level of configuration migration and optimization in large-scale scenarios.

[0023] In one embodiment, the original single-stage Dockerfile and the refactored multi-stage Dockerfile are preprocessed to obtain a single-stage initial syntax tree, including: Comments and whitespace characters are removed from the original single-stage Dockerfile and the refactored multi-stage Dockerfile to obtain the preprocessed text. The dockerfile_parse library is used to parse the preprocessed text line by line, identify various instructions and generate corresponding syntax nodes. Using "Dockerfile" as the root node and all the syntax nodes corresponding to the instructions as direct children of the root node, a flat tree structure is built in the order of their declaration as the single-stage initial syntax tree.

[0024] In one embodiment, based on a single-stage initial syntax tree, the construction stages are divided according to the FROM instruction, and cross-stage dependency edges are established according to the COPY --from instruction to construct a multi-stage dependency syntax tree, including: Based on the FROM instruction, the distribution of FROM nodes in the reconstructed multi-stage Dockerfile is parsed to determine the stage boundaries of each build stage; Parse the COPY / ADD instructions and extract their source and destination paths as node attributes; Parse the COPY --from directive, establish cross-stage dependency edges, and bind the source stage alias and source path information; Using "Dockerfile" as the root node, a multi-stage dependency syntax tree is constructed by treating each build stage as a stage child node based on stage boundaries.

[0025] In one embodiment, the stage boundaries include a start and an end; the start indicates the current FROM instruction; the end indicates the period before the next FROM instruction or the end of the file.

[0026] In one embodiment, a depth-first search algorithm is used to traverse the single-stage initial syntax tree and the multi-stage dependency syntax tree respectively, record the path from the root node to the leaf node, generate a single-stage path set and a multi-stage path set, and construct a global file mapping table, including: A depth-first search algorithm is used to traverse the single-stage initial syntax tree and the multi-stage dependency syntax tree, recording the paths from the root node to each leaf node, and generating a single-stage path set. With multi-stage path sets Each path Represented as an ordered sequence of nodes ; At the same time, a global file mapping table is constructed. M This is used to precisely track the complete lifecycle of each file during the build process; mapping table M = {<f, op, stage_source → stage_destination>}, where f represents the file identifier, op represents the file operation type, and stage_source → stage_destination represents the stage context in which the operation occurs.

[0027] In one embodiment, the multidimensional quantization model includes a path structure variable quantization model, a file operation semantic change quantization model, and a cross-stage dependency strength quantization model; the path structure variable quantization model is used to calculate the edit distance between two path sequences to quantify the degree of change in instruction positions; the file operation semantic change quantization model uses the longest common subsequence algorithm to calculate the file path similarity as follows: ; in, Represents a path string and path string The longest common subsequence; The cross-stage dependency strength quantization model is used to calculate the stage dependency strength of a multi-stage dependency syntax graph as follows: ; in, Represents the set of all stage nodes. It is a set of edges. "e is a COPY --fromdependency edge" is a declaration statement indicating that e is a COPY --from dependency edge.

[0028] It should be understood that, although Figure 1 The steps in the flowchart are shown sequentially as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order in which these steps are executed, and they can be performed in other orders. Figure 1 At least some of the steps in the process may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least some of the sub-steps or stages of other steps.

[0029] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0030] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of the invention. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.

Claims

1. A container configuration reconfiguration quantization analysis method fusing file semantics and cross-stage dependencies, characterized in that, The method comprises: Obtaining an original single-stage Dockerfile file and a reconstructed multi-stage Dockerfile file; preprocessing the original single-stage Dockerfile file and the reconstructed multi-stage Dockerfile file respectively to obtain a single-stage initial syntax tree; On the basis of the single-stage initial syntax tree, a multi-stage dependency syntax tree is constructed by dividing the construction stages according to the FROM instruction and establishing cross-stage dependency edges according to the COPY --from instruction; A single-stage path set and a multi-stage path set are generated by traversing the single-stage initial syntax tree and the multi-stage dependency syntax tree respectively using a depth-first search algorithm, recording the paths from the root node to the leaf node, and constructing a global file mapping table; and a configuration change mode is identified and quantified by comparing and analyzing the single-stage path set and the multi-stage path set based on a multi-dimensional quantization model; and a container configuration change mode analysis is realized according to the quantization analysis result, and a reconstruction analysis report is output.

2. The method of claim 1, wherein, The preprocessing of the original single-stage Dockerfile file and the reconstructed multi-stage Dockerfile file to obtain the single-stage initial syntax tree comprises: Removing comments and white spaces from the original single-stage Dockerfile file and the reconstructed multi-stage Dockerfile file to obtain preprocessed text; and parsing the preprocessed text line by line using a dockerfile_parse library to identify various instructions and generate corresponding syntax nodes; Taking the original single-stage Dockerfile file and the reconstructed multi-stage Dockerfile file as root nodes, and taking all instruction syntax nodes as direct child nodes of the root nodes, a flat tree structure is constructed as a single-stage initial syntax tree according to the declaration order of the syntax nodes.

3. The method of claim 1, wherein, On the basis of the single-stage initial syntax tree, a multi-stage dependency syntax tree is constructed by dividing the construction stages according to the FROM instruction and establishing cross-stage dependency edges according to the COPY --from instruction, which comprises: Determining the stage boundary of each construction stage by analyzing the distribution of FROM nodes in the reconstructed multi-stage Dockerfile file according to the FROM instruction; Parsing the COPY / ADD instruction to extract the source path and the target path as node attributes; Parsing the COPY --from instruction to establish cross-stage dependency edges and bind the source stage alias and the source path information; Taking all Dockerfile files as root nodes, and constructing a multi-stage dependency syntax tree by taking each construction stage as a stage child node according to the stage boundary.

4. The method of claim 3, wherein, The stage boundary comprises a start and an end; the start indicates the current FROM instruction; and the end indicates before the next FROM instruction or the end of the file.

5. The method of claim 1, wherein, The single-stage path set and the multi-stage path set are generated by traversing the single-stage initial syntax tree and the multi-stage dependency syntax tree respectively using a depth-first search algorithm, recording the paths from the root node to the leaf node, and constructing a global file mapping table, which comprises: The single-stage initial syntax tree and the multi-stage dependent syntax tree are traversed by using a depth-first search algorithm, and paths from a root node to each leaf node are recorded to generate a single-stage path set The multi-stage path set is generated by traversing the single-stage initial syntax tree and the multi-stage dependent syntax tree by using a depth-first search algorithm, and recording paths from a root node to each leaf node Each path in the multi-stage path set is represented as an ordered node sequence Each path in the multi-stage path set is represented as an ordered node sequence ; At the same time, a global file mapping table is constructed M to track the complete life cycle of each file during the build process; the mapping table M = { <f, op, stage_source → stage_destination>}, where f denotes a file identifier, op denotes a file operation type, and stage_source → stage_destination denotes a stage context in which the operation occurs.

6. The method of claim 1, wherein, The multi-dimensional quantification model comprises a path structure variable quantification model, a file operation semantics change quantification model and a cross-stage dependence intensity quantification model; the path structure variable quantification model is used for calculating an edit distance of two path sequences to quantify a change degree of an instruction position; the file operation semantics change quantification model adopts a longest common subsequence algorithm to calculate a file path similarity as: wherein represents a path string and a path string the longest common subsequence of The cross-stage dependence intensity quantification model is used for calculating a stage dependence intensity of a multi-stage dependence syntax graph as: wherein, a set of all stage nodes, is a set of edges, e is a COPY --from dependency edge a statement sentence that e is a COPY --from dependency edge.

Citation Information

Patent Citations

  • Detection method and device for container configuration compliance, storage medium and terminal

    CN116467047A

  • Python project mirror image construction method and device, equipment and storage medium

    CN119201144A

  • Multi-stage decision model construction method based on dynamic programming

    CN120875402A