为伞式项目选择发布配置
Choosing releases config for umbrella project
我有 3 个总括项目:
- 业务逻辑;
- 休息API;
- 网页。
我在 root mix.exs
中有以下配置:
releases: [
web: [
applications: [web_project: :permanent]
],
api: [
applications: [rest_api_project: :permanent]
]
]
问题是每次我 运行 mix release release_name
运行 时间配置都是从根项目加载的,而不是从指定的项目加载的。
我什至尝试通过以下方式加载其他配置:
for config <- "../apps/*/config/releases.exs" |> Path.expand(__DIR__) |> Path.wildcard() do
import_config config
end
然而它似乎不起作用,它正在使用编译时配置。
找到相似的后issue opened, the proposed solution by José Valim is to use overlays. The only problem currently with overlays is that you can only point at a specific folder, opposite to the flexibility you have with Disitllery Overlays。
最终解决方案如下:
releases: [
web: [
applications: [my_app: :permanent],
config_providers: [{Config.Reader, {:system, "RELEASE_ROOT", "/releases.exs"}}],
overlays: "apps/my_app/config"
]
]
我选择了不同的路径,因为叠加层没有为使用 steps
提供任何灵活性:
web: [
applications: [my_app: :permanent],
config_providers: [
{Config.Reader, {:system, "RELEASE_ROOT", "apps/my_app/config/releases.exs"}},
{Config.Reader, {:system, "RELEASE_ROOT", "apps/another_app/config/releases.exs"}},
],
steps: [:assemble, ©_configs/1]
]
这样我可以提取 path
和 config_providers
并将它们移动到发布文件夹:
defp copy_configs(%{path: path, config_providers: config_providers} = release) do
for {_module, {_context, _root, file_path}} <- config_providers do
# Creating new path
new_path = path <> Path.dirname(file_path)
# Removing possible leftover files from previous builds
File.rm_rf!(new_path)
# Creating directory if it doesn't exist
File.mkdir_p!(new_path)
# Copying files to the directory with the same name
File.cp!(Path.expand(file_path), new_path <> "/" <> Path.basename(file_path))
end
release
end
我有 3 个总括项目:
- 业务逻辑;
- 休息API;
- 网页。
我在 root mix.exs
中有以下配置:
releases: [
web: [
applications: [web_project: :permanent]
],
api: [
applications: [rest_api_project: :permanent]
]
]
问题是每次我 运行 mix release release_name
运行 时间配置都是从根项目加载的,而不是从指定的项目加载的。
我什至尝试通过以下方式加载其他配置:
for config <- "../apps/*/config/releases.exs" |> Path.expand(__DIR__) |> Path.wildcard() do
import_config config
end
然而它似乎不起作用,它正在使用编译时配置。
找到相似的后issue opened, the proposed solution by José Valim is to use overlays. The only problem currently with overlays is that you can only point at a specific folder, opposite to the flexibility you have with Disitllery Overlays。
最终解决方案如下:
releases: [
web: [
applications: [my_app: :permanent],
config_providers: [{Config.Reader, {:system, "RELEASE_ROOT", "/releases.exs"}}],
overlays: "apps/my_app/config"
]
]
我选择了不同的路径,因为叠加层没有为使用 steps
提供任何灵活性:
web: [
applications: [my_app: :permanent],
config_providers: [
{Config.Reader, {:system, "RELEASE_ROOT", "apps/my_app/config/releases.exs"}},
{Config.Reader, {:system, "RELEASE_ROOT", "apps/another_app/config/releases.exs"}},
],
steps: [:assemble, ©_configs/1]
]
这样我可以提取 path
和 config_providers
并将它们移动到发布文件夹:
defp copy_configs(%{path: path, config_providers: config_providers} = release) do
for {_module, {_context, _root, file_path}} <- config_providers do
# Creating new path
new_path = path <> Path.dirname(file_path)
# Removing possible leftover files from previous builds
File.rm_rf!(new_path)
# Creating directory if it doesn't exist
File.mkdir_p!(new_path)
# Copying files to the directory with the same name
File.cp!(Path.expand(file_path), new_path <> "/" <> Path.basename(file_path))
end
release
end