Help with AWS EB CLI and Docker Image failing at " Compiling cowlib eheap_alloc: Cannot allocate 49515520 bytes of memory (of type "heap")."

Hi,

I am trying to set up a quick and easy continuous deployment with AWS eb cli. I created a kind of short tutorial as follows:

Step 1: Prepare app for release

  1. Change prod.secrets.exs to releases.exs. Change Mix.config to import Config. Change default port to 8080 and set server to true in the endpoint config.

config/releases.exs

# In this file, we load production configuration and secrets
# from environment variables. You can also hardcode secrets,
# although such is generally not recommended and you have to
# remember to add this file to your .gitignore.
# use Mix.Config
import Config

secret_key_base =
  System.get_env("SECRET_KEY_BASE") ||
    raise """
    environment variable SECRET_KEY_BASE is missing.
    You can generate one by calling: mix phx.gen.secret
    """

config :sample_app, SampleAppWeb.Endpoint,
  http: [:inet6, port: String.to_integer(System.get_env("PORT") || "8080")],
  secret_key_base: secret_key_base

# ## Using releases (Elixir v1.9+)
#
# If you are doing OTP releases, you need to instruct Phoenix
# to start each relevant endpoint:
#
config :sample_app, SampleAppWeb.Endpoint, server: true
#
# Then you can assemble a release by calling `mix release`.
# See `mix help release` for more information.
  1. Remove import_config "prod.secret.exs" from config/prod.exs

Step 3: Build Docker image

  1. Sign in to your Linux instance where you have Docker installed.

  2. Create .dockerignore

.dockerignore

