[英]Elixir Mix release - How can I copy extra files into the tarball of Phoenix app?
I wrote the following mix.exs to release my Phoenix application as a tar ball, referring to the “Steps” section of the Mix.Tasks.Release documentation .我编写了以下 mix.exs 以将我的 Phoenix 应用程序作为 tar 球发布,参考 Mix.Tasks.Release文档的“步骤”部分。
defmodule MyApp.MixProject do
use Mix.Project
def project do
[
apps_path: "apps",
apps: [:shared, :admin, :shop],
version: "0.1.0",
start_permanent: Mix.env() in [:qa, :prod],
deps: deps(),
releases: [
my_app: [
applications: [
admin: :permanent,
shop: :permanent
],
steps: [:assemble, ©_extra_files/1, :tar]
]
],
default_release: :my_app
]
end
defp copy_extra_files(release) do
File.cp_r("apps/shared/priv/repo/seeds", release.path <> "/seeds")
release
end
defp deps do
[]
end
end
When I run MIX_ENV=qa mix release my_app
, it created a seeds
directory under _build/qa/rel/my_app
, but when I extract the generated tar ball, it does not contain the seeds
directory.当我运行
MIX_ENV=qa mix release my_app
时,它在_build/qa/rel/my_app
下创建了一个seeds
目录,但是当我提取生成的 tar 球时,它不包含seeds
目录。
How can I rewrite the mix.exs
in order to insert this directory into the tar ball?如何重写
mix.exs
以便将此目录插入到 tar 球中?
Elixir version is 1.11.3. Elixir 版本为 1.11.3。
Note: The same question has been posted on the Elixir Forum.注意: 同样的问题已经发布在 Elixir 论坛上。
You don't have to copy anything manually since elixir does this for you automatically, if you take a look in your my_app/lib/my_app-0.1.0/priv
, there you have all the files you had in your priv folder.您不必手动复制任何内容,因为 elixir 会自动为您执行此操作,如果您查看
my_app/lib/my_app-0.1.0/priv
,您的 priv 文件夹中就有所有文件。
Now in order to access those resources painless without hardcoding the path you can use priv_dir\1
:现在,为了在不硬编码路径的情况下轻松访问这些资源,您可以使用
priv_dir\1
:
:code.priv_dir(:my_app)
This is applicable not only for your application, for example if you want your phoenix static resources, you can find them in phoenix priv folder.这不仅适用于您的应用程序,例如,如果您想要 phoenix static 资源,您可以在 phoenix priv 文件夹中找到它们。
Looking at the source for mix.release
, it appears to only select from specific directories when compiling the release.查看
mix.release
的源代码,编译版本时似乎只有特定目录中的 select 。
If you copy seeds
into #{release.path}/releases/#{release.version}
, it will be included.如果您将
seeds
复制到#{release.path}/releases/#{release.version}
,它将被包含在内。
defp copy_extra_files(release) do
File.cp_r(
"apps/shared/priv/repo/seeds",
"#{release.path}/releases/#{release.version}/seeds"
)
release
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.