Hello builders, Many of you knows me but in case I am Priyanshu Verma, An Open-source Indie Developer.
In this Article we are going to talk about how you can deploy Fluvio integrated apps like APIs on internet for free. It is very easy to do so, As Today I will guide you how to. So, Without any delay let's see what to do.
As To deploy fluvio we need a project with it's integration. I have one from recent Fluvio Series. This is a basic Nodejs Express API with some endpoints and fluvio integration. I won't explain more about it you can explore this on GitHub. This article is just for deployment.
My Project Tree
See the Project tree as that will help in understanding what I am say in later sections.
1. Create an account on Infinyon Cloud
You need to create account on Infinyon Cloud to make a cluster.
2. Install Fluvio CLI Locally
You need to install Fluvio CLI locally for testing and adding connectors to cloud cluster in case we will add a sinker
in a topic named stocks-sinker
from a file in side cloud
folder named sinker.yml
you can see in project tree.
To install Fluvio CLI follow official Website. Or follow me
Run command inside you terminal make sure on windows you use WSL.
After installation you need to add Fluvio to PATH by
Now you will be able to use fluvio
command in your terminal. If not then try again.
3. Login with your Credentials and push connectors
Now, We are going to login with our email and password in Fluvio CLI so, that we can have access to Cloud Clusters. To do so run command
It will ask for Email and Password Use what you created when signing in InfinyOn Cloud account. You can check your clusters by command
If you have any then it will show you else it will show No clusters found
. You can create cluster by the command
it will show something like this
You will get any other Profile name at place of withered-frog
.
Now, What you need to do is switch you profile to what you have created for me it is withered-frog
. By default after creating a cluster you would be on that cluster's Profile. If you are not then switch to that. You can check it by command
on case To switch use command
<profile name>
is the cluster you created in my case it would be withered-frog
.
Now, Let's Push our connector on Cloud cluster which is
/cloud/sinker.yml
I will change this http://deployed.url/sync
to deployed URL later.
It is for my example project yours can be different and more then one.
To Push this connector will use command
You will get something like this
You can have multiple connector can be created similarly.
4. Store Credentials To Deploy and Dockerfile
From here we have two ways to build Docker Image for the Project. It depends on the Public and Private Project if your project is private and you can keep sensitive secret files in your codebase then you can go with approach A if your project is Public then you should go with approach B. You can select any method and tweak that with different tricks to save secrets.
Approach A
For this I am assuming you have a codebase that can keep secret config files. To deploy we need a config
file that we can use to login on server to get that inside terminal we need to export our profile by the command
It will export all configs in a file named config
inside the folder.
Now, Create a Dockerfile
like in project tree.
With the code of your project deploy pipelines
You can see it is self explanatory as the main thing is installing fluvio and adding config file that we exported to the path /root/.fluvio/
.
You can also change the default path of fluvio config by adding a environment variable FLV_PROFILE_PATH
. For now, I just copied to default path.
This was the first approach. Now you can deploy this on any free Platform with docker Image.
Will tell how to deploy after telling second Approach.
Approach B
This is if your project is public on GitHub or if you can't keep secrets in codebase.
You also need to create a Dockerfile
like this
Here also we are doing same thing installing fluvio and running a file named entrypoint.sh
which we have in codebase you can see in project tree.
Let's see what is inside the file entrypoint.sh
.
Here you can see, We are getting FLUVIO_CLOUD_EMAIL
and FLUVIO_CLOUD_PASSWORD
from environment variables and logging in. Then we are syncing the config file.
You can set Environment Variables without exposing them and making it save.
Final Deploy
These were two methods to build Docker Image that we can deploy easily.
You can build Docker Image and publish that online like on Docker Hub to deploy that. For simplicity I will use GitHub to store my code and then deploy it with Approach B
. I will use Render to deploy the Docker Image.
Firstly, Push the code to GitHub and create an account on Render. After that goto dashboard and create a new Web Service.
After that Connect to GitHub and Select your project or fetch deployed Docker Image by Clicking Existing Image
Then select Docker in language
If you are doing with Approach B then add your environment Variables here like this
Then Deploy the Project and You are good to go 🎉! This was the simplest Article about how you can deploy Fluvio using Docker and Render.
Example Project GitHub HERE.
Try to give some approach to fellow developers how they can put secret config file in comments.
Thanks for reading....