# Purple

Purple is an electron-based javascript bridge between the cloud application and the native software.

It is build up around multiple services that each translate changes in the database to local API calls.

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

**Table of Contents** _generated with [DocToc](https://github.com/thlorenz/doctoc)_

- [Running purple on an NRC/NUC in dev mode](#running-purple-on-an-nrcnuc-in-dev-mode)
  - [Configure the device now](#configure-the-device-now)
  - [Remote development using VSCode on a device using SSH](#remote-development-using-vscode-on-a-device-using-ssh)
    - [Access Barco servers](#access-barco-servers)
- [Running the app](#running-the-app)
  - [Setup the environment variables](#setup-the-environment-variables)
  - [Install packages](#install-packages)
  - [Debug with VSCode](#debug-with-vscode)
- [Making a PR in purple](#making-a-pr-in-purple)
  - [content](#content)
  - [pr-overview](#pr-overview)
  - [git-practice](#git-practice)
  - [other](#other)
- [Releasing purple](#releasing-purple)
  - [Pushing purple to debian](#pushing-purple-to-debian)
  - [Creating an ISO](#creating-an-iso)
  - [Publishing an ISO](#publishing-an-iso)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## Running purple on an NRC/NUC in dev mode

### Configure the device now

Use canopener: https://git.barco.com/projects/ED/repos/canopener-gui/browse

Before running the app, the file in /etc/hosts should be changed so that the device can locate the server.
If the server e.g. will run on dev.barco.com, then the following entry should be added:

```
[YOUR-IP-ADDRESS-HERE]  dev.barco.com [my-institute-slug].dev.barco.com [my-other-institute-slug].dev.barco.com
```

### Remote development using VSCode on a device using SSH

Make sure you can setup a SSH connection to the device first. Then VSCode SSH remote development can be used, see [here](https://code.visualstudio.com/docs/remote/ssh).

#### Access Barco servers

To access the Barco git and artifactory servers (e.g. when installing the packages), the hosts file needs to be updated with following values:

```
10.197.195.201  bin.barco.com
10.197.192.83   git.barco.com
10.197.195.56   knddebian.barco.com
```

Also, if working from home a VPN connection may be needed. `openconnect` can be used to setup a VPN connection. If not installed yet, install it on the device with `sudo apt install openconnect`.

Then following command can be used to initiate the VPN connection: `sudo openconnect -b https://kndvpn.barco.com`. Select `token` and enter you credentials to start the VPN connection.

## Running the app

### Using the correct node version

It is recommended to use [nvm](https://github.com/nvm-sh/nvm) to manage the correct node version. This tool makes it a lot easier to handle multiple node version on the same machine.
There is a .nvmrc file in the root which can help with loading the correct version. Just use the `nvm use` command in any of the directories to load the correct node version.

### Setup the environment variables

To run the application the environment needs to be setup first. To do this, [direnv](https://direnv.net/) should be used.
See `./.envrc.example` for more details how to set this up.

### Install packages

Go to `projects/edu` and run:

```
npm run barco:install
```

Error 404 is caused by not having correctly set the npm-virtual npm registry, ensure you have [setup the environment](#setup-the-environment-variables) variables correctly. Note that the npmrc file is not used by meteor, so setting the
variables in this file is not enough.

Then the app can be started by:

```
npm start
```

If you get errors, try running `sudo apt install libxss1` and retry the previous step.

Note that after pairing the process exits. In production mode it will be automatically restarted, during development you have to do this manually.

### Debug with VSCode

To debug the application in VSCode:

- Go to the vscode debug pane and run the `Launch purple` configuration

## Making a PR in purple

This section will give you some guidelines on what to do to make a proper Pull Request in this repository.
If you want more ( like guidelines for review and qa, you can find them [here](https://wiki.barco.com/display/WEC/Pull+requests%3A+how-to)

### content

- it fixes only 1 problem or implements only one feature
- versionnumber in package.json is not bumped manually (use release script for that)
- Code builds and runs without errors on a development machine
- Logging should be meaningful and limited for production devices
- Unit tests if possible (might be problematic depending on Bridge/Service)
- Debt file completed where useful

### pr-overview

- It should be clear in the PR description if there are dependencies upon blue (eg. you need to run a special branch of blue in order to test)
- PR should refer to the corresponding itrack issue number (via branchname) and mention if there are discrepancies wrt. to itrack issue (eg. not everything implemented for some reason).
- In case of no itrack (small issue) the description should point out what issue should be fixed by this.

### git-practice

- Commits are squashed to a reasonable amount so that each commit is relevant in the endresult
- Branch is rebased on target
- Dependencies on different debian versions should be taken into account where applicable (changing debian version)

### other

- Breaking backwards compatibility with blue should be very well documented (Release notes --> mention if minimum compatible version should be updated + what will happen)
- At least tested in single device scenario applicable to story/fix

## Releasing purple

### Pushing purple to debian 11

Make sure you've enough access rights to push things into the rc branch without doing a PR.
Another thing that can be done is to run the release.js script by enabling the DEGUG env var, to check if everything is OK.
You can run `node ./release.js [M.m.p]`

IMPORTANT:

- For this script to work fine, your local debian/nrcdeb11100 branch must track the remote one
- It's strongly recommended to first run the script in simulation mode `DEBUG=1 node ./release.js [M.m.p]`, which will show the commands that it would execute.

`M.m.p` for the Major, minor and patch version respectively.
If not provided, a new build of the current version will be released.

You can also run with `--patch`, `--minor`, `--major` arguments to bump & release the current version respectively in patch, minor, major version.

See [RELEASE.MD](./RELEASE.md) for more information

### Creating an ISO

Before creating an ISO, make sure the last purple version is properly built (https://git.barco.com/projects/ED/repos/purple/commits?until=refs%2Fheads%2Fdebian%2Fnrcdeb11100&merges=include).
You can find a [detailed explanation here](https://wiki.barco.com/display/GEAX/Create+weConnect+ISO)
You can verify that the new version of the barco-edu-proxy package has been published at the following location (subject to change):

- [debian 11: nrcdeb11100](http://kordbld01.barco.com:8066/mini_buildd/api?command=show&package=barco-edu-proxy)

1. Go to [Jenkins job](http://korjnk01.barco.com/jenkins/job/NRC/job/debian/job/Build/job/build-iso%20autobuild/job/master/)
2. Login with barco credentials
3. Click `Build with Parameters`
4. Select distribution (nrcdeb11100)
5. Click `Build`
6. Successful job execution will trigger another job which will build an actual ISO.
7. After an hour you can download ISO from [artifactory](https://bin.barco.com/artifactory/nrc-release/release/nrcdeb11100/).
   If the ISO is not available, you can have a look at the logs from here (and/or maybe re-trigger this job) :
   http://korjnk01.barco.com/jenkins/job/NRC/job/debian/job/Build/job/nrc-iso%20autobuild/job/debian%252Fnrcdeb11100/

### Publishing an ISO

1. Go to [artifactory](https://bin.barco.com/artifactory/nrc-release/release/) and find a link to the latest ISO for the release you're looking to publish.
2. Go to [Repository Uploader Job](http://kndedu01.barco.com:8080/view/EDU%201.2/job/Debian%20Repository%20Uploader/):
   - Click _Build with Parameters_
   - Paste in ISO url and click Build

At the end of the job, if it finishes with success, it provides an url like
http://repository-tst01.edu.barco.cloud/repository/aws-test/Barconrc-3.0.1-b53

To test if it's really deployed/available, suffix the url received with `/version` (it should download a version file)

If the version file above is not available and the job succeeded, it might be necessary to restart the following deployment edu-repository-tst01
