“Building a Comprehensive Corporate Training Portal on GCP: Utilizing Deployment Manager and Automating Talent Onboarding through Serverless Architecture with Python Flask Backend and Cloud Storage Frontend”

A R
7 min readMay 10, 2024

--

In this real world project, I assumed the role of a cloud engineer tasked with deploying the Moodle application on GCP using Deployment Manager and a Marketplace image. The objective was to host Moodle on GCE while storing static content on Cloud Storage.

Subsequently, the client requested to automate HR onboarding process by deploying a training portal for new trainees alongside the Moodle application. The requirement was for a straightforward and cost-efficient solution. I proposed leveraging serverless architecture on GCP, utilizing Cloud Functions to host a Python Flask backend for processing, and employing Cloud Storage to host frontend files (HTML/CSS/JS/BS).

In this setup, a trainee fills out user information in a form and submits it, triggering the execution of a function. This function processes the data and invokes the Moodle application API to register the new user in Moodle.

This streamlined architecture aligns with best practices in the Well-Architected Framework, emphasizing cost-effectiveness, security, operational excellence, reliability, and performance efficiency.

Implementation overview:

Part 1 — Prerequisite — Deployment of A corporate Training Portal on GCP using Deployment Manager, GCE and Cloud Storage

Step 1) Deploying Deployment manager, Moodle application.

Step 2) Moodle setup and customization.

Part 2 — Deployment of a Web Application to automate talent onboarding using HTML / CSS / JS / BS (Front-end) + Python Flask (Back-end) with Cloud Storage and Cloud Functions 100% Serverless.

Step 1) Setting up a Webservice plugin on Moodle.

Step 2) Create and deploy Cloud Function instance and configuration.

Step 3) Configuring Frontend on Cloud Storage

Step 4) Test the application.

Part 1) Prerequisite — Deployment of A corporate Training Portal on GCP using Deployment Manager, GCE and Cloud Storage.

Step 1) Deploying Deployment manager, Moodle application.

1. Enable Cloud Deployment Manager API.

2. Deploy Moodle from Marketplace

  • Machine type: e3-meduim
  • Enter your email address.

3. Create storage bucket.

- For faster file retrieval, select the same region as the application deployed.

- Storage type: standard

  • Control access: allow public access, Uniform.

- Upload Files: iLearnIntro.mp4 and iLearnPDF.pdf

Configure below permissions for each file.

- Entity:Public

- Name: allUsers

- Access: Reader

Each file will get a public URL to allow application access.

Step 2) Moodle setup and customization.

Add logo and add the public URL of Video and files. Make the “Download PDF” title as a hyperlink.

Part 2 — Deployment of a Web Application to automate talent onboarding using HTML / CSS / JS / BS (Front-end) + Python Flask (Back-end) with Cloud Storage and Cloud Functions 100% Serverless.

Step 1) Setting up a Webservice plugin on Moodle

1) Enable webservices and protocols.

Log in as Admin in the Moodle Web Application.

- Enable web services.

- Enable protocols for REST Protocol.

2) Create a webservices authorized users.

Click on web services to add a new webservice.

- Name: webservice

  • Enable Authorized users only.

3) Add function.

Click on web services to add a new webservice.

  • Add core_user_create_users functions

4) Add user.

Click on web services to add specific user.

  • From Not Authorized list, find and select the user Admin User, then click on Add.

5) Add token.

Click on web services create a token for the user.

  • Select the user Admin User and create a token.

Save Changes

* Keep a note of Token generated and Moodle server IP address for later use.

Validate the API if it is working.

From Google Cloud Shell, let’s validate if the API is working properly:

Step 2) Deploying a Cloud Function and configuration.

1. Access the Cloud Functions services and create an instance.
Section Basics

- Function name: moodleUserCreate

Section Trigger

- Trigger type: HTTP

- Authentication: Allow unauthenticated invocations

- Check Require HTTPS

2. Adding environment variables | RUNTIMIME, BUILD, CONNECTIONS AND SECURITY SETTINGS

From Runtime environment variables, add below Variables:

- Name: MOODLE_TOKEN

- Value: insert the token generated

- Name: MOODLE_SERVER

  • Value: insert the Moodle Public IP Server

3. Configure below to create function.

- Runtime: select Python 3.8

- Entry point, type receive_request (Function name in the Main.py)

- Copy your application main.py and replace in the body of function text box.

- Replace the requirements.txt with your requirements too.

Click on Deploy. (This process can take 2–4 minutes).

Step 3) Testing the function.

Access Cloud Function Deployment moodleUserCreate.

From the guide Trigger, copy the Trigger URL and save it in your notepad file!

From the Cloud Shell, check if the function is working:

the curl command triggers the function to register the name Jean Rodrigues with his contact details.

The success code 200 and recording name in the moodle application indicates that the communication between the cloud function and the moodle application works fine.

For error troubleshooting go to Cloud Function | Logs, and analyze the issue.

Having user recorded and logs indicate success, that means our function and Moodle application are configured correctly.

Step 4) Configuring Frontend on Cloud Storage

Using the Cloud Editor, edit the frontend/index.html. In the action, replace the URL wit function trigger URL.

1. Create Bucket (Cloud Storage):

This bucket is used to upload functions frontend content.

Uploading the Frontend files to the bucket created:

2. Setting up the Bucket

We need to configure bucket for website files index.html and error 404.

gsutil web set -e error404.html gs://YOUR_BUCKET_NAME

Below command allows public to access the website.

gsutil iam ch -r -u AllUsers:R gs://YOUR_BUCKET_NAME

By now, we have setup a website that the frontend is hoste on cloud storage. For that reason, the public URL of the <bucket_name>/index.html is the front facing of the website.

Step 5) Test the application.

In bucket, go the index.html, and click on the public URL. It should open in a new browser.

Enter some information and submit. (you see that google storage API responds with success message).

The successful submission of the form will trigger run function in the backend. The function processes the request and calls Moodle main application API. Check the user’s list in Moodle main application and you will see that the new user is recorded.

Conclusion and Insights:

This practical project showcases a distinctive architecture that is characterized by its simplicity, cost-effectiveness, and rapid implementation. A key feature is the separation of the training application from the main application, which effectively mitigates errors stemming from new trainees. Additionally, the application’s cost-effectiveness is achieved through hosting its files on Cloud Storage and leveraging a serverless model via GCP Cloud Function for processing. Upon successful form submission, the function is triggered, subsequently initiating a call to the Moodle main application for user registration.

In summary, the utilization of a serverless architecture, Python code, API integration, and hosting two applications with disparate architectures communicating through API calls provided an enriching experience, offering fresh perspectives on the design of simple, serverless, and cost-effective architectures.

References

--

--

A R
0 Followers

Infrastructure Engineer with focus on Cloud & DevOps | AWS | Microsoft Azure | Google Cloud | Oracle Cloud | IBM | AI-ML