What’s new in App Service for Java developers on Linux | Azure Friday

>>Hi, I’m Donovan with
another episode of Azure Friday. I’m here with [inaudible] and
we’re going to learn about using Java in App Service.
Welcome to the show.>>Thank you Donovan.>>So, what do you do
here at Microsoft?>>I’m an Engineer in
the App Service Team, and I’m working on
Java on Apps Service.>>All right. Perfect. So, I’ve used Java in App Service before, but when I did it in the past, it was all on Windows. And now that I know that we offer a Linux-based App Service, but I think I
remember doing that, I had to do it inside of
a container. Has that changed?>>You are correct. Until very recently, the only way of
creating Java apps for Linux used to be creating your docker
container on your own, and bringing that along to App Service when you
created your Java app.>>Okay great. So, we’ve
made some advances there where that’s no
longer a requirement?>>That’s exactly what
I’m going for demo today.>>Okay.>>Essentially, you might
be a Java developer who doesn’t want to build
your own docker container, and might want to
get started quickly.>>Okay.>>So there’s something for me, something over here that I’m going to show
you that right now.>>All right, perfect.>>So, I’m right now in the middle of
creating a Java app.>>Okay.>>Our choice of
Windows or Linux. I’m going to just
choose Linux here, and as you can see,
the moment I do that, I have a list of
options to choose from. What’s new here is
the Java section here. As you can see,
you can now create a Java app using Tomcat
8.5 or Tomcat 9.>>Okay.>>This is essentially what makes it easy to create a Java app without
bringing a container.>>Got it. So, all
I have to provide for you then is the wav file?>>Exactly.>>Okay got it. Great.
So this is going to be deploying just like I was
deploying to my own server. I wouldn’t have to
worry about again, about the docker overhead. Now, I shouldn’t say
it’s overhead, but if you don’t know docker, you had to first go
learn what is docker, how do I build an image
simply so I could use App Services
with Java on Linux. And now, it’s like hey, if you already know how
to build a wav file, you’re ready to rock and roll?>>Exactly. Plus you can focus on your application while we take care of managing
the rest for you.>>All right, perfect.
So I would then choose whichever Tomcat
I want to target, and then go off and
create my App Service.>>Yes. So lets say
I chose Tomcat 9.0, and I’m creating the app.>>Okay.>>In a few seconds,
the app would be ready, and you would be shown a landing page
something like this.>>Okay, perfect. And then how
do I get my app there now? I know I can do FTP, but are
there other options there?>>Yes. There’re a bunch of
options that you can do. People have been
using all kinds on mechanism to deploy
the application. So, I’m going to
demo something that will be able to buff on the same, but in a much better way
because I’m going to explain to you what
are the issues with any system mechanisms.>>Okay.>>Before that, I wanted to show you something real quick.>>Sure.>>So let’s say you
created this application. Now, because the container is
not managed by you anymore, it’s managed by Apps Service, you might have a requirement
to customize Tomcat. And this time, Tomcat
is not in your control because the container is
not really built by you.>>Interesting so, it’s
interesting because we’ve just said that,
as a Java developer, you no longer have
to deal with docker, but behind the scenes,
it still is a docker container
being executed.>>Exactly.>>Got it. You just don’t
have to worry about it, and we’re going to allow you
to then deploy your wav file into that container that
we’re managing for you.>>Yes.>>All right.>>So an app is created. There is a docker container that created behind the scenes. It’s just that it’s
managed by us.>>Got it.>>When you scale
out app, there are multiple docker instances running behind the scenes for you.>>Got it. And then what
you’re talking about now is a problem
that we all have. When you install Tomcat, there’s usually a config file
which you want to go in and tweak some values in. And that’s always
a pain because you have to set the admin password first so that you can
go in there and get in there, it’s been a challenge. And you’re going to show us how I can now modify that file.>>Yes.>>To customize Tomcat.>>Yes. So let’s take
some real examples. Maybe you are a developer, and you want to
change the name of the log file that is
generated by Tomcat.>>Okay.>>Let’s say the
site access logfile.>>Okay.>>So, I’m in the Kudu Console for one
of the apps I created.>>Okay.>>I’m going to SSH
to my container.>>I see.>>So this is the docker container
which is running Tomcat for you behind the scenes.>>Okay.>>I’m going to change over
to the /home directory. This is a special directory. It provides for
assistant storage, which means when your
application crashes or reboots, this storage is still available
for you across reboots. Also when you scale
out your application, this directory is shared up
across all your instances.>>Okay.>>Now, I’m going to create
a directory called Tomcat. This name is important. It has to be Tomcat in
the /home directory.>>Okay.>>And all I’m going
to do now is copy over the default Tomcat
configuration files from the original
location over here.>>Okay.>>And now I have a clone of the original Tomcat
configuration files.>>Got it.>>I’m going to just head
over to this directory, and open the server.xml file. This is the file that defines where the site access
logs are generated.>>Okay.>>As you can see,
this is the file. I’m simply going to
change the name of this file say,
FRIDAYDEMO_site_access_log. All I have to do is save
this file, and I’m done. Next time I had this application, Tomcat is going to pick the configuration
from this directory, and you will see the site access logs going
to the new location.>>Got it. And because
this is a shared location, even if I scale this up, all my new instances of those containers are also going to read
the same information.>>Yes.>>The same configurations
generate the same log for us.>>Yes.>>Got it. Okay, no
this is really cool because this has always
been a pain point. And obviously, your image
is smart enough to realize that once I do this, create this specific folder
under home called Tomcat, that that’s where you’re supposed to get configuration from?>>Yes, and that’s why it
needs to be called Tomcat because the way Tomcat is
configured in this container, it knows that if
it finds something in the /tomcat directory, that’s the custom configuration
it needs to pick.>>Perfect. And it has
to be all lowercase for those windows developers
out there who are.>>Yes, exactly.>>Type it in mixed case and
wonder why it doesn’t work. So, all lowercase
Tomcat tapping in your config from
the installed location, and any modifications you take there are going to
override the default.>>Yes.>>Perfect. All
right, great. So, now that I have this
set up correctly, I still need to get
my bits there right?>>Yes. And let me talk to you about what you touched
base upon even earlier. How do you get your bits there? The most popular way
of deploying to Java apps has been to upload
the wav file using FTP.>>Sure.>>Now this works
great when you have a single instance of
that application running.>>Right.>>What happens is, when
you upload a wav file, Tomcat unzips it into a separate directory and loads
the application from that.>>Right.>>This is all fine but the moment you scale
out your application, multiple Tomcat instances
are going to race to unzip the wav file into the directory that we
just talked about. As you would expect, this leads to all sorts
of locking issues, and it’s basically
a risk condition that’s yet to be solved.>>Okay.>>So yours where we’ll deploy a new deployment mechanism
that am going to demo now is going
to come in handy.>>Okay.>>So this is API built
into the Kudu site. It is available for
both Windows as well as Linux.>>Perfect.>>So when we are
talking about Linux, this works perfectly
fine for both platforms.>>Okay.>>What it does is, when you publish
our application using this API, it takes care of safely unzipping the wav file on behalf of Tomcat, so that Tomcat doesn’t run into the issues that we just saw.>>Perfect. Okay.>>So as a demo, let’s see how I can use Maven.>>Okay.>>To use the already deployed
API for publishing my app.>>Sounds good. So this is a simple
Todo List Application. It’s built using Spring Boot.>>Okay.>>It lets you manage
your Todo List. So, I’m going to look at
the BOM Load XML file. This is the BOM XML file for the Todo List Application
that I just showed you. The interesting section
here is this. As you can see, we are defining the name of the
application we want to create. There are a bunch of other
things that we define here, the resource group and the region in which we want to
create the application. Also, there are a bunch
of app settings here to configure the database you want be use to
store the Todo items.>>Sure.>>Another interesting
thing here is this. This tag essentially tells
the plugin to go and create a Java application
running on Linux. This is the information that the plugin interprets as a hint for creating
a Linux application.>>Got it, okay.>>And this is what tells
the plugin to go and create a Java application running
Tomcat 8.5 and GiD 8.>>All right, perfect.>>We have a choice
of creating Tomcat 9 too as we saw in the portal, this is just creating a
Tomcat 8.5 application.>>Okay. So if I were to run this Maven and there’s
nothing inside of Azure, it would then create the
resource group and then deploy a Linux based app service
running Tomcat 8.5 for me, and then I would be
able to deploy into it. And if I were to run this again and the app service
already exists, it would just simply say, ‘It’s a no app, everything
is ready to go.’>>Yes, it’s another
important operation.>>Perfect.>>If the app exists,
it will not do that. It will not recreate the app. The only thing that will
happen is the WAR Deploy API will be used to publish the new breeds to
the application.>>Perfect.>>So I’m going to show
you how I can deploy this application to Azure.>>Okay.>>So, I’m going to use Maven, and I’m going to use the Azure Web App Plugin
to perform our deployment.>>Okay.>>So what this is going to do is go and create the
app if it doesn’t exist already, like
we just talked. It’s going to deploy
the WAR file using the Kudu API to the application. Like we discussed before, this works perfectly fine for
Windows as well as Linux.>>Okay.>>So once this is done, you will have a application
running which looks something like this.
This is my Todo list.>>Okay. So, this is great
and I’ve used Maven before. I used to be on the VSTS team, which is Visual
Studio Team Services. So if I had a choice, I’m going to try to do
the CI/CD inside of another tool, potentially VSTS. Is there another way
to get access to that Kudu API for WAR deploy versus just
using a Maven plugin?>>Yeah. So it’s essentially
just a REST API.>>Okay.>>So, Maven was just one of the many ways in which
our developers liked to deploy. So we started with Maven, but you can use the REST API
in a very raw manner. You can use Curl or you
can use PowerShell.>>Okay.>>So I can show you how
we can do that using Curl.>>Sure, please. So
this is just a post I’m assuming of the WAR file
to the API endpoint.>>Exactly. Yeah.>>Okay.>>So, I have a simple site here. As you can see, it’s very ugly. It’s a Hello World! site. I
don’t like the background.>>Sure.>>So, let’s see if
we can change it.>>Okay.>>I have a different version
of this application, which used to use
a different background. So I’m going to head
over to this directory. And as you can see, I have multiple versions
here, blue, dark-green. Let’s see if we can
change this to blue. So I’m going to
use Curl. Like you guessed, it supports Curl.>>Okay.>>And I need to use credentials to access
the Kudu endpoint. So I have my username and password defined as
environment variables.>>Are these the same username
and password I would use for FTP or the
publish profiles?>>They are essentially the same.>>Okay. So, do I just go
to the app service and I can get the username and
password from there?>>Yes.>>Okay.>>You have a choice of using either your deployment
credentials or the site credentials. The FTP credentials that you just referred to are
site specific credentials. So if you have
10 different sites, you would have 10 different
sets of credentials. But, because you are the same person
creating those sites, you have a common set of
credentials for all your sites. Those are your
deployment credentials. So you can use any of those. So I’ve already defined environment variables in
the interest of time. And I need to get a hold of the Kudu
URL because like I said, War Deploy is a Kudu API.>>Sure.>>So I’m just going
to copy the site URL, paste it here and then go on and tweak it
to point to Kudu. So as you know Kudu, basically is a slightly different URL. This is the Kudu URL, and
the API is WAR Deploy. And I’m going to specify what
WAR file we want to use. So let’s use blue. I use dark.>>That’s fine. As long
as it won’t be green, then we’ll know if
it actually worked or not then we’re going
to switch to blue now.>>Yeah, it’s pretty
quick. So like we said, this is talking to the Kudu API, and the Kudu API is
going to take care of unzipping this WAR and
putting it in the directory.>>So just that quickly, you
actually deployed twice; the dark one and then
the blue on top of it.>>Yes. But at the same time
this is a small WAR file, so it really depends
on the payload.>>Sure.>>This is just a REST Curl. So, it’s essentially just going to be proportional to
the size of your WAR file.>>It makes perfect sense.>>So let’s see if this worked.>>Awesome.>>So that’s your new
WAR file using Curl.>>And very nice. I’m really
excited to start playing with this because I write tools that deploy the app service. And being able to just use
the WAR file directly without having to again go
through the gymnastics of creating a docker file, or rezipping it, or
repackaging it so that app service will play nice is really exciting, and
I’m looking forward to it. So, if I want to learn more about this WAR
deploy, where do I go?>>Sure. So like I said, it’s a Kudu API, and Kudu is open source and available
on GitHub for you to see.>>Okay.>>There is a wiki page in the Kudu wiki which talks
about wardeploy in detail. It talks about some things
that we already talked about, why I essentially need this API, what are the issues when you use FTP to publish your application, and how this takes care of that. We talked about using Curl
for doing a deployment. This also has an example of how you could use
PowerShell for doing that.>>Perfect. So we
can target it from both Windows and from
Mac or Linux as well.>>Sure. The plan
could be any of those, and the apps could also be
running on any of those.>>That’s awesome.
Thank you so much for coming and showing us
all this cool stuff. We’re learning all
about running Java apps inside of app service
here on Azure Friday.

Danny Hutson

Leave a Reply

Your email address will not be published. Required fields are marked *