如何选择应用现代化过程中的下一步安全操作
学习如何评估遗留应用程序,选择边界明确的现代化步骤,并使用 GitHub Copilot 代理技能复用该方法。
应用现代化的请求通常始于一个技术问题:哪个框架应替代旧框架?在做出选择之前,先了解现有哪些部分仍能正常运行。随后收集可用作回归防护网的证据,并明确必须进行现代化的位置。
我在四个公开应用程序上使用了以证据为先的方法,从小型 Node.js 游戏到大型 Java 企业资源规划(ERP)应用程序。每个应用程序所需的处理方式各不相同,但我收集证据、选择下一个实验以及确定可行证明点的方式是可复用的。
本文详细阐述该流程,以便您将其应用于自己的某个应用程序。同时展示如何将此过程编码至 GitHub Copilot 代理技能中,同时将架构决策权保留给负责该系统的人员。
构建证据后再选定目标
应用程序上的标签往往信息不足。“Java 微服务”无法说明生产环境中运行的是哪个 Java 开发工具包(JDK)、该版本是否在何处固定、测试是否可执行,或其他系统依赖哪些接口。“遗留单体”也无法说明业务核心是否存在缺陷,或是否因某项已退役的平台依赖导致应用程序无法启动。
在推荐变更前,先建立一份小型证据清单:
- 清单文件、锁定文件、入口点和可部署组件
- 经验证的安装、构建、测试、打包和运行命令
- 容器、CI 工作流、部署文件和开发者工具中的运行时版本固化
- 外部契约,例如 API、数据库行为、文件格式和用户工作流
- 终止生命周期的框架和依赖项,并附有应用仍在使用它们的证据
工作时请记录不确定性。我使用三种简单标签:已记录、推断得出的和未验证的。如果两份文件对 Java 版本存在分歧,请解决该矛盾。如果你无法确定某个 CI 检查是否会阻止合并,请如实说明。记录未知项,而不要把猜测当作发现。
这份清单让你能在提出任何变更之前,与应用程序的所有者一起审查具体内容。
选择最小侵入性但有效的处理方式
了解应用之后,按组件逐项决策。一个系统中可能包含应保留的代码、应替换的依赖项,以及确实需要重写的一个子系统。
首先检查某项能力是否仍有必要。仅在确认其未被使用或已被取代,并与所有者确认后,才移除它。移除本身是一个独立决策,且未必是最具侵入性的做法。
对于仍需保留的能力,从变动最小的方案开始:
- 保留。支持良好且仍能胜任工作的代码,不需要所谓的现代化叙事。
- 升级。迁移到受支持的次版本,并修复破坏性变更。
- 替换。在保持现有设计的前提下替换已废弃的依赖项。
- 封装。稳定一个有用的接口,并逐步替换内部实现。
- 重写。当不存在负责任的升级路径,或架构无法满足要求时使用此方案。
这是一份决策顺序指南,而非对所有工作量或风险的全局排序。请问:有哪些证据能支撑你选择更具侵入性的方案?"代码老旧"本身不够充分。只有当出现以下情况之一时,升级才是合理的:已知的安全漏洞在锁定版本中尚无补丁发行、某个依赖项在你所需的运行环境中无法正常运作,或者当前设计无法达到已衡量的可靠性目标。
明确可以验证的内容
下一步需要判断:即使旧的 CI 管道状态不是绿色(正常),该组件是否仍能运行得足够好,从而产出可供参考的证据。
进行一个限定时间的可行性检查。尝试安装依赖项,在有条件的工具链上完成构建,启动组件,并至少执行一次有实际意义的测试。时间一到立即停止。根据结果,你会被引导到以下两条路径中的一条。
先记录行为,再升级。当旧应用仍能以可接受的成本运行时采用这条路径。记录其对外可见的行为,尽可能修复测试套件,并用这些用例来验证升级后的版本。
先构建一个精简的现代版切片。当旧组件无法运行、必须先修改才能使其运转时才采用这条路径。将最薄且有价值的业务流程迁移到受支持的技术栈上,验证它,然后在此基础上逐步扩展。在这种情境下要求先完整恢复遗留测试套件是循环论证。测试套件的恢复本身就是现代化工作的一部分。
我使用以下安全性级别(改编自 doc-and-modernize skill),来描述当前可获得的最强回归防护等级:
明确说明你能证实什么、还有哪些风险仍然存在。即便达到 L4 级别,也无法保证所有可能的行为都是正确的。API、数据库影响、文件、渲染输出和业务工作流通常可以作为可靠的对比参照,因为这些行为可以在框架或语言变更后依然保持不变。
PiggyMetrics:先捕获行为,再升级
PiggyMetrics 是最典型的一个案例——一个看起来比实际更糟的应用程序。该项目使用了 Java 8、Spring Boot 2.0.3、Spring Cloud Finchley、Zuul、Hystrix 以及旧的 spring-security-oauth2 库。
很容易直接断定这个应用程序无法使用,然后开始设计新的架构。但可行性验证给出了不同的结论。
针对带有 JDK 8 的旧代码仓库进行的这两项探测,得到的历史可行性结果如下:
这些是历史记录,并非预期能在现代化代码仓库中复现那些故障的命令。通过九处错误追溯到 `Failed to load ApplicationContext`,直至嵌入式 MongoDB 下载返回 HTTP 403。固定的二进制文件还针对 i386,无法在 Apple Silicon 主机上运行。
这些探测并未证明整个应用程序可以正常运行或其集成行为是正确的。但它们提供了一个范围更小的下一步行动:在修改生产栈之前,替换测试依赖并重跑受影响的测试。
这一结果让我避免了一个非常整齐却代价高昂的错误。我原本已经在考虑要替换架构中的哪些部分。一个断裂的测试依赖并不足以证明重构整个应用程序是合理的,而五个通过的测试则建立了可以在现代化过程中检查是否有意外变更的行为基线。
现代化计划将这些证据转化为"先捕获,再升级"的步骤序列:
- 用 Testcontainers 替换嵌入式数据库依赖,并在现有栈上建立绿色基线。
- 在修改生产运行时之前,将该基线提交到 GitHub Actions。
- 从 Java 8 迁移至 Java 21 和 Spring Boot 3.3。
- 在其现有接口后替换过时组件:用 Spring Cloud Gateway 替换 Zuul,用 Resilience4j 替换 Hystrix,用 Spring Authorization Server 和 JSON Web Token (JWT) 资源服务器替换已停用的 OAuth 栈。
- 将基线带入后续阶段,并在行为发生变化部分的周围添加契约检查。
第一个验收关卡是在旧栈上通过基线,而非仅仅成功安装了替换依赖项。在 CI 中运行检查并将其作为合并要求强制执行也是计划中的独立步骤。
结果摘要记录了 Java 和 Spring 的升级,同时保留了该应用程序用于展示的 microservice 分解结构。Eureka 和 Cloud Config 保持不变;被已停用 Hystrix 和 Turbine 栈使用的两个监控模块被移除。纳入范围的构建从九个模块减少到七个。
这些版本描述的是实验过程,而不是建议今天选用相同的版本。根据你的当前支持需求来选择目标版本。其中有用的经验是:如何通过仓库证据来缩小变更范围。
方法随系统而变化
同一流程在两个较小的应用程序上得到了不同的答案。它们的锁定报告描述了这些选择:
该对比有一个重要的限定条件:DOOM 的检查冻结了来自现代化引擎本身的输出。它们防范了后续的回退问题;并未独立证明与现代期兼容的传统二进制的等效性。明确这一限制是选择诚实的安全水平的一部分。
扩展该方法而不假装产品已经完成
随后我将该方法应用于 ADempiere,这是一套覆盖企业资源计划、客户关系管理、制造、供应链、会计和零售的大规模 Java 套件。
规模变了,控制手段也随之调整,但方法并未改变。这项工作建立了可复现的构建流程,将运行时迁移至JDK 21,在保留SOAP Web服务契约的同时用CXF和Jakarta替换了XFire,捕获了传统Web行为,并为选定用户引入了现代化Web路径。首次现代业务流程写入与从传统应用程序中冻结的结果进行了比对。
该固定度量报告涵盖30个已合并的现代化PR和102,587.72个Copilot credits,以上均通过首个验收通过的便携演示所重建。credit总数并非美元成本。更重要的是,报告明确说明了结果**不是**什么:它并不是声称ADempiere的每一个界面或生产部署都已完成现代化改造。
我选择在此止步,因为概念验证问题已经有了答案。成果证明了在选定运行时上的构建、新旧路径并存运行,以及一笔真实业务写入与传统结果的比对。完成剩余工作将需要产品层面的资金投入决策,而非另一次技术验证。在该边界处停止本身就是该方法的一部分。
将方法转化为agent技能
重复过这项工作后,我不想让证据检查清单和决策规则只停留在我的笔记里。我将它们编码进了公开的doc-and-modernize agent技能中。
Agent技能是包含指令、脚本和资源的文件夹,当任务相关时,Copilot可以加载它们。项目级技能可以与单一仓库共存:
.github/skills/doc-and-modernize/
├── SKILL.md
├── references/
└── scripts/
只需提供SKILL.md;此处显示的资源文件夹是可选的。该文件需要包含YAML前置元数据,其中应注明名称及描述该技能功能与适用场景的说明,其后为具体指令。创建指南包含了完整格式。
基于commit-pinned技能源改写,其决策路径为:
- 若旧组件能以可接受的成本运行,则在升级前先捕获其行为。
- 若不经修改无法运行,则先构建并验证一小段现代化切片,再逐步扩展。
完整的技能还增加了可行性检查、可测试性里程碑、安全级别、阶段关口及证据要求。
实用的区分在于程序与策略。共享技能可以要求提供仓库证据、有界实验、明确的安全级别以及可运行的退出标准。您的组织仍需自行补充仅其掌握的要素:
- 批准运行的运行时环境、框架和托管服务
- 应用程序关键性及可接受的剩余风险
- 安全、合规和变更控制要求
- 哪些遗留或生产环境结果可作为预期答案
- 谁有权审批架构并宣布生产变更完成
该技能应使这些决策显性化,而非代替您做出决定。
从单个有界应用开始
选择具有明确负责人、已知业务价值且您可观察单一工作流的应用。先运行文档工作流。与系统所有者共同审查架构、命令、运行时影响面及未知项。
然后批准一项实验,而非对整套组合进行重写。
在向项目添加之前,请检视该技能及其支持文件。GitHub CLI的gh skill命令目前处于公开预览阶段;准备使用时请查看当前的安装指南。
标签:
作者:Rel
本文由 AI图鉴自动抓取并翻译,版权归原作者所有;如需查看原文请点下方链接。
How to choose the next safe step in application modernization
Learn how to assess a legacy application, choose a bounded modernization step, and reuse the method with a GitHub Copilot agent skill.
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:
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:
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:
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.
Tags:
Written by
Rel
Auto-fetched and translated by AI Atlas. All rights belong to the original author.