Category Archives: Elixir

Elixir + Phoenixframework + Heroku (SpawnViewer Updated)

http://www.phoenixframework.org/
https://github.com/parroty/spawn_viewer

As an exercise for catching up latest Phoenixframework features, I’ve updated an fairly old heroku app to the latest (v0.4.0 -> v1.1.1) version. It was harder than expected, and leaving some struggle notes here.

  • Basically, the official document (http://www.phoenixframework.org/docs/heroku) covers the procedure to deploy phoenix application to heroku.
    • Struggled on the error around missing config/prod.secret.exs which is described in the document.
    • Also, there’re some configuration settings required around config/prod.exs and it seems difficult to apply heroku button with fixed parameters.
    • As phoenix requires node verison >= 5.0, and node_version in phoenix_static_buildpack.config needed to be specified by following the buildpack README description.
  • The controller’s json/2 expects data model which Poison can encode into JSON (changed from JSON data itself). I was using exjsx and needed to change the data accordingly as keyword lists couldn’t be encoded.
  • Reloading pages seems not working on Chrome + Ghostery, and just showing blank. It was confusing for isolating the issues.
  • New asset compilation with Brunch was a difficult for me, as I don’t much experience on JS developments. The js files using global variables (highlight.js) needed to be stored in vendor directory instead of js as in the following document.

Anyway, re-realized upgrading from actively developed v0.x.y framework is very hard…

Elixir on CircleCI – Updated

I once configured elixir build at CircleCI (Elixir on CircleCI), but haven’t been able to update it. As some of the builds are failing, I’ve updated the configurations as follows.

CircleCI doesn’t seem supports erlang/elixir builds, but there’s nice library (asdf) to configure specified versions of them. The 1st time build takes time, but caching works well and 2nd time or later becomes fast enough.

Reading – Programming Phoenix

https://pragprog.com/book/phoenix/programming-phoenix

Just completed reading through the B2.0 of “Programming Phoenix” book during the weekend. I hadn’t been able to use phoenix some time since pre-1.0, but this book was a good material for catching up the latest features.

The book starts with the strong statements about the benefits of phoenix and underlying elixir, as in the subtitle – Productive |> Reliable |> Fast. Then, the main content explains the features by gradually building up simple and concise application called Rumbl. Building up standard CRUD operations to user models backed by Ecto with postgreSQL DB, and implementing authentication using the model didn’t take long and it was a good exercise.

Definitely looking for the remaining part to complete, which includes the web-socket channel.

Watching – Elixir Conf 2015 Videos (1)

http://confreaks.tv/events/elixirconf2015

I’ve started watching the session videos of elixir conf. I really wanted to join the conference if possible, but it’s good that I can watch every session online.

Keynote Рfrom Jos̩ Valim

http://confreaks.tv/videos/elixirconf2015-keynote

Recent history of extended elixir capability, and coming future enhancements.

The recently added mix profile.fprof provides nice and easy interface for profiling. The fprof of erlang is somewhat cryptic and difficult to start using. The new ex_doc styling is getting nicer, along some other improvements.

Also, the coming future features like pipeline parallelism and GenRouter will be more extending the capabilities in parallel and distributed system, which sounds promising.

Keynote: Elixir Should Take Over the World – from Jessica Kerr

http://confreaks.tv/videos/elixirconf2015-keynote-elixir-should-take-over-the-world

It might be one of the best talk with insightful ideas and encouraging statements. It introduces the power of elixir by comparing with historical progress in physics. It’s an insightful talk about how progress is being introduced, and how it relates to computer and programming architecture. The history shows always new ideas are coming and we need to keep thinking about what’s coming next.

Elixir has strong powers of

  • Functional Programming : Immutability with data flow through actors
  • Object Oriented : Independency in processes and message communication between actors
  • Errors : Isolation with crash and recovery mechanism

which is enforced by the related ideas and technologies coming in this age. One remaining part is the People to spread the idea to the world, which elixir is improving at the moment. Elixir is providing different paradigm and it imposes certain difficulty, and sharing various types of experiences at different levels helps new-comers to improve themselves.

HackerNews API on Firebase + Elixir

Hacker News API

Received Hacker News API relase mail on Firebase, and just tried out with ExFirebase, though it’s not so much interesting one.

Elixir + OAuth 2.0 Client

https://github.com/parroty/oauth2ex

I was trying to playing around Google’s BigQuery, but couldn’t make it work around OAuth 2.0 authentication with Elixir.
It provides limited functionalities yet, but the above oauth2ex provides some authentication features with some OAuth 2.0 providers like Google, GitHub and Dropbox.

Using OAuth 2.0 to Access Google APIs has detailed explanation, and it’s pretty much complex. There’re a lot too learn around authentication technologies.

Elixir + Heroku Button

Introducing Heroku Button

Heroku recently announced “Deploy to Heroku” button. I just tried it out with spawn_viewer, which is a simple application built with elixir + phoenix. If you’ve already set-up heroku account, the following button would work.

Deploy

Also, I’ve placed a link to the github readme too.

https://github.com/parroty/spawn_viewer

It’s pretty much an easy way to try out an application without messing up with local environment.

Docker + Elixir + Phoenixframework

Just playing around docker and elixir. The followings are some notes about deploying sample phoenixframework application on docker.

Deploying using Vagrant is just adding the recipe to the chef.run_list.

config.vm.provision :chef_solo do |chef|
  ...
  chef.run_list = [
    "recipe[docker]",
    "recipe[chef-docker-spawn-viewer]"
  ]

Notes

Creating Eixir Container for Docker

https://github.com/parroty/docker-elixir/blob/master/Dockerfile

It’s just installing the erlang pack and then build elixir.

# Install base package
RUN apt-get update
RUN apt-get install -y wget git build-essential

# Install Erlang
RUN wget http://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb
RUN dpkg -i erlang-solutions_1.0_all.deb
RUN apt-get update
RUN apt-get install -y erlang

# Install Elixir
WORKDIR /tmp/elixir-build
RUN git clone https://github.com/elixir-lang/elixir.git
WORKDIR elixir
RUN git checkout v0.14.2 && make && make install

Creating Phoenix Application Container for Docker

https://github.com/parroty/docker-spawn-viewer

It’s about fetching git repo and comple and start with “mix run” with “–no-halt” option. I’ve used phoenix-docker-example as reference.

## Prerequisites ##
RUN mix do local.rebar, local.hex --force

## Fetch the phoenix application ##
WORKDIR /usr/local/lib
RUN git clone https://github.com/parroty/spawn_viewer.git

## Compile ##
WORKDIR spawn_viewer
RUN mix do deps.get, compile

CMD ["mix", "run", "-e", "SpawnViewer.Router.start", "--no-deps-check", "--no-compile", "--no-halt"]

EXPOSE 4000

Deploying Phoenix Application using Chef

https://github.com/parroty/chef-docker-spawn-viewer

chef-dooker makes it pretty easy to configure parameters for docker deployment.

# Pull latest image
docker_image 'parroty/docker-spawn-viewer'

# Run container exposing ports
docker_container 'parroty/docker-spawn-viewer' do
  detach true
  port '4000:4000'
end

Elixir on CircleCI

Note: Related newer post is at Elixir on CircleCI – Updated

Just made small trial on CircleCI and elixir combination, and taking some notes here.

Though the CircleCI doesn’t have latest erlang/elixir installed, it can be installed as the custom configuration through circle.yml. It takes some time initially, but applying cache makes it pretty much fast for normal code deployments.

Comparing with TravisCI, detection of updates in GitHub and build processing seems pretty much fast, though there’s no free version on CircleCI. It may be a good option for private repositories.

The configuration is messy, but the following is the working example with very simple elixir codes (tested on erlang 17.0 and elixir v0.14.2-dev).

https://github.com/parroty/circle_sample

Elixir – Spawn Viewer

https://github.com/parroty/spawn_viewer

Playing around the process spawning of Erlang/Elixir. It’s an interesting framework, but I faced some difficulties to understand the concept initially. So, I was looking for a way to visually confirming the behavior and implemented a simple GUI. It’s preliminary yet, and might add more function later.

  • It uses Google Chart to show timeline of process behaviors. For easier to make graph, delay is inserted in the spawn processing.
  • It uses highlight.js to display Elixir codes.