:orphan:

============================
Running FactoryTX VM in ESXi
============================

One of the many ways to run the FactoryTX VM is with an
`ESXi hypervisor <https://en.wikipedia.org/wiki/VMware_ESXi>`_. Let's walk
through the steps on how to configure and run the FactoryTX VM. It should be
noted that we are using VMWare ESXi v6.7.0 in our test lab and that the
screenshots in the article are using the web client.

.. contents:: :local:


Upload FactoryTX VM files to Datastore
======================================

With our FactoryTX VM files (e.g. *factorytx-os.vmdk* and *factorytx-data.vmdk*
files) stored on our local device, connect and log in to the ESXi server. From
the sidebar, navigate to the datastore.

.. image:: img/vmware_1_go_to_datastore.png
    :scale: 50%
    :alt: Datastore menu in the VMWare web client

Open the *Datstore browser* and upload the FactoryTX VM files.

.. image:: img/vmware_1_upload_vmdks_to_datastore.png
    :scale: 75%
    :alt: Datastore browser with the uploaded VMDK files displayed


Create a new VM
===============

From the sidebar, navigate to the *Virtual Machines* menu and select the
*Create / Register VM* button.

.. image:: img/vmware_2_create_new_vm_button.png
    :alt: Virtual Machines in the VMWare web client

In the *New virtual machine* window, select the option to create a new virtual
machine.

.. image:: img/vmware_3_create_new_vm_window.png
    :scale: 75%
    :alt: Window to select creation type for new virtual machine

When prompted to select a name and guest OS for the virtual machine, select
**Linux** for the OS family and **Other Linux (64-bit)** for the OS version.

.. image:: img/vmware_4_create_new_vm_OS.png
    :scale: 75%
    :alt: Window to select OS family and version for new virtual machine

When customizing other VM settings, remove the pre-defined hard disk. Select
*Add hard disk*, choose the option for an *Existing hard disk*, and select one
of the FactoryTX VMDK files (e.g. *factorytx-os.vmdk*). Repeat this step, so
that both FactoryTX VMDK files are set as the hard disks for the VM.

.. image:: img/vmware_5_settings_add_hd.png
    :alt: Dropdown menu to add a disk to a virtual machine

Open up the submenu for the OS hard disk and choose **IDE controller 1** and
**Master**.

.. image:: img/vmware_5_settings_drive_os.png
    :alt: Settings for the OS disk

For the FactoryTX data hard disk, choose **IDE controller 1** and **Slave**.

.. image:: img/vmware_5_settings_drive_data.png
    :alt: Settings for the FactoryTX data disk

For the *Network Adapter*, select **E1000e** or **E1000** as the *Adapter Type*.

.. image:: img/vmware_5_settings_network.png
    :scale: 75%
    :alt: Network settings for the new VM

In summary, the hardware settings for the FactoryTX VM should be similar to:

.. image:: img/vmware_6_hardware_settings_summary.png
    :alt: Screenshot of hardware settings for the FactoryTX VM


Deploy code to VM
=================

After powering on the FactoryTX VM, use a web browser and navigate to the
`Balena dashboard <https://dashboard.balena-cloud.com/apps>`_ and check the
application for a new device to appear.

.. image:: img/balena_dashboard_with_devices.png
    :scale: 75%
    :alt: Balena dashboard with devices configured

To deploy FactoryTX code to the VM, open a Terminal window on your local
machine: navigate to the desired FactoryTX directory; add the remote repository
for the Balena application; and push code to the remote.

.. code-block:: bash

    # If you want to deploy a factorytx-core instance
    cd /opt/sightmachine/factorytx-core

    # If you want to deploy a factorytx-<customer> instance
    # Remember to replace "<customer>" with the customer name
    cd /opt/sightmachine/factorytx-<customer>

    # Command can be found in the application view of the Balena dashboard
    git remote add balena g_urian_chang@git.balena-cloud.com:g_urian_chang/esxi-1.git

    git push balena master