We are sometimes faced with use cases where we need to mix different technologies to run our apps. This became such a common use case that it is now fundamental to the micro-services architecture. We tend to mix technologies to create the most powerful environment possible.
One of the most powerful (and, sadly less known) parts of alwaysdata’s architecture is the environment version switcher!
alwaysdata aims to provide a wide range of interpreters: PHP, Python, Node.js, Ruby, Erlang even Perl are all supported in your alwaysdata account from scratch. But sometimes we need a specific version of an interpreter. What if you need to run an application that requires a minimum version of an interpreter? Let’s say, Node.js 10? Fact is, you account is pre-provisioned with a wide range of versions for each interpreter. E.g., Node.js comes with all the following versions (at the time of writing):
Wow. That’s a lot!
Now, I can specify the version I want to use by using the environment version switcher:
$ NODEJS_VERSION=11.8.0 node --version
I can also be less specific and stick to the latest major version of a given release:
$ NODEJS_VERSION=11 node --version
The environment version switcher is available for all interpreters embedded in your account:
PHP_VERSION, and so on. You can retrieve a list of all available versions int the dedicated language page in your admin panel: Environment > [language].
Mix’em all: The Kresus use-case
Let’s view this in action with the Kresus project. Kresus is a personal finance manager that can connect to your online bank account using a dedicated library: Weboob. All of this is self-hosted, a mandatory feature if you care for your privacy.
But Kresus is written in Node.js and expects a
node version >= 10, while Weboob is written in Python and requires a
python >= 3. So let’s mix’em together!
Connect to your account using SSH, and create a directory to host the project:
$ mkdir ~/kresus
$ cd ~/kresus
We will create a Python virtualenv for Weboob that will host the library and its components:
$ PYTHON_VERSION=3 python -m venv ~/kresus/weboob
$ source ~/kresus/weboob/bin/activate
(weboob) $ pip install git+https://git.weboob.org/weboob/weboob.git
(weboob) $ weboob-config update
(weboob) $ deactivate
Now we are ready to install the Kresus manager. We first need to install the
yarn package manager, as Kresus relies on this for build tasks:
$ NODEJS_VERSION=12 npm install --global yarn
Yes, that’s another powerful feature of alwaysdata PaaS: even if you’re not
root, you can install the dependencies globally! Thanks to our wrapping features, everything is sandboxed in your account, and seen as a system-wide tools by your packages managers!
Let’s install the project now:
$ git clone https://framagit.org/kresusapp/kresus.git ~/kresus/app
$ cd ~/kresus/app
$ NODEJS_VERSION=12 npm install
$ NODEJS_VERSION=12 npm run build:prod
Now we’re ready to run the service!
Create a new site in your admin panel at Web > Sites > Add a site. Select a Node.js site, and specify the
Here are the parameters:
- Working directory:
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 substitute the following values:
IP: the IPv4 the app should listen to, indicated under the Command field. It’s specific for each app, and Node.js apps expect it to be exposed by the HOST environment variable
username: your account username at alwaysdata
long random string: a random string with at least 16 chars used by Kresus for sessions 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 visiting the site URL. The first connection may take a small amount of time due to the initialization of the DB, as well as the first bank account retrieval. Grab a coffee and be patient.
This is just a small example of the powerful features we offer at alwaysdata.
Over the next few weeks, we will be migrating our platform to a new version and introducing a new wrapping feature that will allow you to access your version of choice of any interpreter. The environment version switcher will remain available, but soon you will be able to run
python3.7 directly rather than using environment variables.
See you in a few weeks for this new feature! In the meantime, run your own instance of Kresus!