Complete Remote Web Development Virtual Lab Scenario
Info
This part assumes that the Deploying the First Application part has already been completed as it uses resources which have been described and deployed in it.
In this part of the tutorial, we will continue with the deployment of the additional applications required to complete the remote web development virtual lab scenario.
Deploying MailDev
The next application to be deployed is MailDev. As it is also a simple application without too many configuration options during runtime, the only possibility is to enable web authentication using the nmaas application deployment wizard. Ticking this checkbox would require HTTP basic authentication before accessing the web UI. No matter what is selected, the SMTP interface always works without any authentication.
The application access details modal shows instructions on how to connect to both the web interface of the application, as well as the SMTP interface for sending dummy emails during development.
Deploying Valkey
Valkey is a caching solution and is a direct fork of Redis. In this scenario we will be using it to cache the daily quote obtained from the database, reducing the load on the PostgreSQL instance. The only configuration parameter for Valkey exposed by the nmaas application wizard is the authentication password.
As Valkey does not offer a web interface, the only presented access method after its deployment is an external IP address that can be used for accessing the service both from other applications hosted on nmaas, as well as from the virtual lab participants' workstations.
Deploying VS Code Server
The final application that will be deployed as part of the remote web development virtual lab scenario is the integrated development environment - VS Code.
When using a VS Code instance on nmaas the user can write, compile, and run the code on the same hardware where nmaas is hosted, thus removing any hardware performance constraints that would have been applicable if the lab participants were trying to develop on their own, potentially resource limited, workstations. As the development tools for various programming languages differ, during the deployment process the virtual lab participant is asked to select the desired flavor which depends on the programming language that will be used. Currently supported flavors are Java and Python, but more can easily be added in the future, by customizing the set of preinstalled software available in the VS Code container.
After the application is deployed and has entered a running state, the lab participant can login to the web interface using the password specified during deployment time. The web interface is absolutely the same as the VS Code's local version.
Setting up VS Code
As we will be building the demo random quotes application using the Flask Python framework, a couple of prerequisites need to be satisfied.
- Create a new directory that will house the project's files.
- Create a new Python virtual environment using the
Terminal
option from the VS Code web interface. - Activate the newly created Python virtual environment.
- Open the newly created directory as a VS Code project using the
Open Folder
option in VS Code. - Create a new Python file called
main.py
. - Enter a sample Python expression, such as:
-
To run and debug Python files we will need the official Python VS Code extension. This extension can be installed by clicking the
F1
keyboard key, and searching for the expressionextensions install
. Choose theExtensions: Install Extensions
result and search forPython
. -
After the extension has been installed, returning to the
main.py
file should provide the option to run it directly by clicking on the newPlay
button in the top right corner.
Developing the Demo Application
The complete source code for the random quotes application is provided below. It can be pasted directly into a file using a VS Code editor hosted on nmaas and it can integrate with PostgreSQL, Valkey, and MailDev instances also hosted on nmaas.
|
Before running the above example using nmaas applications deployed to your own domain, please change the connection information on lines: 11
, 13
, 14
, and 18
with the relevant information obtained from the access details pages for the respective applications.
In case of any dependency errors, make sure that the following Python packages have been installed in the virtual environment:
- flask
- redis
- records
- psycopg2-binary
These can all be installed using the following command:
Testing the Demo Application
Running the application at this point will start the development web server and will automatically open an internal proxy. Clicking the Open in Browser
button from the presented VS Code popup will open a new tab navigating to the Flask development web server.
As the specified route for the defined function in the source code above is /get-quote
, the path in the new tab will need to be manually adjusted.
To fully test the functionality of the application, we can also insert more quotes in the database:
After inserting the above quotes to the database, refreshing the page multiple times should always return the same result as previously, since that quote has been cached into Valkey and no new queries are executed against the PostgreSQL database.
The final aspect to test is the sending of the emails. A request to the random quotes API should also send an email using MailDev's dummy SMTP server. The content of the email message should be visible using the MailDev web interface.