Developing & Deploying on Akash

figurestudios
8 min readOct 19, 2021

--

This guide will go through the development, dockerization, and deployment of Node applications on Akash — which is something that a lot of new developers don’t already know.

Introduction

When I first came to Akash, I had no idea what Docker was, how it worked, or how to use it for my personal applications. I also had no idea how the Akash SDL worked, or how anything worked, really.

Using the Akashlytics Deploy Tool, I was quickly up & running with pre-made applications such as the PKT mining example, but this didn’t help me run my own applications on Akash. And on top of all this, there are no tutorials that go through the entire process on Akash — everything is separated.

Here, you’ll learn everything you’ll probably need for most simple applications on Akash. Hello World’s, websites, Discord bots, Steam bots, etc. If you get stuck anywhere, you can always ask for help in the Akash Discord.

Requirements

Before you start this guide, please go through this list and install/do everything. Not doing this can make you run into errors or have some other issues down the road.

Setting up the environment

Press the Windows Key on your keyboard and search for ‘Node.js command prompt’ and open it.

To create a folder named ‘hello-akash’, run this command:

mkdir hello-akash

Navigate to that folder with this command:

cd hello-akash

Open Visual Studio Code with this command (you can also just search for it):

code

Current command prompt
This is the Path in my case

Now you should have opened Visual Studio Code and if you’re lucky, you might already be in the proper directory. If not, press ‘Open Folder…’ and navigate to the Path you just saw in the Node.js command prompt. Press ‘Select Folder’ once that’s done.

Current Visual Studio Code
Current Visual Studio Code

Now, you should have a page that looks similar to this. Pay close attention to the ‘HELLO-AKASH’ text near the top-left corner.

Current Visual Studio Code

Lastly, we can create our application file by pressing CTRL + N and CTRL + S. Name it ‘main.js’ and make sure it has the correct file extension.

Saving the application file

Starting to code

Hopefully, you already know a bit of how NodeJS works and some details surrounding that, as I won’t go too in-depth on these parts.

In Node, we’re basically going to use Express with its ‘Hello World’ example that comes with it.

Go back to the Node.js command prompt and type this command:

npm install express --save

If you didn’t close it last time, the full window will look something like this:

Current command prompt

A very important thing to do now is to write down all packages you install, preferably with versions, and we’ll get to why later.

Going back to Visual Studio Code, you should now have a screen that looks like this:

Current Visual Studio Code

Now, we can finally write code like normal inside this file.

Copying the contents from this page gives us something like this:

Current Visual Studio Code

This is what we’ll be using for this tutorial. What the code does is basically set up a webserver on port 3000. When someone accesses this webserver, it will respond with ‘Hello World!’.

To start the webserver, we will use this command in the Node.js command prompt:

node main.js

Now, the webserver is active on the correct port:

Current command prompt

If you open http://localhost:3000 in your browser, you will now see a page that looks like this:

Current tab at http://localhost:3000

And this is everything we’ll need JS code-wise!

Creating & Configuring the Dockerfile

This part is the most confusing for new people. A reference can be found here in case you want to read more, or use commands which I haven’t covered in this guide.

Just like we did with the ‘main.js’ file, we will create our Dockerfile by pressing CTRL + N and CTRL + S. Name it ‘Dockerfile’ and make sure there are no file extensions:

Now, fill the file with this content:

FROM node:alpine

# This line basically says ‘we need to use this light-weight version of Linux which has Node pre-installed’

EXPOSE 3000

# This line opens port 3000

COPY . /app

# This line copies everything from the directory (.) in to the folder (/app)

WORKDIR /app

# This line says that we want to run all commands within the folder (/app)

RUN npm install express

# This line installs the node package express. This is why it’s important to write down all packages you’re using. Sometimes you’ll need to save the specific versions when you’re installing packages too!

CMD [ “node”, “main.js” ]

# This line runs the command ‘node main.js’

