Create a Serverless Project That Runs WebAssembly & Scales Horizontally (Edge-Native)

Create a Serverless Project That Runs WebAssembly & Scales Horizontally (Edge-Native)

Traditionally, getting something like this off the ground would require a lot of work, and probably a highly skilled team of software developers and DevOps. However, thanks to the recently open-sourced autonomous cloud computing platform, Taubyte , it’s not only possible but also easier than building on Firebase or any similar proprietary platforms.

Thinking ahead, the team at Taubyte created Dreamland, a parallel project to the server-deployable one, that allows us to run a local cloud.


Dreamland

Let’s begin by downloading Dreamland, a tool that allows us to run a local serverless cloud computing platform. To do this, execute the following command:

curl https://get.tau.link/dream | sh        

For more details about Dreamland, visit?https://github.com/taubyte/dreamland. As a burgeoning project, it greatly benefits from support and community engagement. If you find it valuable, please consider giving the repo a star.


Start a local cloud (Universe in dreamland terminology)

With Dreamland now installed on your system, let’s initiate a universe. Execute the following command:

dream new multiverse        

This command launches the Dreamland service, referred to as the “multiverse”, and simultaneously starts a default universe within, named?blackhole.

For convenience, if you wish to retain your projects between Dreamland sessions, you can utilize the?--keep?option. This ensures you won't need to import your projects every time you start Dreamland:

dream new multiverse --keep        


Visualize your universe

While we’ll delve into the command line in detail later, let’s start with a visual perspective. To view your universe, visit?https://console.taubyte.com.

No alt text provided for this image

Click on the “Dreamland UI” button. This will open a new tab:

No alt text provided for this image

Expand the “Network” dropdown and select “blackhole”.

No alt text provided for this image

This will display a universe (or network) consisting of nine nodes. Taubyte Clouds operate on a peer-to-peer basis, and by default, Dreamland will establish mesh connections amongst all the nodes.

Although Dreamland is resource-efficient, if you’re looking to further reduce resource usage, you can delete the?elder,?client, and?seer?nodes as they aren't necessary for basic operations. To do this, simply click on the respective node to access the subsequent modal.

No alt text provided for this image

You also have the option to create a slim universe right from the beginning. We’ll explore this in a subsequent post.


GitOps

Taubyte has embraced a design centered around a concept called GitOps, which uses a Git repository as the source of truth instead of exposing APIs directly. The main advantages of this approach include verifiability, ease of roll-back, and auditability.

Thus, to interact with a Taubyte Cloud (including Dreamland), you’ll primarily engage with GitHub repositories.


Connect using Web Console

While we’ll delve into the CLI in another post, let’s initially provide you with a graphical overview of the platform’s capabilities. Return to the previously opened tab:

No alt text provided for this image


Enter your email, then select?Dreamland/blackhole?from the network selector dropdown list. Finally, click on "Login with Github."

No alt text provided for this image

If you haven’t logged in before, the system will prompt you to grant permission to your GitHub account. It’s important to note that these permissions are constrained to the frontend and are utilized for the following purposes:

  • Listing Repositories:?It can enumerate both your public and private repositories, identifying which among them are projects on a Taubyte-based Cloud.
  • Repository Creation:?Web Console has the ability to generate new repositories, specifically for Projects, Websites, and Libraries.
  • Web-hook Configuration:?This permission facilitates the setup of web-hooks on the relevant repositories.
  • Cloning and Pushing:?So web console can clone repositories and push updates to them. Remember Taubyte-based Clouds are GitOps only.

Create a Project

Once logged in, you’ll be redirected to the projects page.

No alt text provided for this image

Click on the “Create Project” button.

No alt text provided for this image

Give it a name and, if you prefer, set it to “Private.” Note that setting it to private means the repositories backing it up will be private. Then click on “Create Project.”

No alt text provided for this image

