小编Gab*_*ira的帖子

Fabric8 docker-maven-plugin:在构建中包含附加标签

我在 pom.xml 中配置了 Fabric8 docker-maven-plugin,如下所示:

  <build>
    ...
    <plugins>
      ...
      <plugin>
        <groupId>io.fabric8</groupId>
        <artifactId>docker-maven-plugin</artifactId>
        <version>${docker.plugin.version}</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>build</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <images>
            <image>
              <name>${docker.image.prefix}/${project.artifactId}:%l</name>
              <build>
                <dockerFile>Dockerfile</dockerFile>
                <assembly>
                  <descriptorRef>artifact</descriptorRef>
                </assembly>
              </build>
            </image>
          </images>
        </configuration>
      </plugin>
      ...
    </plugins>
    ...
  </build>
Run Code Online (Sandbox Code Playgroud)

我使用占位符,如果版本包含 ,则用标签%l标记图像,否则使用 pom 版本。当从 CI 构建时,我想在我的图像中包含一些额外的标签(可能不止一个)(例如构建号/分支名称),但我想保留占位符行为。我认为应该可以从命令行使用 Maven 属性,但我无法从插件文档中找出它(https://dmp.fabric8.io/latest-SNAPSHOT%l

在执行 docker:build 目标时如何包含附加标签?

maven docker docker-maven-plugin

2
推荐指数
1
解决办法
2981
查看次数

Rails:仅当路线存在时才链接到

我正在编写一个 Rails 引擎,在我的一个视图中,如果存在命名路由,我想创建一个指向 main_app 的链接。

我将举一个例子来澄清这个问题:主应用程序可能会也可能不会在routes.rb中定义:

resources :my_resource, only: :index
Run Code Online (Sandbox Code Playgroud)

在我的 Rails 引擎中,仅当 main_app 定义了该路由时,我才需要添加指向 my_resource_path 的链接。我认为应该是这样的:

<%= link_to "Link", main_app.my_path if my_resource_path_exists? %>
Run Code Online (Sandbox Code Playgroud)

我试过:

<%= link_to "Link", main_app.my_resource_path if 
      main_app.respond_to?(:my_resource_path) %>
Run Code Online (Sandbox Code Playgroud)

但是,当路径不存在时,会引发 NoMethodError:

undefined method `my_resource_path' for #<Module>
Run Code Online (Sandbox Code Playgroud)

my_resource_path_如何存在?方法可以实现吗?我正在使用 ruby​​ 2.2 和 Rails 4.2

问题与:确定路径是否作为 Rails 控制器中的路由存在 但在这种情况下,我有一个命名路由(my_resource_path),所以我需要稍微不同的东西,但我自己无法弄清楚。

ruby-on-rails

1
推荐指数
1
解决办法
2786
查看次数