dimitarvp

dimitarvp

At this point I’d say you should publish that new app in GitHub so other people can check.

Also include exact Erlang and Elixir versions (putting this in a .tool-versions file in the repo is what I do).

I’ve ran a lot of Phoenix apps and very rarely did any of them surpass 50-60MB of RAM.

1
Post #11
ollran

ollran OP

YES, IT FINALLY WORKS!

I am on MacOS and I cannot install Elixir on the server. So, I am using Docker for cross compiling the project for Debian 8.

So basically I run these commands:

$ docker build .
[...]
Successfully built 65d60d773205
$ docker create 65d60d773205
$ docker cp dca434f3938c415ebb419d3214b5cc3092e2c7ecdeacf03e52ca4e44eac6bde2:webapp.txz .
$ scp webapp.txz me@myserver.com:
$ ssh me@myserver.com
$ tar xvf webapp.txz
$ _build/prod/rel/webapp/bin/webapp start

I only needed +MMscs 60 (thank you @alvises). I commented out the rest.

This is my Dockerfile:

FROM debian:8

WORKDIR /app

RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
RUN apt-get update && \
    apt-get -y upgrade && \
    apt-get -y dist-upgrade && \
    apt-get install -y --no-install-recommends apt-utils && \
    apt-get -y install wget libwxbase3.0-0 libwxgtk3.0-0 libsctp1 xz-utils

RUN wget -O - https://deb.nodesource.com/setup_12.x | bash - && \
    apt-get install -y nodejs

RUN wget https://packages.erlang-solutions.com/erlang/debian/pool/esl-erlang_22.0.4-1~debian~jessie_amd64.deb && \
    wget https://packages.erlang-solutions.com/erlang/debian/pool/elixir_1.9.0-1~debian~jessie_all.deb

RUN dpkg -i esl-erlang_22.0.4-1~debian~jessie_amd64.deb && \
    dpkg -i elixir_1.9.0-1~debian~jessie_all.deb

RUN mix local.hex --force && \
    mix local.rebar --force && \
    yes | mix archive.install hex phx_new 1.4.8

RUN mix phx.new webapp --no-ecto

RUN cd webapp && \
    mix deps.get && \
    mix compile

RUN echo "config :webapp, WebappWeb.Endpoint, server: true" >> webapp/config/prod.exs

RUN cd webapp/assets && \
    npm install && \
    npm audit fix

RUN cd webapp/assets && \
    npx webpack --mode production && \
    cd .. && \
    mix phx.digest

RUN cd webapp && \
    SECRET_KEY_BASE=$(mix phx.gen.secret) MIX_ENV=prod mix release

# The magic happens in here
RUN cd webapp/_build/prod/rel/webapp/releases/0.1.0/ && \
    #echo "+MMsco true" >> vm.args && \
    #echo "+Musac false" >> vm.args && \
    echo "+MMscs 60" >> vm.args

RUN cd webapp && \
    tar cJvf webapp.txz _build && \
    mv webapp.txz ../..

CMD ["webapp/_build/prod/rel/webapp/bin/webapp", "start"]

Thank you, everyone!

2
Post #12
NobbZ

NobbZ

Your resulting image is unnecessarily bloated.

You probably do not need a full debian:8 under your feets.

Using the builder images by @beardedeagle combined with a multistage build you can get image sizes far less than 100 MB.

Also remember, if done correctly, neither erlang, nor elixir are a runtime requirement.

So in theory you could even use a base image that is compatible to your server, build a release therein, extract that release and only deploy the extracted release to your server. This will probably result in the smallest deployment size.

3
Post #13
garazdawi

garazdawi

Erlang Core Team

You may want to try +Meamin. This will disable all the erts memory allocators and fall back to malloc which can sometimes use less memory.

7
Post #14
— All posts loaded —