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 .
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.
How can I rewrite the mix.exs
in order to insert this directory into the tar ball?
Elixir version is 1.11.3.
Note: The same question has been posted on the Elixir Forum.
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.
Now in order to access those resources painless without hardcoding the path you can use 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.
Looking at the source for mix.release
, it appears to only select from specific directories when compiling the release.
If you copy seeds
into #{release.path}/releases/#{release.version}
, it will be included.
defp copy_extra_files(release) do
File.cp_r(
"apps/shared/priv/repo/seeds",
"#{release.path}/releases/#{release.version}/seeds"
)
release
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.