如何选择应用现代化的下一步安全举措
应用现代化改造的请求,往往始于一个技术问题:该用哪个框架来替换旧的?在做选择之前,先弄清楚哪些部分仍然正常工作。然后收集证据,让这些证据成为该行为的回归防护网,并指出哪些地方确实需要现代化。
我在四个公开应用上采用了“证据优先”的方法,从一个小型 Node.js 游戏到一个大型 Java 企业资源规划(ERP)应用。每个应用都需要不同的处理方式,但我收集证据、选择下一个实验、以及确定可能验证点的方式是可复用的。
本文会完整走一遍这一过程,方便你把它应用到自己手上的某个应用。文中还会展示如何把这套流程编码进 GitHub Copilot 智能体技能,同时把架构判断权留给对系统负责的人。
应用身上的标签很少能告诉你足够的信息。“Java 微服务”不会告诉你生产环境运行的是哪个 Java 开发工具包(JDK)、这个版本在何处被固定、测试是否会执行,或者其他系统依赖哪些接口。“遗留单体”也不会告诉你业务核心是否已经损坏,或者是否因为一个已退役的平台依赖导致应用无法启动。
在你建议做出变更之前,先建立一份小型的证据清单:
在工作过程中记录下不确定之处。我用三个简单的标签:有文档记录、推断得出、未经验证。如果两个文件对 Java 版本的描述相互矛盾,就去解决这个矛盾。如果你无法确定某个 CI 检查是否会阻止合并,就如实说明。把未知项记录下来,而不是把猜测当作发现。
这份清单让你在提出变更之前,有具体的东西可以与负责该应用的人一起评审。
一旦理解了应用,就按组件逐一做决定。单个系统中可能包含应保留的代码、应替换的依赖,以及一个确实需要重写的子系统。
首先,检查某项能力是否仍然需要。只有在确认它未被使用或已被取代,并与它的负责人确认该决定之后,才移除它。移除是一个独立的决定,而且它未必是影响最大的那个。
对于仍然需要的能力,从改动最小的选项开始:
这是一个决策顺序,而不是对工作量或风险的通用排序。要问:有什么证据支持选择影响更大的选项?“代码旧了”并不够。一个已知漏洞且固定版本没有修复版本发布、某个依赖在所需运行时上失败,或者当前设计无法满足已测量的可靠性目标,都可以证明有必要升级到影响更大的方案。
下一个问题是,即使遗留 CI 流水线不是绿色的,该组件能否运行到足以产生证据的程度。
运行一次限时的可行性检查。尝试安装依赖、在可用工具链上构建、启动组件,并执行至少一个有意义的测试。时间一到就停止。结果会让你走向两条路径之一。
先捕获行为,再升级。当旧应用仍能以可接受的成本运行时,走这条路径。记录其对外可见的行为,在可行的情况下修复测试框架,并用这些检查来验证升级。
先构建一小块现代化的切片。当旧组件在你尚未改动它之前就无法运行时,就走这条路径。把最薄、最有用的工作流迁移到受支持的技术上,验证它,再从那里扩展。在这种情况下要求一套完整的遗留测试套件是循环论证。恢复测试套件本身就是现代化工作的一部分。
我使用以下安全级别(改编自 doc-and-modernize 技能)来描述可用的最强回归保护:
说明你能证明什么、还剩下什么风险。即使 L4 关卡也无法确立每一个可能的行为都正确。API、数据库效果、文件、渲染输出和业务流程往往能构成持久的比较点,因为这些行为能够经受住框架或语言的变化。
PiggyMetrics 是最清楚的例子:一个看起来比实际状况更糟的应用。该项目使用了 Java 8、Spring Boot 2.0.3、Spring Cloud Finchley、Zuul、Hystrix 以及旧的 spring-security-oauth2 库。
很容易就把这个应用称为不可用,然后开始画一套新架构。但可行性检查给出了不同的说法。
记录的可行性结果显示了对遗留 checkout 在 JDK 8 下运行的两个探针:
这些是历史结果,并不是期望在现代化的 checkout 上重现那些失败的命令。那九个错误从 Failed to load ApplicationContext 一路追溯到嵌入式 MongoDB 下载返回 HTTP 403。固定的二进制文件还面向 i386,无法在 Apple Silicon 主机上运行。
这些探针并没有证明整个应用能运行,也没有证明其集成行为是正确的。它们确实给了我一个更窄的下一步:在改动生产技术栈之前,先替换测试依赖并重新运行受影响的测试。
那个结果让我避免了一个非常整齐、也非常昂贵的错误。我当时已经开始考虑要替换架构中的哪些部分。仅仅一个损坏的测试依赖,并不足以成为重新设计应用的理由,而五个通过的测试确立了行为基线,让我可以在现代化改造过程中检查是否出现意外变更。
这一现代化计划把那项证据转化为「先捕获、再升级」的流程:
第一道验收关口是在旧技术栈上取得通过的基线,而不只是成功安装一个替代依赖。在 CI 中运行检查并将其作为合并要求强制执行,也是计划中相互独立的步骤。
结果摘要记录了 Java 和 Spring 的升级,同时保留了该应用本身用于演示的微服务拆分。Eureka 和 Cloud Config 予以保留;已退役的 Hystrix 和 Turbine 技术栈所用的两个监控模块被移除。纳入范围的构建从九个模块减少到七个。
这些版本描述的是那次实验,而不是建议今天选择相同的版本。请根据你当前的支持要求来选择目标版本。真正有价值的经验在于,仓库中的证据如何缩小了变更范围。
同一套流程在两个较小的应用上得出了不同的答案。它们固定版本的报告描述了这些选择:
这一对比需要一项重要的限定:DOOM 的检查冻结的是现代化改造后引擎自身的输出。它们防止的是后续的回归,而并未独立证明与符合当时年代的旧版二进制文件等价。明确说出这一局限,是选择诚实安全等级的一部分。
随后我把该方法应用到 ADempiere——一个大型 Java 套件,涵盖 ERP、客户关系管理、制造、供应链、会计和销售点。
规模改变了控制措施,但没有改变方法。这项工作建立了可复现的构建,将运行时迁移到 JDK 21,在将 XFire 替换为 CXF 和 Jakarta 的同时保留了 SOAP Web 服务契约,捕获了遗留 Web 行为,并为选定用户引入了现代 Web 路径。第一次现代业务伙伴写入与从遗留应用程序冻结的结果进行了比较。
这份固定的测量报告涵盖 30 个已合并的现代化 pull request,以及截至第一个被接受的可移植演示所重建的 102,587.72 个 Copilot credits。credits 总数不是美元成本。更重要的是,报告明确说明了该结果不是什么:它并非声称每个 ADempiere 屏幕或生产部署都已现代化。
我停了下来,因为概念验证问题已经得到回答。结果展示了在选定运行时上的构建、新旧路径一起运行,以及一项真实的业务写入与遗留结果进行了核对。完成其余部分本会需要一项产品资金决策,而不是另一个技术证明。停在那个边界是方法的一部分。
在重复这项工作之后,我不想让证据清单和决策规则只存在于我的笔记中。我把它们编码进了公开的 doc-and-modernize 智能体技能中。
智能体技能是 Copilot 在任务相关时可以加载的指令、脚本和资源文件夹。一个项目技能可以存放在一个仓库中:
.github/skills/doc-and-modernize/ ├── SKILL.md ├── references/ └── scripts/ 只有 SKILL.md 是必需的;这里显示的资源文件夹是可选的。该文件需要 YAML frontmatter,其中包含一个名称和一个描述,说明该技能做什么以及何时使用它,后面跟着指令。创建指南包含完整格式。
以下内容转述自锁定 commit 的技能源码,它的决策分叉点是:
完整的技能还加入了可行性检查、可测试性里程碑、安全等级、阶段门禁以及证据要求。
有用的区分是流程与策略之别。共享技能可以要求提供仓库证据、有边界的实验、明确的安全等级和可运行的退出标准。你的组织仍然需要提供只有它自己才知道的部分:
技能应当让这些决策变得可见,而不应替你做出这些决策。
原文较长,译文为节选;译文由英文原文机器翻译,术语按行业惯例统一,可在文末展开原文核对。
查看英文原文(How to choose the next safe step in application modernization)
A request to modernize an application often starts with a technology question: Which framework should replace the old one? Before you choose, find out what still works. Then collect evidence that can act as a regression net for that behavior and show where modernization is necessary.
I used an evidence-first method on four public applications, from a small Node.js game to a large Java enterprise resource planning (ERP) application. Each needed a different treatment, but the way I collected evidence, chose the next experiment, and decided on possible proof points was repeatable.
This post walks through that process so you can apply it to one application of your own. It also shows how to encode the procedure in a GitHub Copilot agent skill while keeping architectural judgment with the people responsible for the system.
Build evidence before choosing a target
The label on an application rarely tells you enough. “Java microservices” doesn’t tell you which Java Development Kit (JDK) runs in production, where that version is pinned, whether the tests execute, or which interfaces other systems depend on. “Legacy monolith” doesn’t tell you whether the business core is broken or whether one retired platform dependency prevents the application from starting.
Before you recommend a change, build a small evidence inventory:
- Manifests, lockfiles, entry points, and deployable components
- Verified commands for installing, building, testing, packaging, and running
- Runtime pins in containers, CI workflows, deployment files, and developer tooling
- External contracts such as APIs, database behavior, file formats, and user workflows
- End-of-life frameworks and dependencies, with evidence that the application still uses them
Record uncertainty while you work. I use three simple labels: documented, inferred, and unverified. If two files disagree about the Java version, resolve the contradiction. If you can’t determine whether a CI check blocks merges, say so. Record the unknown rather than treating a guess as a finding.
That inventory gives you something concrete to review with the people who own the application before you propose changes.
Choose the least disruptive treatment that works
Once you understand the application, make the decision per component. A single system can contain code that should stay, dependencies that should be swapped, and one subsystem that genuinely needs a rewrite.
First, check whether a capability is still needed. Remove it only after verifying that it is unused or superseded and confirming that decision with its owner. Removal is a separate decision, and it’s not necessarily the most disruptive one.
For a capability you still need, start with the option that changes the least:
- Keep it. Supported code that still fits the job doesn’t need a modernization story.
- Upgrade it. Move to a supported major version and fix the breaking changes.
- Swap it. Replace an abandoned dependency while preserving the existing design.
- Wrap it. Stabilize a useful interface and replace the internals in increments.
- Rewrite it. Use this when no responsible upgrade path exists or the architecture cannot meet the requirement.
This is a decision order, not a universal ranking of effort or risk. Ask what evidence justifies choosing a more disruptive option. “The code is old” is not enough. A known vulnerability with no patched release for the pinned version, a dependency that fails on the required runtime, or a measured reliability target the current design cannot meet can justify escalation.
Decide what proof is possible
The next question is whether the component can run well enough to produce evidence, even if the legacy CI pipeline is not green.
Run a time-boxed feasibility check. Try to install dependencies, build on an available toolchain, start the component, and execute at least one meaningful test. Stop when the time box expires. The result sends you down one of two paths.
Capture behavior, then upgrade. Use this path when the old application can still run at an acceptable cost. Record its externally visible behavior, fix the test harness where practical, and use those checks to verify the upgrade.
Build a small modern slice first. Use this path when the old component cannot run until you have already changed it. Move the thinnest useful workflow to supported technology, prove it, and expand from there. Requiring a complete legacy test suite in this situation is circular. Restoring the test suite is part of the modernization.
I use the following safety levels, adapted from the doc-and-modernize skill, to describe the strongest regression protection available:
| Level | Strongest honest protection |
|---|---|
| L0 | No usable regression net; treat the old code and available documentation as the specification. |
| L1 | Small reversible changes, old and new paths in parallel, smoke checks, and domain review. |
| L2 | Captured inputs and outputs, snapshots, or other behavioral comparisons. |
| L3 | Automated checks cover part of the system, with the remaining gaps named. |
| L4 | An automated CI gate combines lint, unit, behavioral, and end-to-end checks for the agreed scope. |
State what you can prove and what risk remains. Even an L4 gate cannot establish that every possible behavior is correct. APIs, database effects, files, rendered output, and business workflows often make durable comparison points because those behaviors can survive a framework or language change.
PiggyMetrics: capture behavior, then upgrade
PiggyMetrics was the clearest example of an application that looked worse than it was. The project used Java 8, Spring Boot 2.0.3, Spring Cloud Finchley, Zuul, Hystrix, and the old spring-security-oauth2 library.
It would have been easy to call the application unworkable and start drawing a new architecture. The feasibility check told a different story.
The recorded feasibility results show these two probes against the legacy checkout with JDK 8:
| Command | Recorded result | What it established |
|---|---|---|
mvn -pl config -am compile | Exit code 0 | The selected config module and required reactor dependencies compiled. |
mvn -pl account-service -am test | 14 tests ran: five passed and nine errored | Some service logic passed; embedded MongoDB initialization blocked the other tests. |
These are historical results, not commands expected to reproduce those failures on the modernized checkout. The nine errors traced through Failed to load ApplicationContext to an embedded MongoDB download returning HTTP 403. The pinned binary also targeted i386, which would not run on the Apple Silicon host.
The probes did not establish that the whole application ran or that its integration behavior was correct. They did give me a narrower next step: replace the test dependency and rerun the affected tests before changing the production stack.
That result saved me from making a very tidy, very expensive mistake. I had already started thinking about which parts of the architecture I might replace. One broken test dependency did not justify redesigning the application, and five passing tests established behavior I could check for unintended changes during modernization.
The modernization plan turned that evidence into a capture-then-upgrade sequence:
- Replace the embedded database dependency with Testcontainers and establish a green baseline on the existing stack.
- Put that baseline in GitHub Actions before changing the production runtime.
- Move from Java 8 to Java 21 and Spring Boot 3.3.
- Replace obsolete components behind their existing interfaces: Zuul with Spring Cloud Gateway, Hystrix with Resilience4j, and the retired OAuth stack with Spring Authorization Server and JSON Web Token (JWT) resource servers.
- Carry the baseline forward and add contract checks around the parts whose behavior changed.
The first acceptance gate was a passing baseline on the old stack, not merely the successful installation of a replacement dependency. Running checks in CI and enforcing them as merge requirements were also separate steps in the plan.
The result summary records the Java and Spring upgrades while retaining the microservice decomposition that the application exists to demonstrate. Eureka and Cloud Config stayed; the two monitoring modules used by the retired Hystrix and Turbine stack were removed. The in-scope build went from nine modules to seven.
Those versions describe the experiment, not a recommendation to select the same versions today. Choose targets against your current support requirements. The useful lesson is how the repository evidence narrowed the change.
The method changes with the system
The same process produced different answers on two smaller applications. Their pinned reports describe these choices:
| Application | What stayed | What changed | Strategy |
|---|---|---|---|
| BrowserQuest | Canvas renderer, pathfinding, world model, protocol, and game-loop model | Node 0.4.7 to Node 22, two obsolete WebSocket stacks to ws, plus tests and GitHub Actions | Upgrade and swap |
| DOOM | Renderer, 35 Hz simulation model, and WAD game-data format | X11 video and OSS audio replaced with SDL2; platform code adapted for modern 64-bit systems | Preserve the core and replace the platform |
The comparison needs one important qualification: DOOM’s checks froze outputs from the modernized engine itself. They protected against later regressions; they did not independently prove parity with a period-correct legacy binary. Naming that limit is part of choosing an honest safety level.
Scaling the method without pretending the product is finished
I then applied the method to ADempiere, a large Java suite covering ERP, customer relationship management, manufacturing, supply chain, accounting, and point of sale.
The scale changed the controls, but not the method. The work established a reproducible build, moved the runtime to JDK 21, preserved SOAP web-service contracts while replacing XFire with CXF and Jakarta, captured legacy web behavior, and introduced a modern web path for selected users. The first modern business partner write was compared with a result frozen from the legacy application.
The fixed measurement report covers 30 merged modernization pull requests and 102,587.72 reconstructed Copilot credits through the first accepted portable demo. The credit total is not a dollar cost. More important, the report says exactly what the result was not: it was not a claim that every ADempiere screen or production deployment had been modernized.
I stopped because the proof-of-concept question had been answered. The result demonstrated a build on the selected runtime, old and new paths running together, and a real business write checked against the legacy result. Completing the rest would have required a product funding decision, not another technical proof. Stopping at that boundary was part of the method.
Turn the method into an agent skill
After repeating this work, I didn’t want the evidence checklist and decision rules to live only in my notes. I encoded them in the public doc-and-modernize agent skill.
Agent skills are folders of instructions, scripts, and resources that Copilot can load when a task is relevant. A project skill can live with one repository:
.github/skills/doc-and-modernize/
├── SKILL.md
├── references/
└── scripts/
Only SKILL.md is required; the resource folders shown here are optional. The file needs YAML frontmatter with a name and a description explaining what the skill does and when to use it, followed by the instructions. The creation guide includes the full format.
Paraphrased from the commit-pinned skill source, its decision fork is:
- If the old component can run at an acceptable cost, capture its behavior before upgrading.
- If it cannot run without changes, build and verify a small modern slice first, then expand it.
The full skill adds the feasibility check, testability milestone, safety levels, phase gates, and evidence requirements.
The useful distinction is procedure versus policy. A shared skill can require repository evidence, bounded experiments, explicit safety levels, and runnable exit criteria. Your organization still needs to supply the parts only it knows:
- Approved runtimes, frameworks, and hosting services
- Application criticality and acceptable residual risk
- Security, compliance, and change-control requirements
- Which legacy or production results may be used as the expected answer
- Who can approve the architecture and declare a production change complete
The skill should make those decisions visible. It shouldn’t make them for you.
Start with one bounded application
Choose an application with an identified owner, known business value, and one workflow you can observe. Run the documentation workflow first. Review the architecture, commands, runtime surfaces, and unknowns with the people who own the system.
Then approve one experiment, not a portfolio rewrite.
Inspect the skill and its supporting files before adding it to a project. GitHub CLI’s gh skill commands are in public preview; check the current installation guidance when you’re ready to use them.
The post How to choose the next safe step in application modernization appeared first on The GitHub Blog.
正文保留英文原文,标题与摘要由机器翻译。
原文发布于 GitHub Blog(How to choose the next safe step in application modernization),标题、摘要与正文由机器翻译,术语按行业惯例统一,未经人工逐句校订。