Cloud Scripting Automation: Desktop-as-a-Service in Container

| May 13, 2020
Desktop-as-a-Service Cloud Scripting

In continuation of the first part of Cloud Scripting (CS) blog series, we cover the Container Operations topic which may be considered as a basis to perform custom actions while deploying your awesome solutions. We will describe how to work with the update type manifests. Or in other words, we will package a working add-on that you can apply to already existing environments. 

Within this article, we’ll create a self-hosted Desktop-as-a-Service that can be provisioned as an add-on to an existing container. This solution helps to move the workspace to the cloud and make it available around the clock from any place or device using NoMachine technology to access the desktop.

Container Operations

The JPS type update mainly relies on actions performed by Cloud Scripting engine inside existing containers: 

Within this blog post we will go over the most commonly used ones (cmd and api) to show the basics of Jelastic Add-On creation and actions utilization. 

1. Let’s create a JPS manifest for DaaS. In this package, we’ll use a free version of NoMachine software available for individual use. You can also Bring Your Own License (BYOL) requested from the vendor for commercial purposes. Please review the NoMachine license agreement.

Follow a line by line explanation for building manifest:

#Define the manifest mandatory option: type
type: update 
#Optional parameter. If id is not specified it will be generated automatically
id: daas-addon
#Defines the required name parameter
name: DaaS Add-On
#Optional parameter, logo that will be displayed in the Marketplace or installation window
#Describe the nodeType the add-on may be installed on. The targetNodes filters available nodes in the environment to fit the required nodeType
     - javaengine,tomcat,glassfish,wildfly,springboot
     - vds
     - storage
#Optional parameters help users to get a better understanding of the package 
  text: Install Add-On on any node in order to create Cloud Desktop with Gnome Display Manager and access it via [NoMachine technology](
  short: Use DaaS Add-On to run your workspace in the Cloud 
#The globals declaration has two placeholders defined within global scope:
#The ${globals.password} contains a randomly generated password
  password: ${fn.password}
#The ${globals.port} sets the container port 4000 that should be mapped to the free outside port of the platform. This port must be open between client and server as a mandatory option to allow connections by NoMachine’s NX protocol.
  port: 4000
#The entry point onInstall event contains three custom actions executed one by one in actions section below.
  - getUser
  - installXWin
  - addEndpoint
#Custom getUser action is created to return a default container username that will be used to connect to a remote desktop. It is performed with cmd action on the required node. Here cmd performs whoami command in order to print to stdout the default template’s user. The result is stored in ${response.out} placeholder. 
      - cmd[${}]: whoami
      - setGlobals:  
          userOut: ${response.out}
#Where the ${} placeholder contains a target container id that will be returned after the container (node) is picked up in the installation dialogue.To return the result we use another setGlobals action that will allow to make the result visible within the global scope of manifest with ${globals.userOut} placeholder.
#The custom installXWin action executes a series of shell commands with help of cmd action on the same container: 
# 1. It installs X Window System and Gnome Display Manager with some associated packages and configuration operations performed.
# 2. Set a password for default container user.
# 3. Download the last version of NoMachine free rpm package for Linux. 
# 4. Install NoMachine package
# 5. Add Mozilla Firefox web browser to the desktop
# 6. Gain user rights to the superuser with no password required to ensure the ability of any other software installation.
      - cmd [${}]:
          yum groupinstall -y "X Window System" "Fonts";
          yum install -y gnome-classic-session gnome-terminal nautilus-open-terminal control-center;
          unlink /etc/systemd/system/;
          ln -sf /lib/systemd/system/ /etc/systemd/system/;
          echo "${globals.userOut}:${globals.password}" | chpasswd; 
          wget -O nomachine.rpm;
          rpm -i nomachine.rpm; 
          yum install -y firefox;
          sed -i "\$a${globals.userOut}\ ALL=NOPASSWD\:\ ALL" /etc/sudoers 
        user: root
#All mentioned commands in action cmd will be executed under user root. If you do not specify a user they will be performed under default container user.
#Custom addEndpoint action maps container open port defined by ${globals.port} placeholder to the outside world through Jelastic Shared Load Balancer. It is performed by api action with env.control.AddEndpoint method that requires a set of parameters to be passed:
#   -  container nodeId (e.g. defined by ${}
#   -  container privatePort to be mapped (e.g. defined by ${globals.port})
#   -  protocol (e.g. TCP or UDP)
#   -  port mapping name (e.g. noMachine)
    - api : env.control.AddEndpoint
      nodeId: ${}
      privatePort: ${globals.port}
      protocol: TCP
      name: noMachine
    - setGlobals:  
        publicPort: ${response.object.publicPort}
#Success text that is displayed upon installation either at the Dashboard, or via email notification. It can be defined as plain text or Markdown syntax and may contain placeholders to provide credentials, URLs and other useful data
success: |
  Cloud desktop has been attached to your environment. Use mapped port instead of port 4000 in NoMachine connection parameters:  
  **Host**: node${}-${env.domain}  
  **Port**: ${globals.publicPort}  
  **Username**: ${globals.userOut}  
  **Password**: ${globals.password}  


2. Now you can import the created manifest to install on an existing environment. Feel free to get it from our JPS examples repository. Take into account that the destination container node should have at least 16 cloudlets to ensure stable work.

Desktop-as-a-Service add-on installation

3. The final directive success will be executed once a successful manifest installation takes place. As a result, you will get connection string and credentials for the further connection.

Desktop-as-a-Service add-on installation

4. The api addEndpoint action result is passed to ${response.object.publicPort} placeholder. To make it accessible within the global scope we use already known action setGlobals. Thus, for our example, container’s port 4000 was mapped via Shared Load Balancer to the one of free public ports 11001. The created mapping can be observed in the environment Endpoints section. To see this click on Settings > Endpoints of required environment upon successful add-on installation.

Desktop-as-a-Service endpoints

Cloud Desktop Launch

1. Install NoMachine client software depending on your platform (Windows, Mac, Linux, iOS, Android, Raspberry Pi, ARM).

2. In NoMachine client software use connection string and credentials received after add-on installation to connect to the Cloud Desktop.

NoMachine Desktop-as-a-Service

3. Follow the wizard to complete connection and open the Remote Desktop that may look like as follows:

connect remote Desktop-as-a-Service

DaaS add-on installation and connection process is simple, you can follow it with the video below.

Now you know how to utilize the most popular container operations to automate the processes for your applications lifecycle. In the upcoming article of this blog series, we will cover topology nodes management actions and respective events i.e. horizontal and vertical scaling. Stay tuned and try cloud programming yourself with Cloud Scripting at one of Jelastic Hosting Providers.