2.5. 使用 Dekorate 自动执行 OpenShift Source-to-Image 构建


在使用 Maven 编译应用程序后,您可以使用 Dekorate 自动执行 OpenShift 容器镜像构建。

请注意,使用 Dekorate 自动触发 Source-to-image 构建的 功能作为技术预览提供。红帽不支持在生产环境中使用此功能。

先决条件

  • 基于 Maven 的应用程序项目配置为使用 Spring BootDekorate
  • 添加至您项目中的源文件的 @SpringBootApplication 注解
  • 安装了 Java JDK 8 或 JDK 11
  • 已安装 Maven
  • 已安装 oc 命令行工具
  • 使用 oc 命令行工具登录到 OpenShift 集群

流程

  1. 将 Dekorate OpenShift Spring Starter 作为依赖项添加到应用程序的 pom.xml 文件中。请注意,此模块作为传输依赖项包含在所有 Dekorate OpenShift Starters 中:

    <project>
      ...
      <dependencies>
         ...
        <dependency>
          <groupId>io.dekorate</groupId>
          <artifactId>openshift-spring-starter</artifactId>
        </dependency>
        ...
      </dependencies>
    ...
    <project>
  2. 构建并部署您的应用。包含 -Ddekorate.build=true 属性,用于在 Maven 编译应用程序后执行容器镜像构建。请注意,自动执行 Source-to-image 构建的 功能作为技术预览提供

    $ mvn clean install -Ddekorate.build=true

    在使用 Maven 编译应用程序后,您还可以从命令行手动执行 Source-to-image 构建:

    # Process your application YAML template that is generated by Dekorate:
    $ oc apply -f target/classes/META-INF/dekorate/openshift.yml
    # Execute the Source-to-image build and deploy your application to the OpenShift cluster:
    $ oc start-build example --from-dir=./target --follow
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部