Run MeasureThat.net application on Linux: building and running the application

In this post I will show how to run MeasureThat.net application on Linux (Ubuntu 16.04 in particular)
MeasureThat is the open source application that allows users to write and run JavaScript microbenchmarks.

It is written with .Net Core, the new cross-platform framework from Microsoft.
Actual MeasureThat.net application is hosted in the Microsoft Azure. It uses SQL Server as a database.

But it is possible to run the exact same application on the Linux machine using PostgreSQL as a database.
This post shows how it can be done.

Prerequisites

To be able to follow the steps described here you will need to have machine with Linux installed. I used Virtual Machine with Ubuntu 16.04:

1
2
3
4
5
6
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.1 LTS
Release: 16.04
Codename: xenial

Here is how I created the VM

Also some additional software is needed, like: .net core, git, nodejs, bower, npm, gulp, PostgreSQL.
Follow the directions described in the other post if you need to install any of those: installing prerequisites (node, .net code, PostgreSQL, git, npm, gulp, bower)

Lets get started.

Check out the application’s source code:

Open the terminal window. Create folder source for the application and check out the code:

1
2
3
4
5
6
7
8
9
10
11
$ mkdir source
$ cd source/
$ git clone https://github.com/thecoderok/MeasureThat.net.git
Cloning into 'MeasureThat.net'...
remote: Counting objects: 2324, done.
remote: Compressing objects: 100% (17/17), done.
remote: Total 2324 (delta 2), reused 0 (delta 0), pack-reused 2305
Receiving objects: 100% (2324/2324), 1.16 MiB | 650.00 KiB/s, done.
Resolving deltas: 100% (1478/1478), done.
Checking connectivity... done.
vitalii@vitalii-vm:~/source$

Build the application

Now everything is ready to build the application. Step into the folder with source code (MeasureThat.net/src/BenchmarkLab$) and run restore dotnet, npm and bower packages (it will take couple of minutes):

1
2
3
dotnet restore
npm install
bower install

Build frontend:

1
gulp

Build the application:

1
dotnet build

Build should succeed:

build_the_application

Prepare the configuration file

Open appsettings.json file in the text editor and:

  • Disable External authentication: set UseFacebookAuthentication / UseGoogleAuthentication / UseTwitterAuthentication / UseMicrosoftAuthenticaiton to false
    (Please let me know in the commens if you want to be able to use External authentication, I can explain how it can be done )
  • Set RequireEmailConfirmation to false
  • Disable reCaptcha: set ReCaptchaEnabled to false.
  • Set database type to PostgreSQL.

Result should look like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
{
"ApplicationInsights": {
"InstrumentationKey": "6fbb4f00-bf94-4fe8-a0e3-a5b4e1283fc2"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
"UseFacebookAuthentication": false,
"UseGoogleAuthentication": false,
"UseTwitterAuthentication": false,
"UseMicrosoftAuthenticaiton": false,
"ResultsConfig": {
"UploadResultsToDb": true,
"UploadGuestUserResultsToDb": true
},
"GoogleAnalytics": {
"Enabled": true,
"Identifier": "UA-83528903-1"
},
"AllowGuestUsersToCreateBenchmarks": true,
"SenderEmail": "MeasureThat@outlook.com",
"SenderName": "MeasureThat Admin",
"DatabaseType": "PostgreSQL",
"RequireEmailConfirmation": false,
"ReCaptchaEnabled": false
}

Prepare the database

Now we need to prepare the database.
Switch to postgres user and run the postgres client:

1
2
$ sudo -i -u postgres
$ psql

If you need to set the passowrd for the postgres user, enter command the password to do so. This may be needed right after PostgreSQL was installed.

1
2
3
postgres=# \password postgres
Enter new password:
Enter it again:

Create the database MeasureThat:

1
2
postgres=# create database MeasureThat;
CREATE DATABASE

You can exit from postgres cleint and switch back to the original user:

1
2
3
4
postgres=# \q
postgres@vitalii-vm:~$ exit
logout
vitalii@vitalii-vm:~/source/MeasureThat.net/src/BenchmarkLab$

Set the connection string (using Secret Manager tool):

1
2
$ dotnet user-secrets set ConnectionStrings:DefaultConnection 'User ID=postgres;Password=root;Host=localhost;Port=5432;Database=MeasureThat;
Pooling=true;'

Create the database schema:

1
2
3
4
5
6
7
8
9
10
11
12
13
$ dotnet ef migrations add testPg
Project BenchmarkLab (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation.
Done. To undo this action, use 'dotnet ef migrations remove'
$ dotnet ef database update
Project BenchmarkLab (.NETCoreApp,Version=v1.0) will be compiled because Input items added from last build
Compiling BenchmarkLab for .NETCoreApp,Version=v1.0
Compilation succeeded.
0 Warning(s)
0 Error(s)
Time elapsed 00:00:04.6049020
Done.

Run the application

Set the ASPNETCORE_ENVIRONMENT variable to Development

1
$ export ASPNETCORE_ENVIRONMENT=Development

And (drum roll) run the application:

1
dotnet run