The Dockerfile should look like this in Visual Studio Code:

Current Visual Studio Code

Building & pushing the Docker Image

Press the Windows Key on your keyboard and search for ‘Docker Desktop’ and open it.

Now, near the top-right corner, you should see a ‘Sign In’ button in case you haven’t logged in already:

Current Docker Desktop

Click that button, enter your details, and then press ‘Sign in’.

Current Docker Desktop

Now, we can go back to the Node.js command prompt.

Press CTRL + C to exit the Node application.

Now, type this command, and change it to include your Docker name instead of ‘figureprod’ (which is my username there):

docker build -t figureprod/hello-akash:1.0.0 .

To then push it to Dockerhub, we can run this command:

docker push figureprod/hello-akash:1.0.0

It all should look something like this in the command prompt:

Current command prompt

We can now see the image, hosted at Dockerhub. This is how we’ll reference it later on:

docker-name/image-name:version

In my case, it is:

figureprod/hello-akash:1.0.0

Testing our Docker Image

Going to our Node.js command prompt, we can simply type this command to start our application again. As previously, change ‘figureprod’ to your own username, as that’s what you’re going to have to do in a real-world scenario.

docker run -p 3000:3000 figureprod/hello-akash:1.0.0

It will look just like when we ran the NodeJS file:

Current command prompt

And just like last time, we should be able to view the page at http://localhost:3000:

Current tab at http://localhost:3000

Deploying onto Akash

Surprisingly, with the GUI tools available on Windows, this is one of the easier parts of the tutorial.

As we did previously, press the Windows Key on your keyboard and search for ‘Akashlytics Deploy’ and open it.

If you don’t already have a Keplr wallet, please take a look at this guide. After this, you will also need to make sure you have more than 5 AKT in your wallet.

After opening Akashlytics Deploy, you’ll see a window that looks like this:

Current Akashlytics Deploy

Enter your seed phrase/12 words/mnemonic phrase in the first input field, any name you want in the second, and a password you can remember in the third. The page will look like this after that:

Current Akashlytics Deploy

Near the top-right corner is a button that says ‘CREATE CERTIFICATE’. Press this and then approve it:

Current Akashlytics Deploy

Now, you can create your deployment by pressing this button:

Current Akashlytics Deploy

Choose an empty template, scroll down, and press ‘CONTINUE’:

Current Akashlytics Deploy

In the dark field that comes up, enter this content. If you want to understand more of how they work, please refer to this page on Stack Definition Language (SDL).

If you have built your own image, change ‘figureprod’ to your own Dockerhub username.

Current Akashlytics Deploy

Scroll down and press ‘CREATE DEPLOYMENT’, then ‘DEPOSIT’, and lastly ‘APPROVE’.

Current Akashlytics Deploy
Current Akashlytics Deploy
Current Akashlytics Deploy

You will now be able to wait for bids to come in. Select one and press ‘ACCEPT BID’ and then approve the transaction.

Current Akashlytics Deploy
Current Akashlytics Deploy

After waiting a bit, you will get a page that looks like this:

Current Akashlytics Deploy

Near the bottom, there is a long address (here, http://r7o69u1nidae1f7lkg5iiupjp8.ingress.provider-0.prod.ams1.akash.pub) which will be the web address you will access your deployment from.

Opening this web address prompts me with this:

Current tab at http://r7o69u1nidae1f7lkg5iiupjp8.ingress.provider-0.prod.ams1.akash.pub/

And that’s it. We did it!

Advancing

To do this with your own applications, all you need to change is:

  • The contents of the Dockerfile
  • The code and files in the directory
  • The version and optionally the name of the image

If you want to keep sensitive details like secrets, passwords, and similar, you can take a look at this guide on how ENV variables work. The reason why we don’t just hardcode this is that all code on Dockerhub is public, so we need to send these details privately to only the provider to avoid people snooping.

--

--