Macro Service — Severless

Jay Liu
4 min readJun 4, 2019

Platform Entrance: https://console.zhonghuacloud.com

Objective

The Objective of Macro Service is migrating the normal website into Serverless cloud without changing one line of source code.

The idea of the platform

We believe it is not right to rewrite your website with SDK to adopt a cloud. The right way is the cloud should fit the current website automatically and put more power an energy to the website directly.

The steps to build a Macro Service Website

Create a new project

  • Enter your own domain name and make sure it is a DNS CNAME record with the value of host.us.zhonghuacloud.com
  • Or you can use a free sub domain with the pattern xxx.v.zhonghuacloud.com such as abc.v.zhonghuacloud.com
  • Choose a programming language and version number, the database and whether your website is stateful or stateless. If your website programs with serverside memory tech such as http session, please choose stateful, otherwise stateless.
  • Click the created project
  • Click the upload file button, upload a zipped file. Please zip the whole website source code from the website root folder. If it is NodeJS project be sure don’t zip the huge node_modules folder because the platform will run the npm install command for you.
  • Click the npm install / pip install button to install the third party packages and build a linux runtime image for Docker. The platform will search the package.json orrequirements.txt under the root folder.
  • Startup the website.
  • Now you can test the installed website. The https SSL certificate will be installed automatically.​

NodeJS github https://github.com/jaynsw/nodejs-hello

Python github https://github.com/jaynsw/installer/tree/master/python-hello

Q & A

Can I bind my own domain name ?

A: Yes

The https certificate is installed automatically ?

A:Yes

How can I access the database ?

A:basically, you can get the database connecting parameters from several env variables. The following is a NodeJS example:

var env = process.env;

var dbo = {

host: env[‘bebox_mysql_host’],

port: env[‘bebox_mysql_port’],

user: env[‘bebox_mysql_user’],

password: env[‘bebox_mysql_password’],

database: env[‘bebox_mysql_database’]

};

var pool = mysql.createPool(dbo);

How the website is started up?

A:If the website is a NodeJS website, it is started up by the command npm start. If it is a Python website, a script named startup.sh is created automatically. Your website will be started up as a Flask website. If it is not a flask website, you should change the startup.sh script according to your own program.

How the public traffic comes to my website?

A:The gateway of the platform will forward all your domain’s public traffic into your website docker container’s port 9000, so your website should listen on port 9000.

What is Stateful / Stateless website ?

A:If your website uses some server side memory techs such as http session, it is a stateful website, otherwise stateless.

When it is stateful website, all the http requests from one person will be forward same website instance to make sure all the user’s state is not lost.

When it is stateless website, all the http requests will be evenly forward to different website instances.

How can I Scale Up / Down my website instances ?

A:There are 2 website instances created by default. You can click the scale button to scale up / down the instance number or by API.

How much the cost ?

A:It is free. No plan to charge at this stage.

Macro Service Features

  • The website instances are running inside Docker containers.
  • Multiple instances are created for each website. The gateway of platform forward the public traffic to these instances smartly.
  • All instances of a website sharing a same file system, so your program can save the data into your local file system safely.
  • You can edit the source code files inline and restart your website instantly taking effect.
  • You can check log, cpu usage, memory usage.
  • You can check status of every instance of your website.

Macro Service Platform Anatomy

There are 2 parts. Console and Gateway.

Console

The console is the user’s workspace. It helps to create projects, upload source code, compile the packages and build the images, startup and shutdown the website, monitor the status.

Gateway

Gateway is forwarding the internet traffic into your website. Gateway knows your website instance’s ip address, port number and other info.

Author: Jaynsw

Version: 20190603

--

--