Skip to content

Development Environment

Matt Primrose edited this page Mar 24, 2024 · 10 revisions

IDE (VSCode)

Our team prefers to use Visual Studio Code for our IDE as it is one of the most versatile, configurable and free editors out there. Here's a list of extensions that are recommended for the development experience with the toolkit.

Recommended Extensions

Copy and paste these ids into the extensions search in VSCode and Install:

  • ms-azuretools.vscode-docker (for working with Docker) https://code.visualstudio.com/docs/containers/overview
  • angular.ng-template (for working with our Sample-Web-UI)
  • streetsidesoftware.code-spell-checker (For ensuring we catch mispelled (<--see what I did there) things in our code0
  • dbaeumer.vscode-eslint (For highlight, and enforcing our coding style -- we use standardjs rules https://standardjs.com/#why-should-i-use-javascript-standard-style)
  • github.vscode-pull-request-github (This helps make code reviews a little easier)
  • eamodio.gitlens (Helps to see who did what, you know, to work with the right people when things break :D )
  • golang.go ( For go development -- make sure you install all the go related tools! ) https://code.visualstudio.com/docs/languages/go
  • orta.vscode-jest ( Helps for running our Jest based tests)
  • ms-vsliveshare.vsliveshare (We use liveshare for peer programming. For those real sticky situations, the ones were it takes 30 minutes to get to where it breaks again and you need a second pair of eyes)
  • equinusocio.vsc-material-theme (To make the editor look good)
  • pkief.material-icon-theme (To make the icons look good too)
  • adamhartford.vscode-base64 (For converting text back and forth to base64 since we do that a lot)
  • redhat.vscode-yaml ('Cuz YAML whitespace can be a pain)

One thing we encourage is HOTKEYS! https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf The most important ones:

  • Ctrl+Shift+P to bring up the command pallet and search for what you want to do. Turn on code coverage? Toggle the minimap? Convert a word to uppercase? launch a docker compose file? You can do it all from this pallet menu!
  • Ctrl+P to open a file if you know the name. Don't go hunting for files in the explorer!!!

Source Control

Everything we do is here on Github. Git support is built into VSCode, check out https://code.visualstudio.com/docs/editor/versioncontrol to learn how to use VSCode's version control features. Sometimes though, you'll have to leverage the git-cli directly, and in that case you can use the integrated terminal: https://code.visualstudio.com/docs/editor/integrated-terminal.

Debugging

To learn more about debugging in VSCode. Check out: https://code.visualstudio.com/docs/editor/debugging

Required Running Services

The core microservices of RPS and MPS both require a database (PostgreSQL) and a secret provider (Vault). The easiest way to run these dependencies is with Docker. Using the docker-compose file in open-amt-cloud-toolkit, and ensuring the .env file has been updated with a proper database username/password and vault token you can run these dependencies with docker-compose up -d db vault. While Kong is used as the API Gateway for our Getting Started/Production flows, when in development, Kong is essentially not used when running the services natively. This has a couple implications, that the services are not served over https (since Kong serves the cert) and that the paths for each service need to leverage the port. For example, instead of https://[ipaddress]/mps to access MPS apis, you would use http://[ipaddress]:3000. Check the logs/config for which port each service is listening on.

Configuration

MPS/RPS

Once the dependencies are up, check to make sure your .mpsrc and .rpsrc have the correct database connection string and vault token that matches what you configured for db and vault. These files are used in development as default values and .env files can overwrite them. Make sure your .mpsrc files are configured per the docs located here: https://open-amt-cloud-toolkit.github.io/docs/2.1/GetStarted/setup/#set-environment-variables (the ones with the MPS_ prefix).

Typescript/NodeJS

Here is a sample launch.json file for MPS that goes in a .vscode folder at the root of each project. This is from a Windows machine, Linux may require the paths to be changed:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "name": "vscode-jest-tests",
            "request": "launch",
            "program": "${workspaceFolder}/node_modules/jest/bin/jest",
            "args": [
                "<<filename>>.test.ts"
            ],
            "cwd": "${workspaceFolder}",
            "console": "integratedTerminal",
            "internalConsoleOptions": "neverOpen",
            "disableOptimisticBPs": true
        },
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "env": {
                "MPS_LOG_LEVEL": "silly"
            },
            "skipFiles": [
                "<node_internals>/**"
            ],
            "outputCapture": "std",
            "program": "${workspaceFolder}\\dist\\index.js",
            "preLaunchTask": "tsc: build - tsconfig.json",
            "outFiles": [
                "${workspaceFolder}/dist/**/*.js"
            ]
        }
    ]
}

It will be similar for RPS, just need to update the ENV var to be RPS instead of MPS

Go

Heres's a launch.json that can be used for RPC-go. You'll need to launch VSCode as an administrator to be able to debug RPC as it talks to hardware:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Run",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${workspaceFolder}/cmd",
            "args": [
                "amtinfo",
                "-bld"
            ]
        }
    ]
}

Remote Development using OpenSSH

With the additions of local features in RPC-Go, the ability to remote into a variety of AMT machines to test & debug code is critical. OpenSSH server should be running on all of your AMT devices that you use for development.

Ubuntu Install

For Ubuntu devices use the following to install and run OpenSSH server:

  1. Open the terminal application for Ubuntu desktop
  2. Type command:
sudo apt-get install openssh-server
  1. Enable the ssh service by typing:
sudo systemctl enable ssh --now

Windows 11 Install

For Windows 11 devices use the following to install and run OpenSSH server:

  1. Open up Settings panel (Windows key, type settings).
  2. In the search bar above Home, type: Optional features.
  3. On the "Add an optional features" line click "View features".
  4. In the "Find an available optional feature" search bar, type "OpenSSH".
  5. Select OpenSSH Server and click Next, then click install.
  6. It will take a few minutes for OpenSSH Server to install.
  7. Open up Task Manager and click on Services.
  8. Find ssh-agent in the list (it's alphabetical) and right click, open services.
  9. Find OpenSSH Authentication Agent. Right click -> Properties. Set Startup Type to automatic.
  10. Find OpenSSH SSH Server (should be next in the list). Right click -> Properties. Set Startup Type to automatic.

VS Code configuration

  1. Open VS Code on your development machine (not the AMT machine)
  2. ctrl-shift-p to open the command pallet
  3. type "Remote-SSH" and select Remote-SSH: OpenSSH Configuration File.
  4. Select the config file you want to update. I use the one stored in my Users folder "C:\Users\your username\.ssh\config"
  5. Add the specific machine you want to use for remote development. This is what my config file looks like for the 3 machines I remote dev on:
Host 192.168.0.38
  HostName 192.168.0.38
  User snuc
Host 192.168.0.82
  HostName 192.168.0.82
  User RBHE_MCP
Host 192.168.0.75
  HostName 192.168.0.75
  User hec-mcp

Connect to remote machine for development

Open VS Code and make sure you have the Remote Development extension installed. It should look like this:

image

In VS Code you should have this icon in the bottom left corner of the window:

image

Click the icon and you'll see drop down menu at the top of the VS Code window. Select "Connect to Host". You'll see a list of devices that should match what you configured in the previous section. Mine looks like this:

image

Select the device you want to remote connect to. You'll be prompted for the password associated with the user you put in the config file. You may have to put the password in twice, that is normal.

You are now remotely connected to the device's terminal and can enter commands just like you would on your local machine. The top of VS Code should look something like this when you are connected:

image

and the bottom left corner of VS Code should look like this:

image

If you have Git installed on the remote machine (required) then you can use all the git commands you would normally use on your local dev machine. You are now remote developing and there is no longer a need to use a slow remote desktop session!

Clone this wiki locally