如何在 Openshift v3 应用程序的非空目录中添加配置文件

How to add a config file in a non-empty directory of an Openshift v3 application

我在新的 Openshift v3 上部署了一个 PHP+postgreqsl 应用程序(TinyTiny RSS,https://github.com/dittos/ttrss-mirror)。在初始访问时,您从可用模板创建一个 config.php,其中包含数据库密码等,以启用 tt-rss 连接到数据库。现在我需要将该文件添加到 tt-rss 期望的应用程序根目录 (/opt/app-root/src/)。

按照明显规范的方式,我创建了一个 configmap,键 config.php 和文件内容作为值。但是,当将该配置文件挂载到 volume 以使其可供应用程序使用时,我 运行 遇到了问题,因为显然 mountpoint[=卷的 47=] 是一个不存在的目录,所以当我给出 /opt/app-root/src/ 的目标路径时,我的应用程序代码被覆盖了。

然后,我发现 a way 在已填充的目录中提供单个文件

you need to supply the absolute path including the filename in the mountPath and the filename again in subPath. The filename (obviously) needs to match the key in your config map.

我这样做了,但这会导致无法访问(无权限)config.php 具有非常 st运行ge 属性的文件,请参阅已部署 pod 中 ls -la 的摘录:

drwxrwxr-x.  8 default root  4096 Sep 29 13:41 classes                                                                                                                                               
-??????????  ? ?       ?        ?            ? config.php                                                                                                                                            
-rw-rw-r--.  1 default root  8057 Sep 29 13:41 config.php-dist

config.php-dist 是模板。问号怎么了??此功能不适用于 Openshift 吗?

相关的 YAML 部分如下所示:

  volumeMounts:
    - mountPath: /opt/app-root/src/config.php
      name: volume-2k03m
      subPath: config.php

  volumes:
    - configMap:
        defaultMode: 420
        items:
          - key: config.php
            path: config.php
        name: tt-rss-config
      name: volume-2k03m

有没有办法修复这个配置?有没有另一种方法 "inject" (需要一个更好的词) config.php 进入应用程序?

有些人推荐符号链接,但我不知道如何在需要的位置以编程方式创建符号链接而不 运行 会遇到与 config.php 本身相同的问题。

我不想将它推送到 (public) 源代码库,因为它包含秘密,而且源代码库实际上是一个上游代码库,我不想分叉它并继续保持更新-和我自己约会。

不熟悉 tt-rss,我这样做的方法是预先创建 config.php 文件并将其包含在您的源代码中。您可以在 config.php 中为任何可能更改的值使用环境变量。

然后不清楚你是否必须将 config.php 文件移出你的 repo 目录,但是在容器已经 运行 之后你需要做的任何事情都是完美的.s2i/bin scripts. Here's a sample run script, use it exactly as it is, and then just add anything else you need, like moving files, or changing permissions (note: you can't change anything that requires root permissions). Finally, any additional configuration of PHP cam be done via environment variables defined in the PHP S2I documentation.

的用例

显然,这是一个当前错误,请参阅 https://github.com/openshift/origin/issues/15750 and https://bugzilla.redhat.com/show_bug.cgi?id=1481617#c1

作为解决方法,像这样指定 subPathsubPath: ..data/config.php,然后一切都会按预期开始工作。