/deps
/_build
ecl_Crash.dump
/node_modules
/priv/static/*
/uploads/files/*
.git
.gitignore
  1. Create a Dockerfile:

Dockerfile

FROM elixir:1.10-alpine as build

ENV AWSCLI_VERSION "1.17.12"

# install build dependencies
RUN apk add --update git build-base nodejs npm yarn \
python \
python-dev \
py-pip \
build-base \
&& pip install awscli==$AWSCLI_VERSION --upgrade --user \
&& apk --purge -v del py-pip \
&& rm -rf /var/cache/apk/*

# prepare build dir
RUN mkdir /app
WORKDIR /app

# install hex + rebar
RUN mix local.hex --force && \
    mix local.rebar --force

# set build ENV
ENV MIX_ENV=prod


# install mix dependencies
COPY mix.exs mix.lock ./
COPY config config
RUN mix deps.get --only prod
RUN MIX_ENV=prod mix deps.compile

# build assets
COPY assets assets
COPY priv priv
RUN cd assets && npm install && npm run deploy
RUN mix phx.digest

# build project
COPY lib lib
RUN mix compile

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

# build release (uncomment COPY if rel/ exists)
# COPY rel rel
RUN mix release

# prepare release image
FROM alpine:3.9 AS app
RUN apk add --update bash openssl

RUN mkdir /app
WORKDIR /app

COPY --from=build /app/_build/prod/rel/sample_app ./
RUN chown -R nobody: /app
USER nobody

ENV HOME=/app

CMD ["./bin/sample_app", "start"]
  1. Run docker images. You should see the image in the list.
docker images
  1. Now we can run the docker build command:
docker build -t sample-app:latest ./ 

Test the image out witb eb cli

eb init

Fill out the prompts with these settings:

Select a default region: 1
Select an application to use: 5
Enter Application Name: sample-app
It appears you are using Docker. Is this correct?: Y
Do you wish to continue with CodeCommit?: Y
Select a repository: Create new Repository
Enter Repository Name: sample-app
Enter Branch Name: master
Do you want to set up SSH for your instances?: Y
Select a keypair.: keypair_that_you_use

eb local setenv HOST=http://localhost:8080 PORT=8080
eb local printenv
eb local run --port 8080

eb create

eb create \
  --envvars MIX_ENV=prod,SECRET_KEY_BASE=ymWHWe14a3Fb9JO3uoTDO4BhNIyzGlGPmJXi4Ps2CS+FYZcgJ8omhJiwapPQq3C2,PORT=8080

Enter Environment Name: sample-app-dev
Enter DNS CNAME prefix: sample-app-dev22
Select a load balancer type: application
Would you like to enable Spot Fleet requests for this environment?: N
Enter an RDS DB username: sampleapproot
Enter an RDS DB master password: verysecurepassword

if get error, try eb init once more.

dockerrun.aws.json

{
  "AWSEBDockerrunVersion": 1,
  "volumes": [
    {
      "name": "sample-app",
      "host": {
        "sourcePath": "/app"
      }
    }
  ],
  "containerDefinitions": [
    {
      "name": "sample-app",
      "essential": true,
      "portMappings": [
        {
          "hostPort": 80,
          "containerPort": 8080
        }
      ]
    }
  ]
}

eb config

aws:elb:listener:80:
  InstancePort: '80'
  InstanceProtocol: TCP
  ListenerEnabled: 'true'
  ListenerProtocol: TCP
  PolicyNames: null
  SSLCertificateId: null

Now make a change and commit to the repo and do then do:

eb deploy

The following error occurs:

caused by: cat: Dockerrun.aws.json: No such file or directory
  cat: Dockerrun.aws.json: No such file or directory
  cat: Dockerrun.aws.json: No such file or directory
  1.10-alpine: Pulling from library/elixir
  c9b1b535fdd9: Pulling fs layer
  8abf1824fc39: Pulling fs layer
  951d1fa3e62f: Pulling fs layer
  c9b1b535fdd9: Verifying Checksum
  c9b1b535fdd9: Download complete
  951d1fa3e62f: Verifying Checksum
  951d1fa3e62f: Download complete
  8abf1824fc39: Verifying Checksum
  8abf1824fc39: Download complete
  c9b1b535fdd9: Pull complete
  8abf1824fc39: Pull complete
  951d1fa3e62f: Pull complete
  Digest: sha256:45718ab3fd121b83abe15c087e7fadb45e8498839b9bca37b2260f6333516521
  Status: Downloaded newer image for elixir:1.10-alpine
  Successfully pulled elixir:1.10-alpine
  Sending build context to Docker daemon  523.3kB

  Step 1/28 : FROM elixir:1.10-alpine as build
   ---> d33a140bc70e
  Step 2/28 : ENV AWSCLI_VERSION "1.17.12"
   ---> Running in 8260eb8ec8aa
  Removing intermediate container 8260eb8ec8aa
   ---> 545ff7ad8d1b
  Step 3/28 : RUN apk add --update git build-base nodejs npm yarn python python-dev py-pip build-base && pip install awscli==$AWSCLI_VERSION --upgrade --user && apk --purge -v del py-pip && rm -rf /var/cache/apk/*
   ---> Running in 4ebf07d5a785
  fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz
  fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/x86_64/APKINDEX.tar.gz
  (1/37) Installing libgcc (9.2.0-r3)
  (2/37) Installing libstdc++ (9.2.0-r3)
  (3/37) Installing binutils (2.33.1-r0)
  (4/37) Installing libmagic (5.37-r1)
  (5/37) Installing file (5.37-r1)
  (6/37) Installing gmp (6.1.2-r1)
  (7/37) Installing isl (0.18-r0)
  (8/37) Installing libgomp (9.2.0-r3)
  (9/37) Installing libatomic (9.2.0-r3)
  (10/37) Installing mpfr4 (4.0.2-r1)
  (11/37) Installing mpc1 (1.1.0-r1)
  (12/37) Installing gcc (9.2.0-r3)
  (13/37) Installing musl-dev (1.1.24-r0)
  (14/37) Installing libc-dev (0.7.2-r0)
  (15/37) Installing g++ (9.2.0-r3)
  (16/37) Installing make (4.2.1-r2)
  (17/37) Installing fortify-headers (1.1-r0)
  (18/37) Installing build-base (0.5-r1)
  (19/37) Installing nghttp2-libs (1.40.0-r0)
  (20/37) Installing libcurl (7.67.0-r0)
  (21/37) Installing expat (2.2.9-r1)
  (22/37) Installing pcre2 (10.34-r1)
  (23/37) Installing git (2.24.1-r0)
  (24/37) Installing c-ares (1.15.0-r0)
  (25/37) Installing libuv (1.34.0-r0)
  (26/37) Installing nodejs (12.15.0-r1)
  (27/37) Installing npm (12.15.0-r1)
  (28/37) Installing libbz2 (1.0.8-r1)
  (29/37) Installing libffi (3.2.1-r6)
  (30/37) Installing gdbm (1.13-r1)
  (31/37) Installing sqlite-libs (3.30.1-r1)
  (32/37) Installing python2 (2.7.16-r3)
  (33/37) Installing py-setuptools (42.0.2-r0)
  (34/37) Installing py2-pip (18.1-r0)
  (35/37) Installing pkgconf (1.6.3-r0)
  (36/37) Installing python2-dev (2.7.16-r3)
  (37/37) Installing yarn (1.19.2-r0)
  Executing busybox-1.31.1-r9.trigger
  OK: 326 MiB in 60 packages
  Collecting awscli==1.17.12
    Downloading https://files.pythonhosted.org/packages/42/74/47660005f20c879e0d74bf455366339f6545b52fe1f1b4d032d10d89dc9e/awscli-1.17.12-py2.py3-none-any.whl (2.9MB)
  Collecting botocore==1.14.12 (from awscli==1.17.12)
    Downloading https://files.pythonhosted.org/packages/23/37/a360f515f1de58c0433128bb760fdc9db44772fc361d039c221e77b555fc/botocore-1.14.12-py2.py3-none-any.whl (5.9MB)
  Collecting PyYAML<5.3,>=3.10 (from awscli==1.17.12)
    Downloading https://files.pythonhosted.org/packages/8d/c9/e5be955a117a1ac548cdd31e37e8fd7b02ce987f9655f5c7563c656d5dcb/PyYAML-5.2.tar.gz (265kB)
  Collecting docutils<0.16,>=0.10 (from awscli==1.17.12)
    Downloading https://files.pythonhosted.org/packages/3a/dc/bf2b15d1fa15a6f7a9e77a61b74ecbbae7258558fcda8ffc9a6638a6b327/docutils-0.15.2-py2-none-any.whl (548kB)
  Collecting rsa<=3.5.0,>=3.1.2 (from awscli==1.17.12)
    Downloading https://files.pythonhosted.org/packages/e1/ae/baedc9cb175552e95f3395c43055a6a5e125ae4d48a1d7a924baca83e92e/rsa-3.4.2-py2.py3-none-any.whl (46kB)
  Collecting s3transfer<0.4.0,>=0.3.0 (from awscli==1.17.12)
    Downloading https://files.pythonhosted.org/packages/69/79/e6afb3d8b0b4e96cefbdc690f741d7dd24547ff1f94240c997a26fa908d3/s3transfer-0.3.3-py2.py3-none-any.whl (69kB)
  Collecting colorama<0.4.4,>=0.2.5; python_version != "3.4" (from awscli==1.17.12)
    Downloading https://files.pythonhosted.org/packages/c9/dc/45cdef1b4d119eb96316b3117e6d5708a08029992b2fee2c143c7a0a5cc5/colorama-0.4.3-py2.py3-none-any.whl
  Collecting urllib3<1.26,>=1.20; python_version != "3.4" (from botocore==1.14.12->awscli==1.17.12)
    Downloading https://files.pythonhosted.org/packages/e8/74/6e4f91745020f967d09332bb2b8b9b10090957334692eb88ea4afe91b77f/urllib3-1.25.8-py2.py3-none-any.whl (125kB)
  Collecting python-dateutil<3.0.0,>=2.1 (from botocore==1.14.12->awscli==1.17.12)
    Downloading https://files.pythonhosted.org/packages/d4/70/d60450c3dd48ef87586924207ae8907090de0b306af2bce5d134d78615cb/python_dateutil-2.8.1-py2.py3-none-any.whl (227kB)
  Collecting jmespath<1.0.0,>=0.7.1 (from botocore==1.14.12->awscli==1.17.12)
    Downloading https://files.pythonhosted.org/packages/83/94/7179c3832a6d45b266ddb2aac329e101367fbdb11f425f13771d27f225bb/jmespath-0.9.4-py2.py3-none-any.whl
  Collecting pyasn1>=0.1.3 (from rsa<=3.5.0,>=3.1.2->awscli==1.17.12)
    Downloading https://files.pythonhosted.org/packages/62/1e/a94a8d635fa3ce4cfc7f506003548d0a2447ae76fd5ca53932970fe3053f/pyasn1-0.4.8-py2.py3-none-any.whl (77kB)
  Collecting futures<4.0.0,>=2.2.0; python_version == "2.7" (from s3transfer<0.4.0,>=0.3.0->awscli==1.17.12)
    Downloading https://files.pythonhosted.org/packages/d8/a6/f46ae3f1da0cd4361c344888f59ec2f5785e69c872e175a748ef6071cdb5/futures-3.3.0-py2-none-any.whl
  Collecting six>=1.5 (from python-dateutil<3.0.0,>=2.1->botocore==1.14.12->awscli==1.17.12)
    Downloading https://files.pythonhosted.org/packages/65/eb/1f97cb97bfc2390a276969c6fae16075da282f5058082d4cb10c6c5c1dba/six-1.14.0-py2.py3-none-any.whl
  Installing collected packages: docutils, urllib3, six, python-dateutil, jmespath, botocore, PyYAML, pyasn1, rsa, futures, s3transfer, colorama, awscli
    Running setup.py install for PyYAML: started
      Running setup.py install for PyYAML: finished with status 'done'
  e[91m  The scripts pyrsa-decrypt, pyrsa-decrypt-bigfile, pyrsa-encrypt, pyrsa-encrypt-bigfile, pyrsa-keygen, pyrsa-priv2pub, pyrsa-sign and pyrsa-verify are installed in '/root/.local/bin' which is not on PATH.
    Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  e[0mSuccessfully installed PyYAML-5.2 awscli-1.17.12 botocore-1.14.12 colorama-0.4.3 docutils-0.15.2 futures-3.3.0 jmespath-0.9.4 pyasn1-0.4.8 python-dateutil-2.8.1 rsa-3.4.2 s3transfer-0.3.3 six-1.14.0 urllib3-1.25.8
  The following packages will be REMOVED:
    py2-pip py-setuptools
  After this operation, 12 MiB of disk space will be freed.
  (1/2) Purging py2-pip (18.1-r0)
  (2/2) Purging py-setuptools (42.0.2-r0)
  Executing busybox-1.31.1-r9.trigger
  OK: 58 packages, 1044 dirs, 11163 files, 314 MiB
  Removing intermediate container 4ebf07d5a785
   ---> 08ee5518f257
  Step 4/28 : RUN mkdir /app
   ---> Running in e35e460c83a7
  Removing intermediate container e35e460c83a7
   ---> f8a5eaf95438
  Step 5/28 : WORKDIR /app
   ---> Running in b4f2c4bb6528
  Removing intermediate container b4f2c4bb6528
   ---> b6bf22023905
  Step 6/28 : RUN mix local.hex --force &&     mix local.rebar --force
   ---> Running in 34c3eb374d31
  * creating /root/.mix/archives/hex-0.20.5
  * creating /root/.mix/rebar
  * creating /root/.mix/rebar3
  Removing intermediate container 34c3eb374d31
   ---> e1c2d6c6e7f8
  Step 7/28 : ENV MIX_ENV=prod
   ---> Running in 7fa1e7210bb6
  Removing intermediate container 7fa1e7210bb6
   ---> 4265506a95ce
  Step 8/28 : COPY mix.exs mix.lock ./
   ---> c49742235cda
  Step 9/28 : COPY config config
   ---> db595053974a
  Step 10/28 : RUN mix deps.get --only prod
   ---> Running in 82096f51d551
  Resolving Hex dependencies...
  Dependency resolution completed:
  Unchanged:
    cowboy 2.7.0
    cowlib 2.8.0
    gettext 0.17.4
    jason 1.1.2
    mime 1.3.1
    phoenix 1.4.12
    phoenix_html 2.14.0
    phoenix_pubsub 1.1.2
    plug 1.8.3
    plug_cowboy 2.1.2
    plug_crypto 1.0.0
    ranch 1.7.1
    telemetry 0.4.1
  * Getting phoenix (Hex package)
  * Getting phoenix_pubsub (Hex package)
  * Getting phoenix_html (Hex package)
  * Getting gettext (Hex package)
  * Getting jason (Hex package)
  * Getting plug_cowboy (Hex package)
  * Getting cowboy (Hex package)
  * Getting plug (Hex package)
  * Getting mime (Hex package)
  * Getting plug_crypto (Hex package)
  * Getting cowlib (Hex package)
  * Getting ranch (Hex package)
  * Getting telemetry (Hex package)
  Removing intermediate container 82096f51d551
   ---> d978bd473f56
  Step 11/28 : RUN MIX_ENV=prod mix deps.compile
   ---> Running in cccefd2b714f
  ==> gettext
  Compiling 1 file (.yrl)
  Compiling 1 file (.erl)
  Compiling 20 files (.ex)
  Generated gettext app
  ===> Compiling ranch
  ===> Compiling telemetry
  ==> jason
  Compiling 8 files (.ex)
  Generated jason app
  ==> phoenix_pubsub
  Compiling 13 files (.ex)
  e[91mwarning: Supervisor.Spec.supervise/2 is deprecated. Use the new child specifications outlined in the Supervisor module instead
    lib/phoenix/pubsub/local_supervisor.ex:Phoenix.PubSub.LocalSupervisor.init/1
  
  e[0me[91mwarning: Supervisor.Spec.supervise/2 is deprecated. Use the new child specifications outlined in the Supervisor module instead
    lib/phoenix/pubsub/pg2.ex:Phoenix.PubSub.PG2.init/1
  
  warning: Supervisor.Spec.supervise/2 is deprecated. Use the new child specifications outlined in the Supervisor module instead
    lib/phoenix/tracker.ex:Phoenix.Tracker.init/1
  
  e[0mGenerated phoenix_pubsub app
  ===> Compiling cowlib
  eheap_alloc: Cannot allocate 49515520 bytes of memory (of type "heap").
  
  Crash dump is being written to: erl_crash.dump...done
  ==> sample_app
  e[91m** (Mix) Could not compile dependency :cowlib, "/root/.mix/rebar3 bare compile --paths="/app/_build/prod/lib/*/ebin"" command failed. You can recompile this dependency with "mix deps.compile cowlib", update it with "mix deps.update cowlib" or clean it with "mix deps.clean cowlib"
  e[0mThe command '/bin/sh -c MIX_ENV=prod mix deps.compile' returned a non-zero code: 1
  Failed to build Docker image aws_beanstalk/staging-app, retrying...
  Sending build context to Docker daemon  523.3kB

  Step 1/28 : FROM elixir:1.10-alpine as build
   ---> d33a140bc70e
  Step 2/28 : ENV AWSCLI_VERSION "1.17.12"
   ---> Using cache
   ---> 545ff7ad8d1b
  Step 3/28 : RUN apk add --update git build-base nodejs npm yarn python python-dev py-pip build-base && pip install awscli==$AWSCLI_VERSION --upgrade --user && apk --purge -v del py-pip && rm -rf /var/cache/apk/*
   ---> Using cache
   ---> 08ee5518f257
  Step 4/28 : RUN mkdir /app
   ---> Using cache
   ---> f8a5eaf95438
  Step 5/28 : WORKDIR /app
   ---> Using cache
   ---> b6bf22023905
  Step 6/28 : RUN mix local.hex --force &&     mix local.rebar --force
   ---> Using cache
   ---> e1c2d6c6e7f8
  Step 7/28 : ENV MIX_ENV=prod
   ---> Using cache
   ---> 4265506a95ce
  Step 8/28 : COPY mix.exs mix.lock ./
   ---> Using cache
   ---> c49742235cda
  Step 9/28 : COPY config config
   ---> Using cache
   ---> db595053974a
  Step 10/28 : RUN mix deps.get --only prod
   ---> Using cache
   ---> d978bd473f56
  Step 11/28 : RUN MIX_ENV=prod mix deps.compile
   ---> Running in 17480f8caa1a
  ==> gettext
  Compiling 1 file (.yrl)
  Compiling 1 file (.erl)
  Compiling 20 files (.ex)
  Generated gettext app
  ===> Compiling ranch
  ===> Compiling telemetry
  ==> jason
  Compiling 8 files (.ex)
  Generated jason app
  ==> phoenix_pubsub
  Compiling 13 files (.ex)
  e[91mwarning: Supervisor.Spec.supervise/2 is deprecated. Use the new child specifications outlined in the Supervisor module instead
    lib/phoenix/pubsub/local_supervisor.ex:Phoenix.PubSub.LocalSupervisor.init/1
  
  e[0me[91mwarning: Supervisor.Spec.supervise/2 is deprecated. Use the new child specifications outlined in the Supervisor module instead
    lib/phoenix/pubsub/pg2.ex:Phoenix.PubSub.PG2.init/1
  
  e[0me[91mwarning: Supervisor.Spec.supervise/2 is deprecated. Use the new child specifications outlined in the Supervisor module instead
    lib/phoenix/tracker.ex:Phoenix.Tracker.init/1
  
  e[0mGenerated phoenix_pubsub app
  ===> Compiling cowlib
  eheap_alloc: Cannot allocate 49515520 bytes of memory (of type "heap").
  
  Crash dump is being written to: erl_crash.dump...done
  ==> sample_app
  e[91m** (Mix) Could not compile dependency :cowlib, "/root/.mix/rebar3 bare compile --paths="/app/_build/prod/lib/*/ebin"" command failed. You can recompile this dependency with "mix deps.compile cowlib", update it with "mix deps.update cowlib" or clean it with "mix deps.clean cowlib"
  e[0mThe command '/bin/sh -c MIX_ENV=prod mix deps.compile' returned a non-zero code: 1
  Failed to build Docker image aws_beanstalk/staging-app: x deps.update cowlib" or clean it with "mix deps.clean cowlib"
  e[0mThe command '/bin/sh -c MIX_ENV=prod mix deps.compile' returned a non-zero code: 1. Check snapshot logs for details. (ElasticBeanstalk::ExternalInvocationError)
caused by: cat: Dockerrun.aws.json: No such file or directory
  cat: Dockerrun.aws.json: No such file or directory
  cat: Dockerrun.aws.json: No such file or directory
  1.10-alpine: Pulling from library/elixir
  c9b1b535fdd9: Pulling fs layer
  8abf1824fc39: Pulling fs layer
  951d1fa3e62f: Pulling fs layer
  c9b1b535fdd9: Verifying Checksum
  c9b1b535fdd9: Download complete
  951d1fa3e62f: Verifying Checksum
  951d1fa3e62f: Download complete
  8abf1824fc39: Verifying Checksum
  8abf1824fc39: Download complete
  c9b1b535fdd9: Pull complete
  8abf1824fc39: Pull complete
  951d1fa3e62f: Pull complete
  Digest: sha256:45718ab3fd121b83abe15c087e7fadb45e8498839b9bca37b2260f6333516521
  Status: Downloaded newer image for elixir:1.10-alpine
  Successfully pulled elixir:1.10-alpine
  Sending build context to Docker daemon  523.3kB

  Step 1/28 : FROM elixir:1.10-alpine as build
   ---> d33a140bc70e
  Step 2/28 : ENV AWSCLI_VERSION "1.17.12"
   ---> Running in 8260eb8ec8aa
  Removing intermediate container 8260eb8ec8aa
   ---> 545ff7ad8d1b
  Step 3/28 : RUN apk add --update git build-base nodejs npm yarn python python-dev py-pip build-base && pip install awscli==$AWSCLI_VERSION --upgrade --user && apk --purge -v del py-pip && rm -rf /var/cache/apk/*
   ---> Running in 4ebf07d5a785
  fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz
  fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/x86_64/APKINDEX.tar.gz
  (1/37) Installing libgcc (9.2.0-r3)
  (2/37) Installing libstdc++ (9.2.0-r3)
  (3/37) Installing binutils (2.33.1-r0)
  (4/37) Installing libmagic (5.37-r1)
  (5/37) Installing file (5.37-r1)
  (6/37) Installing gmp (6.1.2-r1)
  (7/37) Installing isl (0.18-r0)
  (8/37) Installing libgomp (9.2.0-r3)
  (9/37) Installing libatomic (9.2.0-r3)
  (10/37) Installing mpfr4 (4.0.2-r1)
  (11/37) Installing mpc1 (1.1.0-r1)
  (12/37) Installing gcc (9.2.0-r3)
  (13/37) Installing musl-dev (1.1.24-r0)
  (14/37) Installing libc-dev (0.7.2-r0)
  (15/37) Installing g++ (9.2.0-r3)
  (16/37) Installing make (4.2.1-r2)
  (17/37) Installing fortify-headers (1.1-r0)
  (18/37) Installing build-base (0.5-r1)
  (19/37) Installing nghttp2-libs (1.40.0-r0)
  (20/37) Installing libcurl (7.67.0-r0)
  (21/37) Installing expat (2.2.9-r1)
  (22/37) Installing pcre2 (10.34-r1)
  (23/37) Installing git (2.24.1-r0)
  (24/37) Installing c-ares (1.15.0-r0)
  (25/37) Installing libuv (1.34.0-r0)
  (26/37) Installing nodejs (12.15.0-r1)
  (27/37) Installing npm (12.15.0-r1)
  (28/37) Installing libbz2 (1.0.8-r1)
  (29/37) Installing libffi (3.2.1-r6)
  (30/37) Installing gdbm (1.13-r1)
  (31/37) Installing sqlite-libs (3.30.1-r1)
  (32/37) Installing python2 (2.7.16-r3)
  (33/37) Installing py-setuptools (42.0.2-r0)
  (34/37) Installing py2-pip (18.1-r0)
  (35/37) Installing pkgconf (1.6.3-r0)
  (36/37) Installing python2-dev (2.7.16-r3)
  (37/37) Installing yarn (1.19.2-r0)
  Executing busybox-1.31.1-r9.trigger
  OK: 326 MiB in 60 packages
  Collecting awscli==1.17.12
    Downloading https://files.pythonhosted.org/packages/42/74/47660005f20c879e0d74bf455366339f6545b52fe1f1b4d032d10d89dc9e/awscli-1.17.12-py2.py3-none-any.whl (2.9MB)
  Collecting botocore==1.14.12 (from awscli==1.17.12)
    Downloading https://files.pythonhosted.org/packages/23/37/a360f515f1de58c0433128bb760fdc9db44772fc361d039c221e77b555fc/botocore-1.14.12-py2.py3-none-any.whl (5.9MB)
  Collecting PyYAML<5.3,>=3.10 (from awscli==1.17.12)
    Downloading https://files.pythonhosted.org/packages/8d/c9/e5be955a117a1ac548cdd31e37e8fd7b02ce987f9655f5c7563c656d5dcb/PyYAML-5.2.tar.gz (265kB)
  Collecting docutils<0.16,>=0.10 (from awscli==1.17.12)
    Downloading https://files.pythonhosted.org/packages/3a/dc/bf2b15d1fa15a6f7a9e77a61b74ecbbae7258558fcda8ffc9a6638a6b327/docutils-0.15.2-py2-none-any.whl (548kB)
  Collecting rsa<=3.5.0,>=3.1.2 (from awscli==1.17.12)
    Downloading https://files.pythonhosted.org/packages/e1/ae/baedc9cb175552e95f3395c43055a6a5e125ae4d48a1d7a924baca83e92e/rsa-3.4.2-py2.py3-none-any.whl (46kB)
  Collecting s3transfer<0.4.0,>=0.3.0 (from awscli==1.17.12)
    Downloading https://files.pythonhosted.org/packages/69/79/e6afb3d8b0b4e96cefbdc690f741d7dd24547ff1f94240c997a26fa908d3/s3transfer-0.3.3-py2.py3-none-any.whl (69kB)
  Collecting colorama<0.4.4,>=0.2.5; python_version != "3.4" (from awscli==1.17.12)
    Downloading https://files.pythonhosted.org/packages/c9/dc/45cdef1b4d119eb96316b3117e6d5708a08029992b2fee2c143c7a0a5cc5/colorama-0.4.3-py2.py3-none-any.whl
  Collecting urllib3<1.26,>=1.20; python_version != "3.4" (from botocore==1.14.12->awscli==1.17.12)
    Downloading https://files.pythonhosted.org/packages/e8/74/6e4f91745020f967d09332bb2b8b9b10090957334692eb88ea4afe91b77f/urllib3-1.25.8-py2.py3-none-any.whl (125kB)
  Collecting python-dateutil<3.0.0,>=2.1 (from botocore==1.14.12->awscli==1.17.12)
    Downloading https://files.pythonhosted.org/packages/d4/70/d60450c3dd48ef87586924207ae8907090de0b306af2bce5d134d78615cb/python_dateutil-2.8.1-py2.py3-none-any.whl (227kB)
  Collecting jmespath<1.0.0,>=0.7.1 (from botocore==1.14.12->awscli==1.17.12)
    Downloading https://files.pythonhosted.org/packages/83/94/7179c3832a6d45b266ddb2aac329e101367fbdb11f425f13771d27f225bb/jmespath-0.9.4-py2.py3-none-any.whl
  Collecting pyasn1>=0.1.3 (from rsa<=3.5.0,>=3.1.2->awscli==1.17.12)
    Downloading https://files.pythonhosted.org/packages/62/1e/a94a8d635fa3ce4cfc7f506003548d0a2447ae76fd5ca53932970fe3053f/pyasn1-0.4.8-py2.py3-none-any.whl (77kB)
  Collecting futures<4.0.0,>=2.2.0; python_version == "2.7" (from s3transfer<0.4.0,>=0.3.0->awscli==1.17.12)
    Downloading https://files.pythonhosted.org/packages/d8/a6/f46ae3f1da0cd4361c344888f59ec2f5785e69c872e175a748ef6071cdb5/futures-3.3.0-py2-none-any.whl
  Collecting six>=1.5 (from python-dateutil<3.0.0,>=2.1->botocore==1.14.12->awscli==1.17.12)
    Downloading https://files.pythonhosted.org/packages/65/eb/1f97cb97bfc2390a276969c6fae16075da282f5058082d4cb10c6c5c1dba/six-1.14.0-py2.py3-none-any.whl
  Installing collected packages: docutils, urllib3, six, python-dateutil, jmespath, botocore, PyYAML, pyasn1, rsa, futures, s3transfer, colorama, awscli
    Running setup.py install for PyYAML: started
      Running setup.py install for PyYAML: finished with status 'done'
  e[91m  The scripts pyrsa-decrypt, pyrsa-decrypt-bigfile, pyrsa-encrypt, pyrsa-encrypt-bigfile, pyrsa-keygen, pyrsa-priv2pub, pyrsa-sign and pyrsa-verify are installed in '/root/.local/bin' which is not on PATH.
    Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  e[0mSuccessfully installed PyYAML-5.2 awscli-1.17.12 botocore-1.14.12 colorama-0.4.3 docutils-0.15.2 futures-3.3.0 jmespath-0.9.4 pyasn1-0.4.8 python-dateutil-2.8.1 rsa-3.4.2 s3transfer-0.3.3 six-1.14.0 urllib3-1.25.8
  The following packages will be REMOVED:
    py2-pip py-setuptools
  After this operation, 12 MiB of disk space will be freed.
  (1/2) Purging py2-pip (18.1-r0)
  (2/2) Purging py-setuptools (42.0.2-r0)
  Executing busybox-1.31.1-r9.trigger
  OK: 58 packages, 1044 dirs, 11163 files, 314 MiB
  Removing intermediate container 4ebf07d5a785
   ---> 08ee5518f257
  Step 4/28 : RUN mkdir /app
   ---> Running in e35e460c83a7
  Removing intermediate container e35e460c83a7
   ---> f8a5eaf95438
  Step 5/28 : WORKDIR /app
   ---> Running in b4f2c4bb6528
  Removing intermediate container b4f2c4bb6528
   ---> b6bf22023905
  Step 6/28 : RUN mix local.hex --force &&     mix local.rebar --force
   ---> Running in 34c3eb374d31
  * creating /root/.mix/archives/hex-0.20.5
  * creating /root/.mix/rebar
  * creating /root/.mix/rebar3
  Removing intermediate container 34c3eb374d31
   ---> e1c2d6c6e7f8
  Step 7/28 : ENV MIX_ENV=prod
   ---> Running in 7fa1e7210bb6
  Removing intermediate container 7fa1e7210bb6
   ---> 4265506a95ce
  Step 8/28 : COPY mix.exs mix.lock ./
   ---> c49742235cda
  Step 9/28 : COPY config config
   ---> db595053974a
  Step 10/28 : RUN mix deps.get --only prod
   ---> Running in 82096f51d551
  Resolving Hex dependencies...
  Dependency resolution completed:
  Unchanged:
    cowboy 2.7.0
    cowlib 2.8.0
    gettext 0.17.4
    jason 1.1.2
    mime 1.3.1
    phoenix 1.4.12
    phoenix_html 2.14.0
    phoenix_pubsub 1.1.2
    plug 1.8.3
    plug_cowboy 2.1.2
    plug_crypto 1.0.0
    ranch 1.7.1
    telemetry 0.4.1
  * Getting phoenix (Hex package)
  * Getting phoenix_pubsub (Hex package)
  * Getting phoenix_html (Hex package)
  * Getting gettext (Hex package)
  * Getting jason (Hex package)
  * Getting plug_cowboy (Hex package)
  * Getting cowboy (Hex package)
  * Getting plug (Hex package)
  * Getting mime (Hex package)
  * Getting plug_crypto (Hex package)
  * Getting cowlib (Hex package)
  * Getting ranch (Hex package)
  * Getting telemetry (Hex package)
  Removing intermediate container 82096f51d551
   ---> d978bd473f56
  Step 11/28 : RUN MIX_ENV=prod mix deps.compile
   ---> Running in cccefd2b714f
  ==> gettext
  Compiling 1 file (.yrl)
  Compiling 1 file (.erl)
  Compiling 20 files (.ex)
  Generated gettext app
  ===> Compiling ranch
  ===> Compiling telemetry
  ==> jason
  Compiling 8 files (.ex)
  Generated jason app
  ==> phoenix_pubsub
  Compiling 13 files (.ex)
  e[91mwarning: Supervisor.Spec.supervise/2 is deprecated. Use the new child specifications outlined in the Supervisor module instead
    lib/phoenix/pubsub/local_supervisor.ex:Phoenix.PubSub.LocalSupervisor.init/1
  
  e[0me[91mwarning: Supervisor.Spec.supervise/2 is deprecated. Use the new child specifications outlined in the Supervisor module instead
    lib/phoenix/pubsub/pg2.ex:Phoenix.PubSub.PG2.init/1
  
  warning: Supervisor.Spec.supervise/2 is deprecated. Use the new child specifications outlined in the Supervisor module instead
    lib/phoenix/tracker.ex:Phoenix.Tracker.init/1
  
  e[0mGenerated phoenix_pubsub app
  ===> Compiling cowlib
  eheap_alloc: Cannot allocate 49515520 bytes of memory (of type "heap").
  
  Crash dump is being written to: erl_crash.dump...done
  ==> sample_app
  e[91m** (Mix) Could not compile dependency :cowlib, "/root/.mix/rebar3 bare compile --paths="/app/_build/prod/lib/*/ebin"" command failed. You can recompile this dependency with "mix deps.compile cowlib", update it with "mix deps.update cowlib" or clean it with "mix deps.clean cowlib"
  e[0mThe command '/bin/sh -c MIX_ENV=prod mix deps.compile' returned a non-zero code: 1
  Failed to build Docker image aws_beanstalk/staging-app, retrying...
  Sending build context to Docker daemon  523.3kB

  Step 1/28 : FROM elixir:1.10-alpine as build
   ---> d33a140bc70e
  Step 2/28 : ENV AWSCLI_VERSION "1.17.12"
   ---> Using cache
   ---> 545ff7ad8d1b
  Step 3/28 : RUN apk add --update git build-base nodejs npm yarn python python-dev py-pip build-base && pip install awscli==$AWSCLI_VERSION --upgrade --user && apk --purge -v del py-pip && rm -rf /var/cache/apk/*
   ---> Using cache
   ---> 08ee5518f257
  Step 4/28 : RUN mkdir /app
   ---> Using cache
   ---> f8a5eaf95438
  Step 5/28 : WORKDIR /app
   ---> Using cache
   ---> b6bf22023905
  Step 6/28 : RUN mix local.hex --force &&     mix local.rebar --force
   ---> Using cache
   ---> e1c2d6c6e7f8
  Step 7/28 : ENV MIX_ENV=prod
   ---> Using cache
   ---> 4265506a95ce
  Step 8/28 : COPY mix.exs mix.lock ./
   ---> Using cache
   ---> c49742235cda
  Step 9/28 : COPY config config
   ---> Using cache
   ---> db595053974a
  Step 10/28 : RUN mix deps.get --only prod
   ---> Using cache
   ---> d978bd473f56
  Step 11/28 : RUN MIX_ENV=prod mix deps.compile
   ---> Running in 17480f8caa1a
  ==> gettext
  Compiling 1 file (.yrl)
  Compiling 1 file (.erl)
  Compiling 20 files (.ex)
  Generated gettext app
  ===> Compiling ranch
  ===> Compiling telemetry
  ==> jason
  Compiling 8 files (.ex)
  Generated jason app
  ==> phoenix_pubsub
  Compiling 13 files (.ex)
  e[91mwarning: Supervisor.Spec.supervise/2 is deprecated. Use the new child specifications outlined in the Supervisor module instead
    lib/phoenix/pubsub/local_supervisor.ex:Phoenix.PubSub.LocalSupervisor.init/1
  
  e[0me[91mwarning: Supervisor.Spec.supervise/2 is deprecated. Use the new child specifications outlined in the Supervisor module instead
    lib/phoenix/pubsub/pg2.ex:Phoenix.PubSub.PG2.init/1
  
  e[0me[91mwarning: Supervisor.Spec.supervise/2 is deprecated. Use the new child specifications outlined in the Supervisor module instead
    lib/phoenix/tracker.ex:Phoenix.Tracker.init/1
  
  e[0mGenerated phoenix_pubsub app
  ===> Compiling cowlib
  eheap_alloc: Cannot allocate 49515520 bytes of memory (of type "heap").
  
  Crash dump is being written to: erl_crash.dump...done
  ==> sample_app
  e[91m** (Mix) Could not compile dependency :cowlib, "/root/.mix/rebar3 bare compile --paths="/app/_build/prod/lib/*/ebin"" command failed. You can recompile this dependency with "mix deps.compile cowlib", update it with "mix deps.update cowlib" or clean it with "mix deps.clean cowlib"
  e[0mThe command '/bin/sh -c MIX_ENV=prod mix deps.compile' returned a non-zero code: 1
  Failed to build Docker image aws_beanstalk/staging-app: x deps.update cowlib" or clean it with "mix deps.clean cowlib"
  e[0mThe command '/bin/sh -c MIX_ENV=prod mix deps.compile' returned a non-zero code: 1. Check snapshot logs for details. (Executor::NonZeroExitStatus)

Either the machine you are building on or the build container does not have enough memory. Try providing more.

1 Like

To not be able to allocate some measly 50MB of memory is bad. What are the server’s system characteristics?

Yea I figured that. Fixed by adding -i t2.medium in the below command:

eb create -i t2.medium \
  --envvars MIX_ENV=prod,SECRET_KEY_BASE=ymWHWe14a3Fb9JO3uoTDO4BhNIyzGlGPmJXi4Ps2CS+FYZcgJ8omhJiwapPQq3C2,PORT=8080

Also updated eb config sample-app-dev

  aws:autoscaling:launchconfiguration:
    ...
    InstanceType: t2.medium
    ...

Was getting a new funky error:

failed. Reason: The specified instance type can only be used in a VPC. A subnet ID or network interface ID is required to carry out the request. Launching EC2 instance failed.

Fixed by changing default region to us-west-2 :woman_shrugging:

Yea I think it might be all the Docker image building that was going on. The instance type was: Docker running on 64bit Amazon Linux/2.14.1 on t2.micro instance. Switching to t2.medium fixed the issue. Hopefully it doesn’t cost an arm and a leg.

1 Like

Hi,
You can use the Elastic Beanstalk Command Line Interface (EB CLI) to run the Docker containers configured in your AWS Elastic Beanstalk application locally. The EB CLI uses the Docker configuration file (Dockerfile or Dockerrun.aws.json) and source code in your project directory to run your application locally in Docker.

The EB CLI supports locally running applications defined using the Docker, Multicontainer Docker, and Preconfigured Docker platforms.