Help with Phoenix 1.3.0 and elastic beanstalk

We are beginning to work with Phoenix/Elixir and I am tasked with deploy strategy. I did some searching and came across this article on deploying to AWS Elastic Beanstalk and all was well when we were messing with Phoenix 1.2.x and then we made the switch to version 1.3.0. I have made all the necessary updates to the Dockerfile and .dockerignore that have to do with new directory structures. I can get the deployment to work for the initial deploy and even a few after that, but if I try the next day I get Permission denied when it tries to run the brunch command.

I am including my Dockerfile and .dockerignore to see if I am missing something important.

Dockerfile


# Set the Docker image you want to base your image off.
# I chose this one because it has Elixir preinstalled.
FROM trenpixster/elixir:1.4.4


# Set the locale, otherwise elixir will complain later on
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

# Setup Node - Phoenix uses the Node library `brunch` to compile assets.
# The official node instructions want you to pipe a script from the
# internet through sudo. There are alternatives:
# https://www.joyent.com/blog/installing-node-and-npm
RUN curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - && sudo apt-get install -y nodejs

#Install other stable dependencies that don't change often
#
# Compile app
RUN mkdir /app
WORKDIR /app

# Install Elixir Deps
ADD mix.* ./
RUN MIX_ENV=prod mix local.rebar
RUN MIX_ENV=prod mix local.hex --force
RUN MIX_ENV=prod mix deps.get

# Install Node Deps
WORKDIR /app/assets
ADD ./assets/package* ./assets/
RUN npm install

WORKDIR /app
# Install app
ADD . .
RUN MIX_ENV=prod mix compile

# Compile assets
RUN NODE_ENV=production assets/node_modules/brunch/bin/brunch build --production
WORKDIR /app
RUN MIX_ENV=prod mix phx.digest

# Exposes this port from the docker container to the host machine
EXPOSE 4000

# The command to run when this image starts up
CMD MIX_ENV=prod mix ecto.create && \
    MIX_ENV=prod mix ecto.migrate && \
    MIX_ENV=prod mix phx.server




----------
.dockerignore


----------

 /deps
/_build
ecl_Crash.dump
/assets/node_modules
/priv/static/*
/uploads/files/*
.git
.gitignore
# Elastic Beanstalk Files
.elasticbeanstalk/*

AFAIK you need to be in assets when you run brunch. So you need to put another WORKDIR /app/assets in front of running node and also chaning back to WORKDIR /app at the correct place after wards.

Also in general I’d suggest to ENV MIX_ENV="prod" NODE_ENV="production", early in the file and removing those strayed in the RUN directives to make it easier to alter the environment when necessary.

Also I’d think about splitting up into a container that compiles your stuff into a tarball and another one that you copy that tarball into to run it. Donce correctly you can decrease the footprint of the production container massively. When you then use alpine as a base you can easily reach unpacked container sizes far below 100 MiB!

1 Like

I have tried the suggestions you provided and I am still getting 91m/bin/sh: 1: brunch: not found Although locally my docker build works fine.

I have also tried using the full path to brunch and even adding to PATH and none are working.

Brunch not found is fundamentally different to a permission denied. Can you create a minified project showing your problem and push it to github?

I had various other issues and I have since figured out the issue.

  1. RDS settings were wrong for using an existing RDS.
  2. The paths for the commands

Thanks for the suggestions they helped tremendously!

Actually maybe you can help me get clarity on why when I use Elastic Beanstalk I have to move the devDependencies into the dependencies in the package.json so that the deploy can actually see and use brunch… On 1.2.x Phoenix this was not the case it only started when I moved to 1.3.0.