我有一个 Rails 项目 PROJECTX,它托管在 Heroku 上。为了存储生产配置和文件,我使用不同的存储库PROJECTX-config。是否可以:
- 克隆 PROJECTX-config,
- 删除当前配置文件,并且
- 将配置文件符号链接(symbolic link)到 PROJECTX 配置文件
请注意,这必须在 Heroku 上完成。我还知道 Heroku 可以选择使用环境变量来维护配置,但这不是我想要的。
谢谢!
最佳答案
不,这是不可能的。
或者至少没有像 setupe 这样的 Rube Goldberg 机器,您可以在其中设置某种自动化(如提交后 Hook )来合并存储库 A 和存储库 B 并将结果推送到 heroku。Each dyno gets its own ephemeral filesystem, with a fresh copy of the most recently deployed code. During the dyno’s lifetime its running processes can use the filesystem as a temporary scratchpad, but no files that are written are visible to processes in any other dyno and any files written will be discarded the moment the dyno is stopped or restarted. For example, this occurs any time a dyno is replaced due to application deployment and approximately once a day as part of normal dyno management.
- https://devcenter.heroku.com/articles/dynos#ephemeral-filesystem
Also I believe that app config should not be present in environment variables, as it is tedious to maintain rather than maintaining a file.
Heroku 对此并不同意。
The traditional approach for handling such config vars is to put them under source - in a properties file of some sort. This is an error-prone process, and is especially complicated for open source apps which often have to maintain separate (and private) branches with app-specific configurations.
A better solution is to use environment variables, and keep the keys out of the code. On a traditional host or working locally you can set environment vars in your bashrc file. On Heroku, you use config vars. - https://devcenter.heroku.com/articles/config-vars
尽管您可能高估了 ENV 变量中实际需要存储的内容。您只需在 ENV 中存储 API key 等 secret 即可。
其他非 secret 配置,例如各种 gem 的设置,可以而且应该在 config/initializers
中设置。
如果您仍然认为使用 GUI 很糟糕,那么请使用您解析并用于设置 ENV 变量的 YAML 文件:
require 'yaml'
yaml = YAML.load_file(File.join(__dir__, 'conf.yml'))
def create_key(*components)
components.join('_').upcase
end
env_vars = yaml["production"].each_with_object({}) do |(key,value), memo|
key_components = [key]
if value.kind_of? Hash
value.each_pair do |k,v|
memo[create_key(*key_components.dup.push(k))] = v
end
else
memo[create_key(*key_components)] = value
end
end.each do |k,v|
system("heroku config:set #{k}=#{v}")
puts "Setting #{k} = #{v}; #{ $? }"
end
或者您甚至可以将序列化表单(JSON 或 YAML)存储在单个环境变量中 - 但总大小限制为 32kb。
关于ruby-on-rails - 在 Heroku 上部署期间克隆存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46143128/