MARTIN OMANDER: Hi, Veer.
VEER MUCHANDI: Hello, Martin.
MARTIN OMANDER: So you are an App Modernization Solution
Manager at Google, right?
And you have an app for us to modernize today?
VEER MUCHANDI: Yes, we have a Legacy two-tier Node.js
application running on a VM.
And we want to modernize it using serverless technologies.
The VM is costing us money 24 by 7.
Also, we have to assign someone with the right operation skills
to maintain it.
We'd like Google to do that for us.
MARTIN OMANDER: All right.
And does the team running this app know containers?
VEER MUCHANDI: The team has started the containerization
journey.
They considered Kubernetes, but they don't have
enough experience with that.
MARTIN OMANDER: A lot of organizations
are in that place.
Let's migrate the app for them using
Cloud Run, which doesn't require them to learn Kubernetes.
[MUSIC PLAYING]
VEER MUCHANDI: This is what the app UI looks like.
It's a simple to-do list application.
Let me add a couple of to-do list items
about modernizing this application.
MARTIN OMANDER: Got it.
What does the architecture look like?
VEER MUCHANDI: Here it is, a web frontend,
and Node.js backend, and a MongoDB database.
The HTML and JavaScript for web frontend
is served by the Node.js backend.
MARTIN OMANDER: Does the app use server-side sessions
or any other storage outside the database?
VEER MUCHANDI: No.
It's a simple app where all the users see the same content.
All the data is in the database.
Let's keep the database as is for now.
We'll move the Node.js backend and the serving of HTML
to Cloud Run, then we can shut down that VM.
MARTIN OMANDER: That makes sense.
Let's look at the database machine for a minute.
VEER MUCHANDI: We need to set up a serverless VP
connector from Cloud Run to this database.
MARTIN OMANDER: Right.
Let me click the Serverless VPC connector option here.
And then I'll create one.
I'll give it a name, and I'll use all the default settings.
And now let's create it.
This will take a minute, so let's get
started on the next step.
VEER MUCHANDI: Let's have a look at the source code here.
This is a Git repo, which is good.
Most of the enterprises want their code protected,
especially when the development is done offshore or remotely.
Think COVID, right?
I'm going to use a browser, browser-based editor that
works like VS Code but doesn't depend on my workstation.
MARTIN OMANDER: Good idea.
Editing the code in the cloud also means that it
doesn't matter what version of Node.js--
NPM, et cetera-- that you or I have on our laptops.
VEER MUCHANDI: Right.
First, I'll open the Google Cloud shell here,
which gives me a command line in the cloud.
Now that I have a command line, I
can run a Git clone of this repo.
MARTIN OMANDER: All right.
And then you'll edit it in the cloud?
VEER MUCHANDI: Yeah, I'll click here to start the cloud editor.
This editor looks and feels similar
to a traditional editor, like VS code running on my laptop,
but it runs in the cloud.
MARTIN OMANDER: All right.
The Cloud Run docs say that our code
should listen on a port defined by the port environment
variable?
VEER MUCHANDI: Yeah.
Here it is.
It looks like the existing code already
does that so we don't have to change anything.
If the port had been hardcoded here, we have to change it.
MARTIN OMANDER: Right.
How does the code connect to the database, Veer?
VEER MUCHANDI: Well, let's see.
It looks like it reads the connection parameters
from the environment variables, as well.
Whoever wrote this application knew what they were doing.
MARTIN OMANDER: Yeah, well done.
Veer, do you think we should write a Docker file
and build a container ourselves for this app?
VEER MUCHANDI: Well, we could.
It's not very hard.
But the team isn't very comfortable with containers
yet.
So let's deploy from source code and use Buildpacks instead.
MARTIN OMANDER: Yeah, that makes sense.
It's a Node app so we should probably run NPM install first.
VEER MUCHANDI: OK, I'm doing so now.
Now that all the packages have been installed,
I will prep the gcloud run deploy command.
MARTIN OMANDER: Right.
We need to tell Cloud Run about the VPC connector
and the environment variables.
VEER MUCHANDI: Absolutely.
We can also set all that in Google Cloud console,
but the team wants things done from the command line
so they can automate it later.
Here is the gcloud run command with all the environment
variables, with database connection parameters.
I'm also adding the VPC connector.
MARTIN OMANDER: Hmm, very nice.
VEER MUCHANDI: Let's run it.
It's asking me a few follow-up questions here
about region and such.
I'll answer them.
MARTIN OMANDER: All right.
It looks like the build is running.
Let me open the build log here in the Cloud Console.
Uh-huh.
Yeah, it looks like things are happening here.
The Buildpack is taking our source code
and building a container from it without us
having to create a Docker file or know anything
about containers.
That makes it easy for developers.
VEER MUCHANDI: It looks like the build is done now.
Look at the container is replaced.
MARTIN OMANDER: Uh-huh.
Ah, there is our container.
VEER MUCHANDI: Now let's go to the Cloud Run in the Console.
MARTIN OMANDER: Let's see.
Yeah, there's our deployed service.
The URL is shown here.
Let's hit it.
VEER MUCHANDI: Hmm, look at that.
The app is working.
And we are seeing the same to-do list items in the UI
as before, when this app was running in the virtual machine.
And now I can mark these two to-do list items
that I created before as done.
MARTIN OMANDER: Right.
That reminds me, we don't really need that virtual machine
anymore, do we?
VEER MUCHANDI: We don't.
Let's turn it off.
MARTIN OMANDER: All right.
I'm navigating to Virtual Machines.
There it is, and I'm deleting it.
VEER MUCHANDI: Feels good, doesn't it?
We moved code from a virtual machine
that was costing us money 24 by 7 to Cloud Run
where we pay for CPU and memory usage
only when the request is being served.
If we get less traffic at night, we pay less.
And if we get no traffic on weekends,
we don't pay anything at all.
MARTIN OMANDER: Right.
And even if the container is ready to serve requests,
we don't pay anything until an actual request comes in.
Also, we do not have to assign anyone
to maintain the virtual machine.
Veer, will the team build new versions of this web app?
VEER MUCHANDI: Yeah, I think they probably
will need a CI/CD pipeline for that,
but that will be a story for another day.
MARTIN OMANDER: Sounds good to me.
Thank you for watching, everyone.
If you have any questions for Veer or me,
let us know in the comments.
Also, let us know what you thought of today's episode
and other serverless topics you'd
like to see in the future.
Until next time.
[MUSIC PLAYING]