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.
Click on the “Dreamland UI” button. This will open a new tab:
Expand the “Network” dropdown and select “blackhole”.
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.
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:
Enter your email, then select?Dreamland/blackhole?from the network selector dropdown list. Finally, click on "Login with Github."
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:
Create a Project
Once logged in, you’ll be redirected to the projects page.
Click on the “Create Project” button.
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.”
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:
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.
On the left side, you’ll see a list of resource types:
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.
Then click the “+” button. This will open a “New Function” modal.
To proceed quickly, we’re going to use a helpful shortcut. Click on “Template Select.”
For the purpose of this article, we’re going to choose the “ping_pong” template.
Then close the modal by clicking on the “X” button. Notice that most fields have been pre-filled for you.
Click on “Select Domain,” then choose “GeneratedDomain”
Now, switch view to “Yaml”
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:
Finally, click on “Code” to switch to the integrated code editor.
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.
领英推荐
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.
Review your configuration changes:
Review your code changes:
Enter a commit message:
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.”
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.”
Then, click on “GeneratedDomain.”
Copy the domain’s FQDN.
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.
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
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.
Now on the login page, enter your email, and ensure that?Taubyte's Sandbox Network?is selected.
Click the “Login with Github” button. Then, click “Import Project.”
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.
Now, you should see your project appear on the projects page.
Click on it to open the project. Once the project opened, navigate to “Domains”, then delete the domain generated by dreamland.
Then click on the “+” button to create a production generated domain:
Make sure you name it “GeneratedDomain” and toggle the “Generate a domain” option. Click on the checkmark button to confirm.
Next, navigate to “Functions” and click on your function.
Next, click on the “Code” tab and then modify the message that the function returns.
Don’t forget to click on the checkmark button. Then, click on the push button located on the bottom right corner.
Review your diff, add a commit message then push!
Navigate to “Builds”
You should see two jobs just like in dreamland
Once the jobs are done, go ahead and navigate back to “Functions”. Then click on the thunderbolt icon.
Clicking on the thunderbolt icon will open a new tab displaying the function’s HTTP URL.
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?