Teslamate: Contributing / Local testing setup ?

Created on 10 Sep 2019  Â·  15Comments  Â·  Source: adriankumpf/teslamate

I am new to elixir however I want to help contribute. I spent some time last weekend setting up teslamate for local development. In the process I was looking at your build scripts and other components however I couldn't get the testing and build flow working properly. Would you mind sharing how you setup teslamate for development in your environment and any tips on how to best shape pull requests?

guide question

Most helpful comment

I am new to elixir however I want to help contribute.

Awesome!

I should write documentation on how to get started. That's what I have so far:

Initial setup

Start postgres and mosquitto locally. Then download all dependencies and setup the database:

# download dependencies
mix deps.get

# create database and run migrations
mix ecto.setup

# download JavaScript dependencies
npm install --prefix ./assets

# an alias for all of the above commands which uses yarn instead of npm:
mix setup

Development

TeslaMate

Start an iex session in another terminal window:

iex -S mix phx.server

Usually I sign in with my real Tesla account. Sometimes it makes sense to use a fresh test account.

Compiling
mix compile
Hot reloading

To immediately apply your local changes open or reload http://localhost:4000. You can also reload specific modules via iex, for example:

iex> r TeslaMate.Vehicles.Vehicle
Code formatting
mix format

Grafana

I usually run Grafana with a custom docker-compose file:

_docker-compose.yml_

version: '3'
services:
  grafana:
    image: teslamate-grafana:latest
    environment:
      - DATABASE_USER=postgres
      - DATABASE_PASS=postgres
      - DATABASE_NAME=teslamate_dev
      - DATABASE_HOST=host.docker.internal
    ports:
      - 3000:3000
    volumes:
      - grafana-data:/var/lib/grafana

volumes:
    grafana-data:
# build the image
make grafana

# run the container
docker-compose up grafana

To change a dashboard edit it locally and save it as a json file at ./grafana/dashboards/.

Running tests

# initially create the test database
MIX_ENV=test mix ecto.setup

# run tests
mix test

All 15 comments

I am new to elixir however I want to help contribute.

Awesome!

I should write documentation on how to get started. That's what I have so far:

Initial setup

Start postgres and mosquitto locally. Then download all dependencies and setup the database:

# download dependencies
mix deps.get

# create database and run migrations
mix ecto.setup

# download JavaScript dependencies
npm install --prefix ./assets

# an alias for all of the above commands which uses yarn instead of npm:
mix setup

Development

TeslaMate

Start an iex session in another terminal window:

iex -S mix phx.server

Usually I sign in with my real Tesla account. Sometimes it makes sense to use a fresh test account.

Compiling
mix compile
Hot reloading

To immediately apply your local changes open or reload http://localhost:4000. You can also reload specific modules via iex, for example:

iex> r TeslaMate.Vehicles.Vehicle
Code formatting
mix format

Grafana

I usually run Grafana with a custom docker-compose file:

_docker-compose.yml_

version: '3'
services:
  grafana:
    image: teslamate-grafana:latest
    environment:
      - DATABASE_USER=postgres
      - DATABASE_PASS=postgres
      - DATABASE_NAME=teslamate_dev
      - DATABASE_HOST=host.docker.internal
    ports:
      - 3000:3000
    volumes:
      - grafana-data:/var/lib/grafana

volumes:
    grafana-data:
# build the image
make grafana

# run the container
docker-compose up grafana

To change a dashboard edit it locally and save it as a json file at ./grafana/dashboards/.

Running tests

# initially create the test database
MIX_ENV=test mix ecto.setup

# run tests
mix test

Regarding pull requests: feel free to open a PR with your changes even if it's still work in progress.

do you spin up postgres and mqtt locally with docker compose as well? if not any reason not to ?

I run both locally to to avoid the overhead of running docker (on a mac).

There is now a "Contributing" guide in the README. Please open another issue if anything seems unclear.

Thank you. Will do.

Nirmal Mehta

On Sep 17, 2019, at 3:36 PM, Adrian Kumpf notifications@github.com wrote:

Closed #158.

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.

When I run "mix deps.get", I get the following error:

** (CompileError) config/config.exs:1: module Config is not loaded and could not be found
(elixir) lib/code.ex:232: Code.eval_string/3
(mix) lib/mix/config.ex:220: Mix.Config.eval!/2

Same with "mix ecto.setup".

Which version of elixir is installed on your system? Make sure you are using the latest version (1.9).

Ah, ok. Raspbian Buster comes with 1.7. I installed 1.9.1 and it is getting better... :)

It now fails with

==> phoenix
Compiling 67 files (.ex)
17:23:39.845 [error] Loading of /usr/lib/elixir/bin/../lib/elixir/ebin/Elixir.Calendar.ISO.beam failed: :badfile
17:23:39.845 [error] beam/beam_load.c(2314): Error loading function 'Elixir.Calendar.ISO':from_unix/2: op i_plus q x p x: no specific operation found
17:23:43.316 [error] beam/beam_load.c(2314): Error loading function 'Elixir.Calendar.ISO':from_unix/2: op i_plus q x p x: no specific operation found
17:23:43.316 [error] Loading of /usr/lib/elixir/bin/../lib/elixir/ebin/Elixir.Calendar.ISO.beam failed: :badfile
== Compilation error in file lib/mix/phoenix/schema.ex ==
** (UndefinedFunctionError) function Calendar.ISO.parse_microsecond/1 is undefined (module Calendar.ISO is not available)
(elixir) Calendar.ISO.parse_microsecond("")
(elixir) lib/calendar/naive_datetime.ex:556: NaiveDateTime.raw_from_iso8601/2
(elixir) lib/calendar/naive_datetime.ex:587: NaiveDateTime.from_iso8601!/2
(elixir) expanding macro: Kernel.sigil_N/2
lib/mix/phoenix/schema.ex:216: Mix.Phoenix.Schema.type_to_default/3

Appears to be an issue with Erlang 22. @adriankumpf Are you using Erlang 21?

Looks like an issue with Erlang/OTP 22 on 32bit architectures like the Raspberry Pi: https://github.com/phoenixframework/phoenix/issues/3478 Any success with OTP 21?

According to this post: https://elixirforum.com/t/cant-import-calendar-iso-on-raspberry-pi/23004/3 installing erlang and elixir with the asdf version manager solves the issue. Alternatively OTP 21 should work:

I was able to use it with (ESL) Erlang/OTP21:

sudo apt remove -y esl-erlang && sudo apt autoremove
sudo apt install -y esl-erlang=1:21.3.3-1
sudo apt-mark hold esl-erlang # prevents apt from updating the package
sudo apt install -y elixir

Right, I already tried it with Erlang 21, but (and also with the above approach) I get

09:57:08.401 [error] beam/beam_load.c(1878): Error loading module telemetry_handler_table:
This BEAM file was compiled for a later version of the run-time system than 21.

Ok, fixed by rm -rf deps _build and starting all over.

Ok, teslamate and grafana up and running. Grafana gives me an error: dial tcp: lookup host.docker.internal on 127.0.0.11:53: no such host.

The 11 in that looks strange. No idea yet, where it comes from.

It turns out, that host.docker.internal does not work under Linux.

So, you have to use the local network name or IP address for DATABASE_HOST. And allow access to postgresql for the docker IP.

Good to know! I updated the README accordingly.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DrMichael picture DrMichael  Â·  4Comments

olivercho picture olivercho  Â·  4Comments

russinating picture russinating  Â·  4Comments

Try2Fly picture Try2Fly  Â·  5Comments

virtualm2000 picture virtualm2000  Â·  4Comments