All Projects → kentaro → mix_tasks_upload_hotswap

kentaro / mix_tasks_upload_hotswap

Licence: MIT license
Deploy local code changes to the remote node(s) in a hot-code-swapping manner

Programming Languages

elixir
2628 projects
HTML
75241 projects

Labels

Projects that are alternatives of or similar to mix tasks upload hotswap

inky
A library for managing Inky e-ink displays from Elixir.
Stars: ✭ 60 (+93.55%)
Mutual labels:  nerves
Nerves
Craft and deploy bulletproof embedded software in Elixir
Stars: ✭ 1,778 (+5635.48%)
Mutual labels:  nerves
pigpiox
An Elixir wrapper around pigpiod for the Raspberry PI
Stars: ✭ 29 (-6.45%)
Mutual labels:  nerves
kiwi
Kiwi turns your Pimoroni Keybow into a fully customizable poor-man's Elgato Stream Deck!
Stars: ✭ 40 (+29.03%)
Mutual labels:  nerves
nerves livebook
Develop on embedded devices with Livebook and Nerves
Stars: ✭ 135 (+335.48%)
Mutual labels:  nerves
scenic asteroids
A toy Asteroids clone written in Elixir with the Scenic UI library
Stars: ✭ 42 (+35.48%)
Mutual labels:  nerves
nerves init gadget
Simple initialization for devices running Nerves
Stars: ✭ 53 (+70.97%)
Mutual labels:  nerves
shoehorn
Handle OTP application failures without restarting the Erlang VM
Stars: ✭ 36 (+16.13%)
Mutual labels:  nerves
grovepi
Use the GrovePi in Elixir
Stars: ✭ 46 (+48.39%)
Mutual labels:  nerves
hap
A HomeKit Accessory Protocol (HAP) Implementation for Elixir
Stars: ✭ 50 (+61.29%)
Mutual labels:  nerves
nerves system ev3
Base Nerves system configuration for the Lego EV3
Stars: ✭ 23 (-25.81%)
Mutual labels:  nerves
elixir bme680
An Elixir library to interface with the BME680 (and BME280) environmental sensor
Stars: ✭ 19 (-38.71%)
Mutual labels:  nerves
elixir-opencv
OpenCv NIF Bindings for Erlang/Elixir.
Stars: ✭ 30 (-3.23%)
Mutual labels:  nerves
nerves thermal camera
Thermal camera imaging with Elixir, Nerves, Raspberry Pi, and a MLX90640 sensor
Stars: ✭ 28 (-9.68%)
Mutual labels:  nerves
mdns lite
A simple, no frills mDNS implementation in Elixir
Stars: ✭ 29 (-6.45%)
Mutual labels:  nerves

Mix.Tasks.Upload.Hotswap hex.pm version

This package provides a mix task named mix upload.hotswap to deploy local code changes to remote node(s) and to apply them without rebooting whole the application (the so-called hot code swapping).

It could be convenient when you code for IoT devices backed by Nerves because it's much faster than mix firmware && mix upload. Although you eventually need to update the firmware if you want to persist the changes onto devices, this task could be your help in development phase because it allows you to quickly confirm if your changes work fine on the devices without waiting long time.

Installation

Add mix_tasks_upload_hotswap to your list of dependencies in mix.exs:

def deps do
  [
    {:mix_tasks_upload_hotswap, "~> 0.1.0", only: :dev}
  ]
end

Prerequisites

To use this package, you need to meet the requirements below:

  1. Add configurations for mix upload.hotswap
  2. Start node(s) on your device(s) through which your code changes are deployed

1. Add configurations for mix upload.hotswap

The task mix upload.hotswap depends on the settings below are available:

config :mix_tasks_upload_hotswap,
  app_name: :example,
  nodes: [:"[email protected]"],
  cookie: :"secret token shared between nodes"

All the pairs above are required to be set.

See example/config/config.exs for working example.

2. Start node(s) on your device(s) through which your code changes are deployed

Start a node which has the name and cookie set in the configuration above. The code should be like below:

# Start a node through which local code changes are deployed
# only when the device is running in the develop environment
if Application.get_env(:example, :env) == :dev do
  System.cmd("epmd", ["-daemon"])
  Node.start(:"[email protected]")
  Node.set_cookie(Application.get_env(:mix_tasks_upload_hotswap, :cookie))
end

Notice that the node starts only when the :env of the application is set to :dev. Below is an example to configure the environment value in config.exs:

config :example, env: Mix.env()

See example/lib/example/application.ex and example/config/config.exs for working example.

Usage

Mix Task

Make some changes into your code and just execute the mix task as below:

$ mix upload.hotswap

Illustration by Example App

Imagine there is an Example application which has hello method as below:

def hello do
  :world
end

You can confirm the method invoked on your device:

$ ssh nerves.local
(snip)

iex([email protected])1> Example.hello
:world

Suppose you made some changes like below:

diff --git a/example/lib/example.ex b/example/lib/example.ex
index ca49896..81c696a 100644
--- a/example/lib/example.ex
+++ b/example/lib/example.ex
@@ -13,6 +13,6 @@ defmodule Example do

   """
   def hello do
-    :world
+    :"new world"
   end
 end

You can deploy the changes to the device as below:

$ mix upload.hotswap
==> nerves
==> example

Nerves environment
  MIX_TARGET:   rpi3
  MIX_ENV:      dev

Compiling 2 files (.ex)
Generated example app
Successfully connected to [email protected]
Successfully deployed Elixir.Example to [email protected]
Successfully deployed Elixir.Example.Application to [email protected]

Now you can see the changes applied into the code on the device:

$ ssh nerves.local
(snip)

iex([email protected])1> Example.hello
:"new world"

It's much faster than mix firmware && mix upload.

Acknowledgement

Using Erlang Distribution to test hardware - Embedded Elixir inspired me how to implement this package.

Author

Kentaro Kuribayashi

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].