Upon taking this step, the system will establish two distinct repositories: one dedicated to configuration and another for inline code. The rationale behind segregating these repositories revolves around two pivotal considerations:

  1. Access Control & Visibility:?In many enterprise environments, the team responsible for overseeing project configuration may not overlap with the team actively involved in code development. By keeping these repositories separate, organizations can more effectively control who has access to what. Furthermore, there could be instances where certain secrets or sensitive data are stored in the configuration repository. By compartmentalizing these two aspects, organizations can opt to keep the configuration private, thereby safeguarding any sensitive information, while still making the codebase publicly accessible.
  2. CI/CD Optimization:?Continuous Integration and Continuous Deployment (CI/CD) processes can benefit from this dichotomy. Builds that hinge on configuration are generally more lightweight, often not necessitating actions such as spinning up containers. By distinctly housing configuration and code, the system can efficiently determine what needs to be built without delving into intricate evaluations of what has been modified. This streamlined approach not only simplifies the CI/CD pipeline but also expedites the overall build process.

No alt text provided for this image

Next, the project repositories will be cloned inside a browser-based virtual file system.


A Quick Tour of Today’s Possibilities

Once the repositories are cloned, you’ll be redirected to the console’s main project dashboard.

No alt text provided for this image

On the left side, you’ll see a list of resource types:

  • Applications:?Used to organize your project. An application can only access resources within it or those global to the project.
  • Functions:?Serverless web assembly functions. These are often referred to as dFuncs due to their distributed/decentralized nature.
  • Libraries:?Separate repositories designed to produce WebAssembly modules. Libraries can be referenced by functions or SmartOps. They are particularly useful for code reusability, interoperability, and access control.
  • Websites:?These are also separate repositories. The content is built into an asset archive that can be served via HTTP. Use this for front-end interfaces or entire websites.
  • Storage:?This is edge-native CRDT-based object storage.
  • Messaging:?A serverless pub-sub system.
  • Database:?Edge-native CRDT-based key-value store.
  • Domains:?This section handles DNS domains and sub-domains.
  • Services:?Peer-to-peer services.
  • SmartOps:?These handle Just-In-Time Provisioning. SmartOps are similar to dFuncs but are triggered by provisioning events and have direct access to infrastructure primitives.


What Will Be Possible in the Future

On the Taubyte roadmap, consensus protocols, clusters, containers, and virtual machines are planned additions.


Your first Function (dfunc)

To define a function, click on the “Functions” button in the sidebar.

No alt text provided for this image

Then click the “+” button. This will open a “New Function” modal.

No alt text provided for this image

To proceed quickly, we’re going to use a helpful shortcut. Click on “Template Select.”

No alt text provided for this image

For the purpose of this article, we’re going to choose the “ping_pong” template.

No alt text provided for this image

Then close the modal by clicking on the “X” button. Notice that most fields have been pre-filled for you.

No alt text provided for this image

Click on “Select Domain,” then choose “GeneratedDomain”

No alt text provided for this image

Now, switch view to “Yaml”

No alt text provided for this image

Besides the?id, which will be generated once you've created the function, all other attributes are now defined. For now, take note of the following:

  • trigger: Defined as?GET /ping?on http/https.
  • execution: Defines the entry point (i.e., the function within the WebAssembly module to call) as?ping.


Finally, click on “Code” to switch to the integrated code editor.

No alt text provided for this image

We will delve into the code in subsequent articles. For now, it’s sufficient to note that the?ping?function (exported as?ping) is handling an HTTP request and responding with "PONG".


Click on the checkmark button to create the function.

No alt text provided for this image



Push Your Changes to GitHub

Everything you’ve done so far exists only in a virtual file system within the browser. To make your code available to the clouds you intend to use, including Dreamland, click on the green button in the bottom right corner.

No alt text provided for this image


Review your configuration changes:

No alt text provided for this image

Review your code changes:

No alt text provided for this image

Enter a commit message:

No alt text provided for this image

Done!


Inform Dreamland of the Push

Since a local Dreamland instance is unlikely to receive a webhook, we need to emulate this using what’s termed a “fixture”. Fixtures are invoked using the sub-command?inject.

