elixirdistillery

Deploy with single file using distillery?


Background

I have an OTP Application that I now need to deploy. To achieve this, I am using distillery. My objective is to pass a self-sufficient file to the PROD machine that contains everything and doesn’t need to be extracted.

The usual route

Most people using distillery will know the usual route:

  1. Run MIX_ENV=prod mix release
  2. Copy the tarball in build/prod/rel/<name>/releases/<version>/<name>.tar.gz to the deploy server
  3. Extract the tarbal
  4. Run the code.

Objective

My objective is to eliminate step 3. I don’t want to extract anything, I just want to copy the release and run it, like a sudo executable.

–executable

According to the documentation one can also run MIX_ENV=prod mix release --executable or MIX_ENV=prod mix release --transient. This will create a pseudo executable file that doesn’t need to be extracted.

Question

However, after running the MIX_ENV=prod mix release --executable command, I usually search the file build/prod/rel/<name>/releases/<version>/<name>.run. In theory this should be the file I need to copy into my deploy server but I can’t find it anywhere.


Solution

  • Try double checking what you're doing. For reference, I just tried this, and it worked fine. I'm using Elixir 1.7.4 and distillery 2.0.12.

    Here's what I did:

    1. create a new project:

      mix new test_executable --sup
      
    2. added distillery to mix.exs,

    3. ran

      mix release.init
      
    4. ran:

      env MIX_ENV=prod mix release --executable
      

      Got this output:

      ==> Assembling release..
      ==> Building release test_executable:0.1.0 using environment prod
      ==> Including ERTS 10.2 from /usr/local/Cellar/erlang/21.2/lib/erlang/erts-10.2
      ==> Packaging release..
      Release successfully built!
      To start the release you have built, you can use one of the following tasks:
      
          # start a shell, like 'iex -S mix'
          > _build/prod/rel/test_executable/bin/test_executable.run console
      
          # start in the foreground, like 'mix run --no-halt'
          > _build/prod/rel/test_executable/bin/test_executable.run foreground
      
          # start in the background, must be stopped with the 'stop' command
          > _build/prod/rel/test_executable/bin/test_executable.run start
      
      If you started a release elsewhere, and wish to connect to it:
      
          # connects a local shell to the running node
          > _build/prod/rel/test_executable/bin/test_executable.run remote_console
      
          # connects directly to the running node's console
          > _build/prod/rel/test_executable/bin/test_executable.run attach
      
      For a complete listing of commands and their use:
      
          > _build/prod/rel/test_executable/bin/test_executable.run help
      
    5. I can now copy the file elsewhere and run it:

      cp _build/prod/rel/test_executable/bin/test_executable.run /tmp
      cd /tmp
      ./test_executable.run console
      Erlang/OTP 21 [erts-10.2] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [hipe] [dtrace]
      
      Interactive Elixir (1.7.4) - press Ctrl+C to exit (type h() ENTER for help)
      iex(test_executable@127.0.0.1)1>