Deploy a Java Application to Azure using Continuous Integration
Join us for episode 2 in our series for DevOps for Java Shops! In this episode Brian Benz walks us through how to deploy a Java application to Azure App Service using GitHub Actions and continuous integration.
April: We’re back this week with the dev ops lab and we’re continuing our series DevOps for Java shops. So let’s welcome back, Brian Benz. Welcome back, Brian.
Brian: Great to be back. Thanks.
April: Really excited to have you back. So we’re gonna be building out our Java app a little bit more, and we’re going to be integrating that into GitHub actions today,
Yes. Yeah, this is going to be cool. What I did in the last episode as I introduced the application. Which is basically here. It’s just a little application with bit a and what it is, it runs on an Azure app [00:01:00] service and it connects to a feature manager in something on Azure called app configuration.
So I’m actually going to show you how to take that from GitHub today, and then deploy it out to. An Azure app service. The part we’re going to do today is just the build because the first time I run it, it’s going to fail and I’m going to explain why it fails and what you have to do. And this is a real world thing.
It’s kind of cool because you have a connection to string that this application relies on, which pretty much every application does. I could use a really simple demo that just runs when you deploy it, but that’s not really the way the real world works. So I am going to create an app service from scratch.
And then we’re going to fix something that needs to be fixed in terms of linking the application together with app configuration. So I get started with that. So here’s my Azure portal dashboard portal that azure.com is where you go for this. And I’ve got a repo on [00:02:00] GitHub that runs that code that I showed to just a second ago.
And what I’m going to do is I’m going to create a new resource.
And the resource itself is a web app.
And use my subscription. I’m going to use a resource group that I’ve already set up called dev ops for Java shops in Microsoft’s portal world. In Azure, you have to have a resource group for everything you do so you can group things together. The web app name is going to be dev ops labs. Let’s see if that works.
Nope. Have ups labs has already taken BB. There we go. It has to be firstname.lastname@example.org in order to work. So dev ops labs with BB we’ll do it. We’re going to have a runtime stack of Java because this is a Java application that runs on it’s a spring boot application that runs on Java.
Java 11 will be fine. You can have Jay boss Tomcat or Java se, we’re just going to keep it simple with Java se. And I’m going to use an app [00:03:00] service plan that I’ve already set up in west us two. And it’s called Java shops and it’s the lowest version of the Java shop, so you can get and that’s it.
So let’s go to deployment of we, I did everything. Deployment is where we’re actually gonna set up the CICT workflow. What this is going to do is create a good hub action for us. When we enable this GitHub action, it’s going to ask me. Select an order to select an organization. In this case, my GitHub account select a repository.
In this case, I want something called dev ops for Java shops, test feature flags. And by the way, I’ll, I’ll share a link at the end where you can find all of this and follow along later, if you’d like. We’re not going to able application insights because it’s just a demo. We don’t need any tags cause it was just demo.
So next thing is going to do is it’s going to create the web [00:04:00] app and it’s actually going to tell us the dis successfully deployed, which is a complete lie. It’s a complete, not truth. This is what happens in the real world. It deployed the app service. Yes, but the app. Didn’t
April: get deployed. So we have this running so well, it’d be our infrastructure.
Just no application running on it.
Brian: Yes. So it says, yeah, it really was great. I did my job, but it didn’t actually deploy the application because GitHub is where that happens. So let’s go over to get hub and I’ll show you that one back to my dashboard and I can open up dev ops for Java shops, test feature flags.
If I go to my actions, you’re going to see that this is actually. So it’s a Azure workflow. It’s a build and it works here. It’s called, that’s not the right one. It’s this one. So main dev ops labs, [00:05:00] BB Jamo, and it’s building and it’s going to deploy, but while that’s doing that, let me show you the code here.
If you’re going to get hub workflows, you can see I’ve got a couple of different, this is the demo app that I already had built. And this is the new one that we did. Yeah, we just deployed. Yeah, no, we just deployed. Yes. And it’s deploying this is a yellow file that automatically gets generated by Azure.
And there’s one thing we need to add to this file. Now, what I’ve done inside here, for those of you who want to follow along, I have created a provided GitHub workflow. Yammel file for you. And here is the actual. Connection string that we need to add. This refers to something called a secret that I’ve already set up.
So this connection string, there’s two things you need to change this, the publish profile and the connection string. In this case, it’s just quicker and easier if I change the existing Yammel and set that up. So let’s go back to our actions and by now it should have [00:06:00] failed. There it is. So it failed.
Okay, so it’s failed completely and it’s failed on the Maven build because it can’t find that feature flag. So what we want to do is we actually want to change this and to do that, I am going to use code spaces, which is a new feature that you have new code space. I can actually set up an IDE inside of my GitHub, repo in a browser.
And what it does is it actually close this to a container. And if I go into the container, it’s got all the code that I had in the other one, including this Yammel file. I can add this here. And I can save it. It’s asking me if I want to do some stuff. I’ll explain what that is in a second. And I can save it control less.
It’s [00:07:00] saved now over here in source control is telling me that we’re out of sync. So this local clone, when you’re working with code spaces, it creates a local clone inside of something called a runner on GitHub and. Container is not directly accessing the code. I could just directly access it the code, but I don’t want to do that.
So what I say is update a feature. I here check that box is going to ask me if you want to stage those commits. And I sync them. Okay. Now what that’s going to do. Let’s get rid of that little message. So what that’s going to do is it’s going to sync with my GitHub repo, which is over here, and you can see that the last change was in update
April: a couple of seconds ago.
It’s kicking off your
Brian: workflow again. Yeah. It’s kicking off and work again. And that [00:08:00] workflow. Is now going to work? Yeah, just give it a couple seconds here. And that should work. Everything. We
April: just went through Brian, cause I think there’s a lot of fantastic information there for everyone following along.
So we deployed a new app service, which is great deployed quickly, but it had no. So we went into our repo where our code sits, but we enable a continuous deployment within the Azure portal, which is an awesome feature that we’re seeing on a lot of of the different resources in Azure now, because before you’d spend something up and then have to help us in separately, and that made DevOps processes really hard.
So we’ve gotten that set up. We’ve gotten our pipeline excuse me, our workflow go. We’ve added that connection string. And because we update in code spaces, we have secure environment was quick to do, we’d have to clone our code and set up our workstation environment, push our code up and it looks like our deployed is going to be successful.
Brian: Yeah, the the building said the build is green check mark, which means a built [00:09:00] it’s going to deploy now, which is fine too, but it’s still not going to work. And in the next episode, I’ll show you what you have to do to update the app service, to deploy. So there you go. It’s built is deployed. Not when I actually click on the deployed Azure web app, it’s going to fail.
It’s going to give me an error message and I’ll show you afterwards. What happens when that actually what we need to do to update that.
April: Cool. Well, thank you everyone for watching today. Thank you, Brian, for showing us this, to see what happens to how we fix our application tune in next time for the next episode in the series for DevOps, for Java.
Learn about DevOps and subscribe:
Follow us on Twitter: