# Getting Started with Arm Virtual Hardware
*Accelerating MLOps in the cloud*
This README is a set of instructions for the [Introductory IoT DevOps workshop](https://www.arm.com/company/contact-us/virtual-hardware).
**Table of contents**
1. [Prerequisites](#prerequisites)
2. [Accessing and launching the AMI](#amilaunch)
- 2.1 [Find AMI on AWS Marketplace](#marketplace)
- 2.2 [(Alternative) Launch the AMI from AWS EC2](#launch)
- 2.3 [Enable AMI console](#console)
- 2.4 [(Optional) Enable Code Server](#codeserver)
- 2.5 [(Optional) Enable Virtual Network Computing (VNC)](#vnc)
3. [Import and build example](#buildexample)
- 3.1 [Fork and clone example](#clone)
- 3.2 [Build example within the AMI](#build)
- 3.3 [Run the example in place](#run)
- 3.4 [Edit example](#edit)
- 3.5 [Submit changes back to GitHub](#push)
4. [Automated CI/CD with GitHub Actions](#actions)
- 4.1 [Configure GitHub Actions](#confactions)
- 4.2 [Setup runner on AMI](#runner)
- 4.3 [GitHub Actions workflow](#workflow)
- 4.4 [Demonstration of a failed workflow](#failure)
5. [To go further](#further)
<a name="prerequisites"></a>
## 1. Prerequisites
* a valid [AWS](https://aws.amazon.com/) account
* a valid [Github](https://github.com/) account
* a SSH (VNC) client installed: e.g. [PuTTY](https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html), [MobaXterm](https://mobaxterm.mobatek.net/)
<a name="amilaunch"></a>
## 2. Accessing and launching the AMI
<a name="marketplace"></a>
### 2.1. Find AMI on AWS Marketplace
1. Log into your [AWS account](https://aws.amazon.com/) and select *AWS Marketplace Subscriptions* service
2. Go to *Discover products* and search for *Arm Virtual Hardware* (with spaces)
![AWS AMI subscription button](img/subscribe.png)
3. Click on *Continue to subscribe to the AMI* > *Continue to configuration* > *Continue to launch*
4. Choose **c5.large** instance type. This type has 2 powerful vCPU and 4 GB of RAM which is enough resources to run the AMI and simulation fast.
![AWS instance size list](img/instance_type.png)
5. If you don't have a VPC (Virtual Private Cloud network) already, click on *Create a VPC in EC2 * in the corresponding section. In the *Your VPCs* interface, click on *Actions* > *Create default VPC* in the top-right corner.
![AWS instance size list](img/ec2_vpc.png)
6. If you don't have a Security Group already, click on *Create new security group based on seller settings* in the corresponding section. This will allow SSH connection to the instance. Add a name and description to save it.
![AWS instance size list](img/ec2_sg.png)
7. If you don't have a Key Pair already, click on "Create a key pair in EC2" in the corresponding section. A SSH key pair correspond to a public key that will be copied on the server side (the running AVH AMI instance) and a private key needed by a client to connect to it (your local machine). In the *Key pairs* interface, click on *Create a pair* in the top-right corner and follow the default steps to download the private key that you will need to connect.
![AWS key pair selection menu](img/key_pair.png)
8. Click on *Launch*. You will see a "Congratulations" message to inform you that the instance was successfully deployed. Click on the link provided "You can view this instance on EC2 Console" to check the instance status and retrieve its *Public IPv4 address*.
<a name="launch"></a>
### 2.2. (Alternative) Launch the AMI from AWS EC2
1. Log into your [AWS account](https://aws.amazon.com/) and select *Elastic Compute Cloud (EC2)* service
2. Locate *Images > AMIs* in the sidebar
3. Search *Public Images* for *ArmVirtualHardware* (without spaces) and click on Launch.
![AWS key pair selection menu](img/ec2_launch.png)
4. Follow the steps with the default options. If this has not been configured already, you will need to create a VPC, a new security group similar to what is described in [section 2.4](#marketplace).
8. Click on *Review and launch* > *Launch* to select or create a key pair (see [section 2.4](#marketplace)). You will see a message to inform you that the instance was successfully launched. Click on the *View instances* link provided to check its status and retrieve its *Public IPv4 address*.
<a name="console"></a>
### 2.3. Enable AMI console
To connect to the running instance, you will need its *Public IPv4 address*. If you don't have it already, you can get from the *EC2* > *Instances*.
Use SSH command on Linux, MacOS or [Windows Powershell](https://www.howtogeek.com/336775/how-to-enable-and-use-windows-10s-built-in-ssh-commands/):
ssh -i <key.pem> ubuntu@<AMI_IP_addr>
Or, if using MobaXterm on Windows:
* Add new SSH session
* Specify `<AMI_IP_addr>` as *Remote host*
* Specify `ubuntu` as *username*
* Enable *Use private key* and specify path to `<key.pem>`
![MobaXterm SSH configuration](img/moba_ssh.png)
Or, if using PuTTY:
* Use **PuTTYgen** to convert the .pem file to .ppk
* Specify `ubuntu@<AMI_IP_addr>` in *Session > Host name*
![PuTTY username and hostname/IP configuration](img/putty_ip.png)
* Specify path to `key.pem` in *Session > Connection > SSH > Auth > Private key file for authentication*
![PuTTY private key configuration](img/putty_key.png)
<a name="codeserver"></a>
### 2.4. [Optional] Enable [Code Server](https://github.com/cdr/code-server) (Visual Studio Code)
The Arm Virtual Hardware AMI comes with an IDE (Visual Studio Code) which can be accessed with a web browser. To access it, you will need to:
1. Start a SSH tunnel to the instance and forward port 8080. On Linux, MacOS or [Windows Powershell](https://www.howtogeek.com/336775/how-to-enable-and-use-windows-10s-built-in-ssh-commands/):
`ssh -i <key.pem> -N -L 8080:localhost:8080 ubuntu@<AMI_IP_addr>`
The -N option holds the SSH tunnel connection and does not allow to execute other remote commands. This is useful for just forwarding ports.
Or, with MobaXterm on Windows:
* Add new SSH tunnel
* Specify `8080` in *My computer > Forwarded port*
* Specify `<AMI_IP_addr>` in *SSH server*
* Specify `ubuntu` in *SSH login*
* Specify `22` in *SSH port*
* Specify `localhost` in *Remote server*
* Specify `8080` in *Remote port*
* Save configuration. Click on the key icon to specify the path to `<key.pem>`
* Start the tunnel connection
![MobaXterm SSH tunnel configuration](img/moba_tunnel.png)
2. Launch a web browser on your local machine and open the following URL: [http://localhost:8080](http://localhost:8080)
<a name="vnc"></a>
### 2.5. [Optional] Enable Virtual Network Computing (VNC)
VNC is a protocol to enable remote desktop. The instruction below will securely enable VNC through a SSH tunnel.
In the AMI terminal:
1. Enable VNC password (no need to enter a view-only password)
`vncpasswd`
2. Start the VNC server for the session
`sudo systemctl start vncserver@1.service`
To restart the VNC server after reboot
`sudo systemctl enable vncserver@1.service`
On your local machine:
3. Forward port 5901 on local machine. On Linux, MacOS or [Windows Powershell](https://www.howtogeek.com/336775/how-to-enable-and-use-windows-10s-built-in-ssh-commands/):
`ssh -I <key.pem> -N –L 5901:localhost:5901 ubuntu@<AMI_IP_addr>`
Then, connect VNC client (e.g. Remmina, TigerVNC) to port 5901. You will be prompted for password.
Or, with MobaXterm on Windows:
* Add new VNC session
* Specify `localhost` as *Remote hostname*
* Specify `5901` as *Port*
* Select the *Network settings* tab configure the *SSH gateway* with:
* `<AMI_IP_addr>` as *Gateway host*
* `ubuntu` as *Username*
* `22` as *Port*
* Enable *Use SSH key* and specify path to `<key.pem>`
![MobaXterm VNC configuration through SSH gateway](img/moba_vnc.png)
<a name="buildexample"></a>
## 3. Import and build example
<a name="clone"></