Written by

We are some­times faced with use cas­es where we need to mix dif­fer­ent tech­nolo­gies to run our apps. This became such a com­mon use case that it is now fun­da­men­tal to the micro-ser­vices archi­tec­ture. We tend to mix tech­nolo­gies to cre­ate the most pow­er­ful envi­ron­ment possible.

Running different versions of the same interpreter

One of the most pow­er­ful (and, sad­ly less known) parts of alwaysdata’s archi­tec­ture is the envi­ron­ment ver­sion switch­er!

always­da­ta aims to pro­vide a wide range of inter­preters: PHP, Python, Node.js, Ruby, Erlang even Perl are all sup­port­ed in your always­da­ta account from scratch. But some­times we need a spe­cif­ic ver­sion of an inter­preter. What if you need to run an appli­ca­tion that requires a min­i­mum ver­sion of an inter­preter? Let’s say, Node.js 10? Fact is, you account is pre-pro­vi­sioned with a wide range of ver­sions for each inter­preter. E.g., Node.js comes with all the fol­low­ing ver­sions (at the time of writing):

  • 12.0.0
  • 11.12.0
  • 11.8.0
  • 11.1.0
  • 11.0.0
  • 10.15.3
  • 10.15.1
  • 10.13.0
  • 10.12.0
  • 10.9.0
  • 9.11.2
  • 8.15.1
  • 8.15.0
  • 8.12.0
  • 8.11.4
  • 6.17.0
  • 6.16.0
  • 6.14.4

Wow. That’s a lot!

Now, I can spec­i­fy the ver­sion I want to use by using the envi­ron­ment ver­sion switch­er:

I can also be less spe­cif­ic and stick to the lat­est major ver­sion of a giv­en release:

The envi­ron­ment ver­sion switch­er is avail­able for all inter­preters embed­ded in your account: PYTHON_VERSION, PHP_VERSION, and so on. You can retrieve a list of all avail­able ver­sions int the ded­i­cat­ed lan­guage page in your admin pan­el: Environment > [lan­guage].

Mix’em all: The Kresus use-case

Let’s view this in action with the Kresus project. Kresus is a per­son­al finance man­ag­er that can con­nect to your online bank account using a ded­i­cat­ed library: Weboob. All of this is self-host­ed, a manda­to­ry fea­ture if you care for your pri­va­cy.

But Kresus is writ­ten in Node.js and expects a node ver­sion >= 10, while Weboob is writ­ten in Python and requires a python >= 3. So let’s mix’em together!

Kresus : Accounts view
Kresus : Accounts view

Connect to your account using SSH, and cre­ate a direc­to­ry to host the project:

Install Weboob

We will cre­ate a Python vir­tualenv for Weboob that will host the library and its components:

Install Kresus

Now we are ready to install the Kresus man­ag­er. We first need to install the yarn pack­age man­ag­er, as Kresus relies on this for build tasks:

Yes, that’s anoth­er pow­er­ful fea­ture of always­da­ta PaaS: even if you’re not root, you can install the depen­den­cies glob­al­ly! Thanks to our wrap­ping fea­tures, every­thing is sand­boxed in your account, and seen as a sys­tem-wide tools by your pack­ages managers!

Let’s install the project now:

Launch the service

Now we’re ready to run the service!

Create a new site in your admin pan­el at Web > Sites > Add a site. Select a Node.js site, and spec­i­fy the 12.0.0 version.

Admin panel: Node.js website
Admin pan­el: Node.js website

Here are the parameters:

  • Command: node bin/kresus
  • Working direc­to­ry: kresus/app
  • Environment: NODE_ENV=production HOST=[IP] KRESUS_DIR=/home/[username]/kresus/data KRESUS_PYTHON_EXEC=/home/[username]/kresus/weboob/bin/python KRESUS_SALT=[long random string]

Make sure to sub­sti­tute the fol­low­ing values:

  • IP: the IPv4 the app should lis­ten to, indi­cat­ed under the Command field. It’s spe­cif­ic for each app, and Node.js apps expect it to be exposed by the HOST envi­ron­ment variable
  • username: your account user­name at alwaysdata
  • long random string: a ran­dom string with at least 16 chars used by Kresus for ses­sions purposes

You may also check the Force HTTPS usage in the SSL tab to ensure a secured connection.

And that’s it. Launch your app by vis­it­ing the site URL. The first con­nec­tion may take a small amount of time due to the ini­tial­iza­tion of the DB, as well as the first bank account retrieval. Grab a cof­fee and be patient.

This is just a small exam­ple of the pow­er­ful fea­tures we offer at alwaysdata.

Over the next few weeks, we will be migrat­ing our plat­form to a new ver­sion and intro­duc­ing a new wrap­ping fea­ture that will allow you to access your ver­sion of choice of any inter­preter. The envi­ron­ment ver­sion switch­er will remain avail­able, but soon you will be able to run node12 or python3.7 direct­ly rather than using envi­ron­ment variables.

See you in a few weeks for this new fea­ture! In the mean­time, run your own instance of Kresus!