在 Heroku 上部署期间克隆存储库
Clone a repository during deployment on Heroku
我有一个 Rails 项目 PROJECTX,托管在 Heroku 上。为了存储生产配置和文件,我使用了不同的存储库 PROJECTX-config。是否可以:
- 克隆 PROJECTX-config,
- 删除当前配置文件,并且
- 符号链接配置文件到 PROJECTX-config 文件
请注意,这必须在 Heroku 上完成。我也知道 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
或者至少在没有像 setupe 这样的 Rube Goldberg 机器的情况下,你可以在其中设置某种自动化(如 post-commit 挂钩)来合并 repo A 和 repo B,并将结果推送到 heroku。
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 密钥等秘密。
其他非机密配置,例如您对各种 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。
我有一个 Rails 项目 PROJECTX,托管在 Heroku 上。为了存储生产配置和文件,我使用了不同的存储库 PROJECTX-config。是否可以:
- 克隆 PROJECTX-config,
- 删除当前配置文件,并且
- 符号链接配置文件到 PROJECTX-config 文件
请注意,这必须在 Heroku 上完成。我也知道 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
或者至少在没有像 setupe 这样的 Rube Goldberg 机器的情况下,你可以在其中设置某种自动化(如 post-commit 挂钩)来合并 repo A 和 repo B,并将结果推送到 heroku。
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 密钥等秘密。
其他非机密配置,例如您对各种 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。