Deployment to Google Compute Engine

deployment
compute-engine

#61

In your hello-builder, before you build the release, please add this:

rm -rf deps _build
mix do deps.get, deps.compile

This will ensure that the dependencies will be cleaned and refetched prior to the build and does not rely anymore on you doing it manually.


#62

Dockerfile

FROM elixir:latest
WORKDIR /app
RUN mix local.rebar --force && mix local.hex --force
RUN rm -rf deps _build
RUN mix do deps.get, deps.compile
ENV MIX_ENV=prod REPLACE_OS_VARS=true TERM=xterm
CMD ["mix", "release", "--env=prod", "--executable", "--verbose"]
Muhammads-MacBook-Pro:builder Azim$ docker build -t hello-builder .
Sending build context to Docker daemon  4.096kB
Step 1/7 : FROM elixir:latest
 ---> 46c8f1ed0132
Step 2/7 : WORKDIR /app
 ---> Using cache
 ---> 3f18f38e96fb
Step 3/7 : RUN mix local.rebar --force && mix local.hex --force
 ---> Using cache
 ---> b3cf53fe75bc
Step 4/7 : RUN rm -rf deps _build
 ---> Using cache
 ---> eb87150a83b8
Step 5/7 : RUN mix do deps.get, deps.compile, compile
 ---> Running in f80f7f74a82a
** (Mix) Could not find a Mix.Project, please ensure you are running Mix in a directory with a mix.exs file
The command '/bin/sh -c mix do deps.get, deps.compile, compile' returned a non-zero code: 1

Im getting this


#63

Oh… hello.-builder was the name of your docker image, not that one of a script. Clearly my fault for not reading correctly…

Please remove the lines I told you to add, and change the CMD to this:

CMD ["mix",  "do",  "deps.get,", "deps.compile,", "compile,", "release", "--env=prod", "--executable", "--verbose"]

That should do it, plus/minus some syntax error I hacked because I’m on a mobile :wink:


#64

Its the same error like before Elixir.Bcrypt.Base :sweat:

My latest Dockerfile

FROM elixir:latest
WORKDIR /app
RUN mix local.rebar --force && mix local.hex --force
RUN rm -rf deps _build
ENV MIX_ENV=prod REPLACE_OS_VARS=true TERM=xterm
CMD ["mix", "do", "deps.get,", "deps.compile,", "compile,", "release", "--env=prod", "--executable", "--verbose"]

I notice after I docker run --rm -it -v $(pwd):/app hello-builder it will rebuild _build/prod/rel/hello/bin/hello.run
After it finish building it, I deleted the /tmp folder and try running it locally on my Mac PORT=8080 _build/prod/rel/hello/bin/hello.run foreground

Muhammads-MacBook-Pro:hello Azim$ PORT=8080 _build/prod/rel/hello/bin/hello.run foreground
/Users/Azim/Phoenix/hello/tmp/hello/erts-10.2.1/bin/erl: line 13: /Users/Azim/Phoenix/hello/tmp/hello/erts-10.2.1/bin/erlexec: cannot execute binary file
/Users/Azim/Phoenix/hello/tmp/hello/erts-10.2.1/bin/erl: line 13: /Users/Azim/Phoenix/hello/tmp/hello/erts-10.2.1/bin/erlexec: Undefined error: 0
Unusable Erlang runtime system! This is likely due to being compiled for another system than the host is running

Is that suppose to happen after I build it using docker?


#65

Yes, this is supposed to happen.

Have you deleted deps before your recent docker run?

This is an important step that you need to do manually before running the docker, since you are using a volume and we can not currently put it in your entry point easily.


#66

FINALLY! IT WORKS! :tada: :partying_face:

I did run itself after I create the GCE instance

I tried again and make sure deps is deleted and re-run the docker run

Thank you to you and @dazuma for helping me. Im very grateful for your help :pray:
Im so happy

I do want to learn your way if you are okay with it


#67

@azimlord Great to hear!

@NobbZ Thank you very much for your help on this! I’ve filed a work item to update the tutorial to use docker cp instead of mounting a volume.


#68

Looking forward for the update

Thank you very much :smile: