>> In this third episode of
our four-part series on Python and Django on Azure.
Carlton Gibson is here to show us how to use
Azure Pipelines to enable continuous integration and
continuous delivery of Python Web Apps to
Azure App Service or anywhere else today on Azure Friday.
[MUSIC]
>> Hey friends and Pythonisters,
welcome to another episode of Azure Fridays,
I'm Nina Zakharenko, a Senior
Club Developer Advocate at Microsoft.
With me is, Carlton Gibson.
He is a Django fellow as well as a Maintainer on
Django and a lot of other packages
and frameworks that you probably use.
Last time we talked about deploying
Python Web Apps to Azure App Service,
today we're going to talk about automating
deploys with Azure DevOps Pipelines.
>> Okay, awesome. Thank you, Nina.
So, the REST Framework
tutorial app that we've been using through the series,
we've deployed it to Azure but now we want to do
that every time that we make a commit or commit to master perhaps.
So, we've integrated it with Azure Pipeline,
see the build succeeded there
and I'm going to show you how that works.
The first thing you've got to do is- it makes it easier is install
the Azure Pipelines GitHub app
and you can get that from the marketplace,
you just search for it and it'll show up.
I've already installed it. So, it talks about setting up a plan,
edit plan, it would be a big "Install" button for you.
Install that give it you information
and then it can access your repos.
You see here, it says you can build
Linux or Mac OS build windows as one of
the really cool features of pipelines is that
you can build in across the different environments.
Anyway, let's head over to
the DevOps console and here's
the pipelines that I got set up for
the REST framework tutorial, there are two here.
One is CI and what that
does is that it runs the test suite. So, we-
>> What does CI stand for?
>> Continuous Integration.
The idea is that when you make a change,
it runs your test suite and if you've broken something,
one of your test will fail and you'll notice there and then,
and the idea being that the bug is quicker to fix there and then.
So, this is just a Yammer file that-
you have to have the Yammer file in your repo,
and this is a template that you can get from the repo,
and you can copy it, it's perfectly
generic, you can use it in yours.
If you're selecting a Python, I should probably
update that Python version,
and then it just looks for the manage.py file,
then it creates- the pip installs your requirements.
Pip installs this for a unit- for reporting the unit test and
then it just runs manage.py test which runs the test suite, okay.
So, it's a really generic Yammer file.
And this this pipeline uses that.
If I click on edit here we can come in and we can
say that's where it picks it up.
>> Great.
>> So, it's looking for that thing.
Anyway, let's go back over here.
And you can see the- it runs a test.
So let's- we adjusted group serializer,
we had an error in that.
So, it does all these phases in a test,
runs the tests, we can get the click-in,
we can see the results.
Okay, brilliant it run one test.
That was a test we set up for the bug we saw in the first episode.
>> Great.
>> Let's close that. So, that's the CI
built and that's all- that's great.
But what we want to do then is
deployed and here's where the magic bit is.
So, we've run the tests but now we want to deploy,
and here we've got a second deploy, a app service deploy.
So let's me show you the Yammer for that one.
And that one's again very simple and
the key bit is just down
the bottom here where it's got this script.
It says git push and there's this complicated URL,
our current head to master.
Okay, and that's doing exactly what we
did with the Git Deploy to App Service in the previous video.
Instead of us doing it directly from VS Code,
pipelines is going to do it from the build server.
>> So, we did it in VS Code,
all of these variables were populated for us.
>> Right.
>> But outside of that environment
we have to take care of them ourselves.
>> Yeah. So, here's the variables we need.
We need a deployment URL,
a deployment username and a deployment password.
And if you go to the environment example file that's in the repo,
I've shown you all about those.
And you must create these for the deployment to work.
If you don't create these variables,
the deployment fails. You can't get pushed.
So, there's a AZ command to create the username and the password,
and there is also another AZ command to get the deployment URL for
your repo and fill those in and then what we need to do,
is tell them if you wanted to do that locally,
you'd load them into your environment-
>> Right.
>> And run that get command.
But we need to set them in the pipeline.
So, what we've done here is we've created
three secret variables and these are kept secretly.
If you if you un-click this folder they disappear,
you can't get them back ever again.
So, there's totally secret,
there's a deployment password,
there's deployment username, and there's the deployment URL.
>> That's very secure.
>> Well, it's great and then the task loads
on in into environment and then the get
push command just uses those.
So, it's the simplest simple convey,
the only other thing that we need to look at to
see this working is the triggers.
So, normally the pipelines
are run every time there's
a commit or every time there's a pull request.
We've disabled that, we've
disabled the continuous integration
and we've disabled the pull request checking.
Then we've created a dependency on the CI pipeline,
and what we've done is we've said when that CI by
pipeline passes if it's on the master branch then deploy.
>> Great.
>> That's it. That's how you deploy,
you setup continuous deployments with DevOps as your pipelines.
>> That's lovely.
>> What else? Django-filter. We have this on Django-filter.
So, we have that setup here.
>> What is Django-filter?
>> Django-filter is a add-on for Django, it's a Django app.
>> And you're the maintainer?
>> Yeah, I'm the maintainer of that,
and what it does is it enables you
to get rid of a lot of bootstrap,
when you want to take your query string parameters
and use that for filtering.
So, you'd need to create a form,
you'd need to whatever.
You'd need to do all things,
it does it all for you just declaratively, check that out.
So, but the cool thing about this is it doesn't just run
the tests for one version of Django or one version of Python,
it runs the test for all the versions of
Python that are supported on
all the versions of Django that are supported.
So, it's running probably
12 versions each time there's
a pull request or a commit to master.
>> That's great.
>> That's cool. It's super and it's free for open source.
>> Well, fun fact, even C Python uses Azure Pipelines.
In this episode we learned how to automate with pipelines,
check the show notes for a link to
the repository it contains all the setup instructions.
>> Yeah.
>> Along with the Yammer files.
>> Yeah.
>> On the next video we're going to talk about developing
serverless applications with Azure functions.
[MUSIC]