To emulate a push, run:

dream inject push-all        


Build Jobs (CI/CD)

Return to the web console and click on “Builds.”

No alt text provided for this image

You’ll observe two jobs: one for code and the other for configuration. Both should be complete quickly. If the jobs don’t indicate “Success,” allow more time.


Test Your Function

In a production cloud, a DNS request targeting a node running the seer protocol would resolve the generated domain to a valid IP address of one of the available substrate nodes.

First, let’s retrieve our generated domain. Click on “Domains.”

No alt text provided for this image

Then, click on “GeneratedDomain.”

No alt text provided for this image

Copy the domain’s FQDN.

No alt text provided for this image

For me, the domain is?kjy2drfb0.g.tau.link.


Now, let’s associate this domain with localhost. To do this, add?"127.0.0.1 <your generated domain>"?to the?/etc/hosts?file. In my case, it'll look like:

127.0.0.1 kjy2drfb0.g.tau.link        

On Windows, the file should be located at?C:\Windows\System32\drivers\etc.

Next, let’s determine the port number of one of the substrate node. Switch to the Dreamland UI tab and hover over the substrate node.

No alt text provided for this image

In my case, the port is 11329.

Now, open your browser and navigate to:?https://<generated-domain>:<substrate-http-port>/ping

For me, the URL is:?https://kjy2drfb0.g.tau.link:11329/ping

No alt text provided for this image

Voila!


Push to a Public/Production Cloud!

Now that you’ve got your project up and running, you’re ready to make it public. Though you can use any Taubyte-based Cloud, we will use?sandbox.taubyte.com, which is free.

Switch back to the tab (console.taubyte.com) where your project is open and log out.

No alt text provided for this image

Now on the login page, enter your email, and ensure that?Taubyte's Sandbox Network?is selected.

No alt text provided for this image

Click the “Login with Github” button. Then, click “Import Project.”

No alt text provided for this image

This action will open a modal. To import a project, all you need are the config and code repositories. Type the name of your project into the “Config Repository” input field, and it will auto-complete to the corresponding configuration repository. Once you select the correct configuration repository, the code repository will automatically populate for you.

No alt text provided for this image

Now, you should see your project appear on the projects page.

No alt text provided for this image

Click on it to open the project. Once the project opened, navigate to “Domains”, then delete the domain generated by dreamland.

No alt text provided for this image

Then click on the “+” button to create a production generated domain:

No alt text provided for this image

Make sure you name it “GeneratedDomain” and toggle the “Generate a domain” option. Click on the checkmark button to confirm.

No alt text provided for this image

Next, navigate to “Functions” and click on your function.

No alt text provided for this image

Next, click on the “Code” tab and then modify the message that the function returns.

No alt text provided for this image

Don’t forget to click on the checkmark button. Then, click on the push button located on the bottom right corner.

No alt text provided for this image

Review your diff, add a commit message then push!

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Navigate to “Builds”

No alt text provided for this image

You should see two jobs just like in dreamland

No alt text provided for this image

Once the jobs are done, go ahead and navigate back to “Functions”. Then click on the thunderbolt icon.

No alt text provided for this image

Clicking on the thunderbolt icon will open a new tab displaying the function’s HTTP URL.

No alt text provided for this image

You’re all set! Your function is now live, and anyone with the URL can access it!


Conclusion

In this guide, we ventured into the realm of #edgecomputing & #serverless projects using Taubyte , a game-changing, open-sourced platform. With Dreamland, Taubyte ’s ingenious companion tool, we saw the ease of running a local cloud, simplifying a traditionally complex process. As the cloud computing landscape evolves, Taubyte stands out, simplifying #webassembly deployments and horizontal scalability. Embrace this new wave of edge-native development, for it heralds the future of seamless and efficient #serverless computing.


What’s Next?

In the upcoming post, I’ll guide you on how to use the?tau-cli?from Taubyte .

要查看或添加评论,请登录

Samy Fodil, PhD的更多文章

社区洞察

其他会员也浏览了