Having trouble compiling Telemetry 0.4.0 under Elixir Alpine

I’m using Phoenix 1.4.8 and I’m trying to use Distillery to compile the app inside Alpine (elixir:1.8.2-alpine). Do I need to install some library to make the compilation work? I’m using Gitlab CI to compile the app:

distillery:
  stage: build
  image: elixir:1.8.2-alpine
  cache:
    paths:
      - _build
      - deps
  before_script:
    - apk --no-cache add git
    - mix local.rebar --force
    - mix local.hex --force
    - mix deps.get
    - mix deps.compile
  script:
    - MIX_ENV=prod mix release --verbose
$ mix deps.compile
==> inflex
Compiling 6 files (.ex)
Generated inflex app
==> base64url (compile)
Compiled src/base64url.erl
==> gettext
Compiling 1 file (.erl)
Compiling 20 files (.ex)
==> jose
Compiling 90 files (.erl)
Compiling 8 files (.ex)
warning: function Poison.EncodeError.exception/1 is undefined (module Poison.EncodeError is not available)
  lib/jose/poison/lexical_encoder.ex:8

Generated jose app
===> Compiling ranch
===> Compiling telemetry
===> Uncaught error in rebar_core. Run with DEBUG=1 to see stacktrace or consult rebar3.crashdump
===> When submitting a bug report, please include the output of `rebar3 report "your command"`
==> rarex
** (Mix) Could not compile dependency :telemetry, "/root/.mix/rebar3 bare compile --paths "/builds/rarex/core/_build/dev/lib/*/ebin"" command failed. You can recompile this dependency with "mix deps.compile telemetry", update it with "mix deps.update telemetry" or clean it with "mix deps.clean telemetry"

Can you run with the environment variable DEBUG=1 or copy out the rebar3.crashdump file from the container so the error can be seen?

Here’s what I got when I ran it again:

$ DEBUG=1 mix deps.compile
==> inflex
Compiling 6 files (.ex)
Generated inflex app
==> base64url (compile)
Compiled src/base64url.erl
==> gettext
Compiling 1 file (.erl)
Compiling 20 files (.ex)
==> jose
Compiling 90 files (.erl)
Compiling 8 files (.ex)
warning: function Poison.EncodeError.exception/1 is undefined (module Poison.EncodeError is not available)
  lib/jose/poison/lexical_encoder.ex:8

Generated jose app
===> Expanded command sequence to be run: []
===> Provider: {default,do}
===> Expanded command sequence to be run: [{default,app_discovery},
                                           {bare,compile}]
===> Provider: {default,app_discovery}
===> Provider: {bare,compile}
===> Compiling ranch
===> run_hooks("/builds/rarex/core/deps/ranch", pre_hooks, compile) -> no hooks defined

===> run_hooks("/builds/rarex/core/deps/ranch", pre_hooks, erlc_compile) -> no hooks defined

===> erlopts [debug_info]
===> files to compile ["/builds/rarex/core/deps/ranch/src/ranch_app.erl",
                       "/builds/rarex/core/deps/ranch/src/ranch_acceptors_sup.erl",
                       "/builds/rarex/core/deps/ranch/src/ranch.erl",
                       "/builds/rarex/core/deps/ranch/src/ranch_crc32c.erl",
                       "/builds/rarex/core/deps/ranch/src/ranch_server.erl",
                       "/builds/rarex/core/deps/ranch/src/ranch_transport.erl",
                       "/builds/rarex/core/deps/ranch/src/ranch_protocol.erl",
                       "/builds/rarex/core/deps/ranch/src/ranch_tcp.erl",
                       "/builds/rarex/core/deps/ranch/src/ranch_conns_sup.erl",
                       "/builds/rarex/core/deps/ranch/src/ranch_sup.erl",
                       "/builds/rarex/core/deps/ranch/src/ranch_acceptor.erl",
                       "/builds/rarex/core/deps/ranch/src/ranch_listener_sup.erl",
                       "/builds/rarex/core/deps/ranch/src/ranch_proxy_header.erl",
                       "/builds/rarex/core/deps/ranch/src/ranch_ssl.erl"]
===> run_hooks("/builds/rarex/core/deps/ranch", post_hooks, erlc_compile) -> no hooks defined

===> run_hooks("/builds/rarex/core/deps/ranch", pre_hooks, app_compile) -> no hooks defined

===> run_hooks("/builds/rarex/core/deps/ranch", post_hooks, app_compile) -> no hooks defined

===> run_hooks("/builds/rarex/core/deps/ranch", post_hooks, compile) -> no hooks defined

===> Expanded command sequence to be run: []
===> Provider: {default,do}
===> Expanded command sequence to be run: [{default,app_discovery},
                                           {bare,compile}]
===> Provider: {default,app_discovery}
===> Provider: {bare,compile}
===> Compiling telemetry
===> run_hooks("/builds/rarex/core/deps/telemetry", pre_hooks, compile) -> no hooks defined

===> run_hooks("/builds/rarex/core/deps/telemetry", pre_hooks, erlc_compile) -> no hooks defined

===> erlopts [debug_info]
===> files to compile ["/builds/rarex/core/deps/telemetry/src/telemetry_app.erl",
                       "/builds/rarex/core/deps/telemetry/src/telemetry_handler_table.erl",
                       "/builds/rarex/core/deps/telemetry/src/telemetry_sup.erl",
                       "/builds/rarex/core/deps/telemetry/src/telemetry.erl"]
===> Uncaught error in rebar_core. Run with DEBUG=1 to see stacktrace or consult rebar3.crashdump
===> Uncaught error: {badmatch,{error,enoent}}
===> Stack trace to the error location:
[{rebar_erlc_compiler,modify_erlcinfo,5,
                      [{file,"/home/tristan/Devel/rebar3/_build/prod/lib/rebar/src/rebar_erlc_compiler.erl"},
                       {line,477}]},
 {rebar_erlc_compiler,'-update_erlcinfo_fun/2-fun-0-',4,
                      [{file,"/home/tristan/Devel/rebar3/_build/prod/lib/rebar/src/rebar_erlc_compiler.erl"},
                       {line,463}]},
 {lists,foldl,3,[{file,"lists.erl"},{line,1263}]},
 {rebar_erlc_compiler,update_erlcinfo,3,
                      [{file,"/home/tristan/Devel/rebar3/_build/prod/lib/rebar/src/rebar_erlc_compiler.erl"},
                       {line,448}]},
 {rebar_erlc_compiler,'-update_erlcinfo_fun/2-fun-0-',4,
                      [{file,"/home/tristan/Devel/rebar3/_build/prod/lib/rebar/src/rebar_erlc_compiler.erl"},
                       {line,463}]},
 {lists,foldl,3,[{file,"lists.erl"},{line,1263}]},
 {rebar_erlc_compiler,init_erlcinfo,4,
                      [{file,"/home/tristan/Devel/rebar3/_build/prod/lib/rebar/src/rebar_erlc_compiler.erl"},
                       {line,411}]},
 {rebar_erlc_compiler,compile_dirs,5,
                      [{file,"/home/tristan/Devel/rebar3/_build/prod/lib/rebar/src/rebar_erlc_compiler.erl"},
                       {line,195}]}]
===> When submitting a bug report, please include the output of `rebar3 report "your command"`
==> rarex
** (Mix) Could not compile dependency :telemetry, "/root/.mix/rebar3 bare compile --paths "/builds/rarex/core/_build/dev/lib/*/ebin"" command failed. You can recompile this dependency with "mix deps.compile telemetry", update it with "mix deps.update telemetry" or clean it with "mix deps.clean telemetry"

