sashaafm

sashaafm

I’m trying to build a release of a project I’m working on which has several CSV, JSON and ETS files. There files are used at runtime to import ETS tables and at compile-time to dynamically generate certain modules. However, Distillery does not seem to include them in the release.

At the beginning I had them in a directory inside the Elixir project (alongside lib). I also tried moving the files inside the lib dir (and changing the config accordingly) but the results were the same.

I’ve been reading the docs but don’t find anything about this. There’s the following reference:

  • code_paths (list of strings);
    a list of additional code paths to use when searching
    for applications/modules

but it does not seem to be related to extra needed files.

Showing Posts 1 to 10

michalmuskala

michalmuskala

The traditional place to put non-code resources that are needed at runtime is the priv folder. All the tools are aware of this convention and preserve proper paths.

You can access the files at runtime using Application.app_dir(app_name, "priv/path/to/file")

11
Post #1
sashaafm

sashaafm OP

Thank you @michalmuskala. I’m going to try this and report back!

EDIT: Michal’s answer does work. Marking it as the solution.

bitwalker

bitwalker

Leader

You can use :code.priv_dir(app) to get the priv directory directly as well, it’s what I typically use in my applications.

chensan

chensan

How can I access the priv path in dev.exs file? When I do it as below:

"#{Application.app_dir(:app)}/priv/ssl/ca.pem"

I got:

** (Mix.Config.LoadError) could not load config config/dev.exs
    ** (ArgumentError) unknown application: :app
    (elixir) lib/application.ex:428: Application.app_dir/1
    (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
    (stdlib) erl_eval.erl:269: :erl_eval.expr/5
    (stdlib) eval_bits.erl:81: :eval_bits.eval_field/3
    (stdlib) eval_bits.erl:65: :eval_bits.expr_grp/4
    (stdlib) erl_eval.erl:474: :erl_eval.expr/5
    (stdlib) erl_eval.erl:878: :erl_eval.expr_list/6
    (stdlib) erl_eval.erl:236: :erl_eval.expr/5

I’m setting ssl_opts for Ecto, putting those pem files under priv/ssl, but the application can’t access them after building with Distillery.

Qqwy

Qqwy

TypeCheck Core Team

Quick question about this: Does this directory stay the same for all releases, or will each new version have its own priv_dir?

OvermindDL1

OvermindDL1

As long as you install each release into the same directory then the priv directory ‘should’ always remain the same (unless using a custom OTP build or so).

bitwalker

bitwalker

Leader

New versions of your application will have a slightly different path (as the path includes the version of your app in a release), but the same version will always be the same path, regardless of OTP version, Elixir version, etc.

Qqwy

Qqwy

TypeCheck Core Team

Thank you. This has tripped me off before. I stored some general app-state-information in a file (because the database would be ridiculously overkill for this), but it turned out that the file was not found after upgrading my release, with the app thus restarting with a blank slate every time after an upgrade.

bitwalker

bitwalker

Leader

Yeah my general advice along these lines is to use priv for anything version-specific and/or static data/assets and to rely on something more well-known of your own creation in the filesystem for stateful data, i.e. /var/myapp/. You could also use the var directory created by the release, which you can obtain via the RELEASE_MUTABLE_DIR environment variable exposed to the release (which is used for temporary files like pipes, generated configs, and log files). That said, I would still tend towards using a directory like /var/myapp myself, since you can avoid clutter and manage it’s permissions and so on separately.

acrogenesis

acrogenesis

I’m having the same problem as @chensan I’m trying to set some ssl_opts in a config file and it says:

** (ArgumentError) unknown application: :app
    (elixir) lib/application.ex:654: Application.app_dir/1
    (elixir) lib/application.ex:681: Application.app_dir/2
    (stdlib) erl_eval.erl:680: :erl_eval.do_apply/6
    (stdlib) erl_eval.erl:888: :erl_eval.expr_list/6
    (stdlib) erl_eval.erl:240: :erl_eval.expr/5
    (stdlib) erl_eval.erl:232: :erl_eval.expr/5
    (stdlib) erl_eval.erl:888: :erl_eval.expr_list/6
    (stdlib) erl_eval.erl:240: :erl_eval.expr/5

The app is named :app in mix.exs

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
psy-q
I’m trying to set up Emacs with elixir-ls via lsp-mode and credo via Flycheck. This should mostly be preconfigured as Flycheck picks up c...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews