m_burg

m_burg

Running a Phoenix application on a read-only filesystem

I am trying to build a Phoenix application for Sandstorm. Sandstorm runs instances of applications in containers, grains, that all have a read-only filesystem. The only writeable directory is /var.

In order to prepare a grain a few scripts are run: setup.sh, build.sh, and launch.sh.

setup.sh is in charge of installing all the necessary dependencies in a VM to setup your development environment.

build.sh prepares the sources for your application.

launch.sh starts the actual grain.

In my build.sh I simply run MIX_ENV=prod mix compile to build my application. in launch.sh I start it with MIX_ENV=prod PORT=4000 mix phx.server.

When trying to start the application I get the following log output:

    Compiling 5 files (.ex)
    warning: redefining module HistorianWeb.PageController (current version loaded from _build/prod/lib/historian/ebin/Elixir.HistorianWeb.PageController.beam)
      lib/historian_web/controllers/page_controller.ex:1

    warning: redefining module HistorianWeb.Gettext (current version loaded from _build/prod/lib/historian/ebin/Elixir.HistorianWeb.Gettext.beam)
      lib/historian_web/gettext.ex:1

    warning: redefining module HistorianWeb.ErrorView (current version loaded from _build/prod/lib/historian/ebin/Elixir.HistorianWeb.ErrorView.beam)
      lib/historian_web/views/error_view.ex:1

    warning: redefining module HistorianWeb.LayoutView (current version loaded from _build/prod/lib/historian/ebin/Elixir.HistorianWeb.LayoutView.beam)
      lib/historian_web/views/layout_view.ex:1

    warning: redefining module HistorianWeb.PageView (current version loaded from _build/prod/lib/historian/ebin/Elixir.HistorianWeb.PageView.beam)
      lib/historian_web/views/page_view.ex:1

    ** (File.Error) could not write to file "/opt/app/_build/prod/lib/historian/ebin/Elixir.HistorianWeb.PageView.beam": read-only file system
        (elixir) lib/file.ex:953: File.write!/3
        (mix) lib/mix/compilers/elixir.ex:560: anonymous fn/4 in Mix.Compilers.Elixir.write_manifest/5
        (elixir) lib/enum.ex:1925: Enum."-reduce/3-lists^foldl/2-0-"/3
        (mix) lib/mix/compilers/elixir.ex:555: Mix.Compilers.Elixir.write_manifest/5
        (mix) lib/mix/compilers/elixir.ex:198: Mix.Compilers.Elixir.compile_manifest/9
        (mix) lib/mix/task.ex:316: Mix.Task.run_task/3
        (mix) lib/mix/tasks/compile.all.ex:68: Mix.Tasks.Compile.All.run_compiler/2
        (mix) lib/mix/tasks/compile.all.ex:52: Mix.Tasks.Compile.All.do_compile/4

Why does it need to compile more code? The fact that all the modules that are being redefined have the word view in their name suggests to me that this has something to do with templates.

Is there a way to compile this extra code before running the application? Or have it recompile without trying to write to the filesystem?

I am using Phoenix 1.3.4, because there are no SQLite adapters for Ecto 3 at the moment.

Most Liked

OvermindDL1

OvermindDL1

The issue is that it looks like it’s being launched via mix instead of a release. mix is designed for development purposes, so it will often recompile a lot of things on every launch, especially as it dynamically loads modules.

Releases on the other hand don’t, they are static, and if build_embedded is on then all modules get statically loaded regardless (no hickups on first-loading of modules), etc… You always want to use a release.

chrismcg

chrismcg

Check you’ve changed the :my_app to your actual app name where @repos is defined in the example code.

m_burg

m_burg

You use Distillery for that, right? I’ll try that.

Where Next?

Popular in Questions Top

albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: The documentation above suggests that while ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
dotdotdotPaul
Okay, I’m having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I’m sure I’...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

Other popular topics Top

danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29377 241
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New

We're in Beta

About us Mission Statement