Have you tried with the cache deleted? I think this can also happen if some of what you have cached is not readable…

I haven’t tried that yet although the app I’m doing this on is pretty fresh, so I’m not sure if this is the cause. So does this mean that I don’t need to install any libraries using apk before doing the compilation?

Seeing this path in a dockerized build makes me think…

It looks like a path from your host OS, not like one I’d expect to see in the guest.

Can you please verify that you have deps and _build in your .dockerignore?

No, that is actually my path :). It is using an old prebuilt rebar3 escript that was built on my machine.

That might actually be an issue, mix local.rebar installs versions it is known to work with, you should not use a different rebar when compiling mix projects.

They aren’t, it is using the version installed my mix local.rebar.

Can you share access to the code? Or at least recreate the issue in a clean/fresh phoenix application which we could clone and experiment with?

This is unrelated to apk, I’m simply suggesting rerunning without _build and deps cached (and deleted locally in case you are including them in the context, better to put them in .dockerignore).

What deps and applications are you using? I faced what seems like it could be a similar issue that I solved by moving away from listing the applications and instead using extra_applications: https://github.com/BlakeWilliams/Elixir-Slack/pull/196

Actually looking at jose, it looks like it has the same issue

And it could be fixed by either adding :poison to the list of application or moving the the :extra_applications approach.

I’m not using Docker yet, but I removed the caching of deps and _build from gitlab-ci.yml and it works now. Thanks for pointing this out. Turns out, telemetry had nothing to do with the problem.

1 Like

I’m seeing this (occasional :telemetry compile fails) too. I’m not sure how to repro it as it seems to happen randomly once and awhile. I’ve seen it on my local OSX machine as well as on a circleci/elixir:1.9.1-node container.

The relevent part from my CircleCI config looks like this:

elixir_tests:
    docker:
      - image: circleci/elixir:1.9.1-node
    working_directory: ~/repo/api/my_app
    steps:
      - checkout:
          path: ~/repo

      - restore_cache:
          keys:
            - ex-deps-{{ checksum "mix.exs" }}-{{ checksum "mix.lock" }}
            - ex-deps-

      - run:
          name: Install hex and rebar3
          command: mix local.hex --force && mix local.rebar --force

      - run:
          name: App Dependencies
          command: MIX_ENV=test mix do deps.get --only test, deps.compile, compile

      - save_cache:
          paths:
            - deps
          key: ex-deps-{{ checksum "mix.exs" }}-{{ checksum "mix.lock" }}

      - run:
          name: ExUnit Tests
          command: mix test --cover

      - store_artifacts:
          path: cover
          destination: cover

mix deps.clean telemetry fixes it up if I SSH in and try to interactively manipulate the build.

1 Like

I had the same issue on CircleCI.

I was using a two stage workflow: building and running unit tests in one stage, and running E2E/integration tests in another stage.

They were using different Elixir docker images (1.8 vs 1.9), and when I upgraded to telemetry 0.4 it started to error on build. Using the same Docker image on both stages fixed this.

1 Like

I had the same problem. It’s not telemetry, it’s old cached files. Delete “_build” and “deps” folders and run “mix deps.get” and “mix deps.compile”. Everything ok now.