I have a small nerves project locally that I would like to write tests for. The tests won’t interact with hardware, they will test functions I wrote to handle data from sensors. Gitlab’s CI infrastructure is what I will be using, and I have other Elixir projects running on it successfully. That being said, I cannot get my nerves project to run. My .gitlab-ci.yml file and error is below. I did move the archive.install command around a bit to test out a theory, it yielded no results. It appears Nerves isn’t installed and trying to install it (or any mix commands) throws errors about it not being installed
.gitlab-ci.yml
image: elixir:1.6
variables:
MIX_ENV: "test"
MIX_TARGET: "rpi3"
stages:
- test
before_script:
- apt-get -qq update && apt-get install -y ssh-askpass squashfs-tools git g++ libssl-dev libncurses5-dev bc m4 make unzip cmake python
- mix local.hex --force
- mix local.rebar --force
- mix archive.install hex nerves_bootstrap
- mix local.nerves
- mix deps.get --only test
unit-testing:
stage: test
script:
- mix test
Error
$ mix archive.install hex nerves_bootstrap
Mix environment
MIX_TARGET: rpi3
MIX_ENV: test
** (UndefinedFunctionError) function Nerves.Bootstrap.add_aliases/1 is undefined (module Nerves.Bootstrap is not available)
Nerves.Bootstrap.add_aliases([])
mix.exs:28: LakeEffect.MixProject.project/0
(mix) lib/mix/project.ex:676: Mix.Project.get_project_config/1
(mix) lib/mix/project.ex:111: Mix.Project.push/3
(stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
ERROR: Job failed: exit code 1
You are calling into nerves bootstrap from your mix file? That means you have to install bootstrap before mix file is available (in case of emergency just move a dirlevel up for installing the archive.
Thanks, you were spot on! Getting close, trying to get past the compiler error now. build-essential and erlang-dev packages are being installed. Updated gitlab-ci.yml file and error below.
gitlab-ci.yml
image: elixir:1.6
variables:
MIX_ENV: "test"
MIX_TARGET: "rpi3"
stages:
- test
before_script:
- 'echo `pwd`'
- apt-get -qq update && apt-get install -y ssh-askpass squashfs-tools git g++ libssl-dev libncurses5-dev bc m4 make unzip cmake python build-essential erlang-dev
- cd /srv && mix local.hex --force
- cd /srv && mix local.rebar --force
- cd /srv && mix archive.install --force hex nerves_bootstrap
# - mix local.nerves --force
- 'cd $CI_PROJECT_DIR && mix deps.get --only test'
unit-testing:
stage: test
script:
- mix test
Error
==> nerves_runtime
mkdir -p priv
/root/.nerves/artifacts/nerves_toolchain_arm_unknown_linux_gnueabihf-linux_x86_64-0.13.0/bin/arm-unknown-linux-gnueabihf-gcc -c -I/root/.nerves/artifacts/nerves_system_rpi3-portable-0.20.0/staging/usr/lib/erlang/erts-9.2/include -I/root/.nerves/artifacts/nerves_system_rpi3-portable-0.20.0/staging/usr/lib/erlang/lib/erl_interface-3.10.1/include -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -pipe -Os -I/root/.nerves/artifacts/nerves_system_rpi3-portable-0.20.0/staging/usr/include -std=gnu99 -o src/uevent.o src/uevent.c
/root/.nerves/artifacts/nerves_toolchain_arm_unknown_linux_gnueabihf-linux_x86_64-0.13.0/bin/arm-unknown-linux-gnueabihf-gcc: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by /root/.nerves/artifacts/nerves_toolchain_arm_unknown_linux_gnueabihf-linux_x86_64-0.13.0/bin/arm-unknown-linux-gnueabihf-gcc)
Makefile:66: recipe for target 'src/uevent.o' failed
make: *** [src/uevent.o] Error 1
could not compile dependency :nerves_runtime, "mix compile" failed. You can recompile this dependency with "mix deps.compile nerves_runtime", update it with "mix deps.update nerves_runtime" or clean it with "mix deps.clean nerves_runtime"
==> lake_effect
** (Mix) Could not compile with "make" (exit status: 2).
Depending on your OS, make sure to follow these instructions:
* Mac OS X: You need to have gcc and make installed. Try running the
commands "gcc --version" and / or "make --version". If these programs
are not installed, you will be prompted to install them.
* Linux: You need to have gcc and make installed. If you are using
Ubuntu or any other Debian-based system, install the packages
"build-essential". Also install "erlang-dev" package if not
included in your Erlang/OTP version. If you're on Fedora, run
"dnf group install 'Development Tools'".
ERROR: Job failed: exit code 1
One thing I notice is that you have MIX_TARGET set to rpi3, which will end up cross-compiling things to run on Raspberry Pi 3 (ARM CPU). Unless your goal is to build firmware in CI, this probably isn’t what you want because your CI server won’t be able to run the tests.
Thanks for pointing that out Greg, I copied over the local config I had and didn’t think about the proper target. After looking through the target docs, x86_64 is the correct target. Digging into the compiler issues, and it seems to be related to version issues at the distro level, still need to dig more.
Ah sorry, I should have clarified. I think you should set MIX_TARGET to host, which should disable all the Nerves magic and allow you to just test the modules you want to. You’ll need to check your mix.exs to make sure that you’re not loading any dependencies in host mode that depend on real hardware being there.
No worries, I appreciate the help! I really do need to sit down and read all the documentation instead of picking and choosing based on my current needs.