(music)
>> My name is Anthony.
I usually spend time working on Python code on stream,
usually open source stuff.
Although recently I've been building little startup,
continuous integration application called pre-commit ci.
The idea behind pre-commit ci
is it will run your linters and code formatters
and auto fix your pull requests for you.
And today, we're doing a little bit of a special stream
where I'm gonna be learning about Azure,
so I'm going to show you getting started
with Azure from scratch.
So we're gonna be installing all the tooling
and trying to set up a basic application
that just runs in Azure,
hopefully using the serverless functionality.
So I don't have to manage any servers,
but we'll see what happens there.
Once that works,
'cause I assume that will work really quickly,
we will try and get pre-commit ci running in Azure as well.
We'll see what happens.
I'm not a hundred percent certain
what's going to happen there.
That's what we got for the stream.
Hopefully it goes, well, I'm excited for this.
I haven't worked with anything but AWS in quite a long time.
So this should be pretty exciting.
Okay, I did a little bit of prep work before this,
but mostly I wanted to start from scratch on this computer.
So I did a little bit of prep work on my other computer,
but the plan for today is to work
with the Azure Terraform modules to do that from scratch.
So I've already installed Terraform, Terraform.
Terraform is a configuration management software
that previsions cloud resources,
and we're gonna be using it to provision Azure resources.
I don't have the Azure client installed yet.
So we're gonna go over installing that.
So I think I'm probably just gonna install it via PyPI,
which is not recommended,
but fortunately I have a way to do that automatically.
So let's just figure out how I installed Adls Client,
and do the same thing for Azure Client.
I don't know what its dependencies are.
So I'm going to, I mean, isolate it
in a separate virtual live.
Which is just a little bit of copy pasta here.
ITOs CLI we're going to do easy CLI,
comments is wrong,
Azure CLI,
package
Azure CLI.
Hopefully that will work.
Two small puppet.
So this is essentially setting up a virtual environment,
and doing PIP install, Azure CLI.
Just a little bit weird there.
Drink time might says...
Ooh, I see a zip-up here.
I just learned about zip up a few days ago.
It's pretty...
Yeah, you're talking about here.
Yeah, I'm actually working on adding Zip up
support to pre-commit.
Which would allow you to just download a zip,
and not have to use any installer for that.
So I'm using puppet to manage the staffer on my machine.
This is basically some automated configuration management.
I have a YouTube video about this.
If you go to my YouTube channel,
which is Anthonywritescode or linked in the Twitch chat.
Let's see what happens here.
Made the virtualenv.
I think it's doing the installation right now,
which I'm a little concerned how slow it is.
Anyway, it installed after awhile,
and we got the Azure CLI.
That's cool.
And if I recall correctly,
the first thing we need to do is,
easy login and that should get us started there.
Which is going to make me log in next,
paste that in there.
Okay, hopefully none of these are secrets,
otherwise yikes.
Okay, we're logged into Azure.
That's this part.
So I wanted to just make a very basic
flask application just to get something working.
And then we're going to try
and upload that to Azure functions,
and try and serve it out of,
whatever the Azure equivalent of, gateway is.
So get in it's Azure sample, location.
Initial empty commit.
That's just copy a pre pre-commit config
from some other projects that I have
and get that to the latest versions.
But pre-commit is the tool that I'm working on today.
But I'm gonna make a very simple app
and we're going to do import flask,
app equals flasks dot flask,
made a million flask apps so
this is basically just similarly play here.
Methods equals get.
(keyboard clattering)
I'll make a little entry for this
that we'll run it in the debug mode.
App dot run.
Porch equals 8,001, sure.
And we're going to set up a virtualenv for this.
Oops (inaudible)
Interesting that this print system exit too.
That seems like a bug.
Install, well, let's make a requirements.
Minimal dot tct, 60.
And then I'm gonna install flask,
and then I'm gonna freeze these requirements,
into requirements dot txt.
I'm making sure to pin all of the requirements.
These are all the dependencies that we're using so far.
And we should be able to run our app.
And if I open this in the browser.
Okay, we've got "hello world" working locally.
It's not on Azure yet, we'll get there soon.
Let's see webapp flask.
We'll see if there's a tutorial on this,
scroll through this and see what we need.
I wonder if I have that in the
virtual one that I made
and I just didn't similarly get.
Wow, it installed fabric, interesting.
Also we have batch files,
even though we're not on windows.
So we don't have the funk command.
But hopefully we don't need that.
Oh, cause we've got to NPM install something.
Hm Hm.
We could try this.
I'm not going to use dash G.
Came on this guy.
Hey, we got the average logo.
Okay, cool.
All right, create the Python function.
This is using the funk stuff.
It's like, there's a pip package for this.
Let's install those,
Pip freeze requirements dot txt.
Okay, so we've installed Azure functions.
My guess is this is kind of the bridge code
between a normal whiskey application and Azure.
Step to create some code.
Okay, we've already created the code.
We're not going to use the funk way.
Kind of cool they're actually using
type annotations as well,
which I find kind of cool.
But they're using the func types here.
I think we can get away without using that.
Here we go.
This, read me was much more useful.
Perfect.
Okay, that's what we want.
So they suggest doing import Azure dot functions as func.
I kind of don't like that.
I know it's like super popular data science
to do like as NP or whatever,
but I think it's much more readable
just to Azure dot functions.
That way, it's super clear that this works that way.
Oh, the Azure main, and maybe we'll rename it later.
Yeah, remote and origin.
Close all these out, and that should pass pre-commit now.
Yay!
We don't have any tests.
Oh, we also don't have a setup dot CFG.
And I'm not gonna write a test for this thing, so.
Well, and then we should have just all green stuff.
Mikayla says, now it's going to look like C-sharp.
Man I wish I could write more C-sharp, I love C-sharp.
It's so good.
Initial commit with pre-commit and dependancies.
Hopefully we'll see what else we need to do there.
The next step we're going to be creating a function.
Function, entry point dot py.
We'll do it like this in a separate file.
Import Azure dot functions.
So this, cannot be named main,
because this is also named main.
Git add app dot py,
turns out the Azure function has to be named main.
Though we will need to add that function dot json
or functions dot json or whatever it was called.
So lets copy this,
function dot json.
Function entry point dot py, bindings.
Yeah, sure that seems fine.
Importing logging is optional, but recommended.
And like you say, C-sharp reminds me of Java
and that reminds me of nightmares.
But the thing is, and I've said this a lot.
C-sharp is Java that doesn't suck.
Yeah, this is basically an entry point for my application.
It will import this code
and look for this special main function,
and call it using whatever Azure primitives.
In fact, we have the Lambda example on the left.
So the Lambda example is a little bit more complicated
and we're actually gonna need to do
this same sort of thing for Azure
or they way PCI picks its back in the rotation
is based on this environment variable.
We'll need to do a little bit of shuffling, there.
And so these, they should almost look the same
when we're done with it, which would be pretty cool.
Let's do.
Required main, takes these things, cool.
Foo raised to the two.
Yeah no, it doesn't...
It doesn't work.
Oh, that's actually a weird error message.
Unsporting operator type four...
Oh, I see.
They're both implemented the same.
Okay, you can debug your Azure function
locally and visual studio, cut.
That's kind of cool.
I guess we could create a function and see what it does.
I think I have the S code installed.
Lunch BS code quick open.
Control P, sign into Azure
should be a little dropdown thinking here.
Hey, there we go.
Signed into Azure.
Yes.
Okay, so this should, let me look at the code.
That's all I wanted to do.
Launch dot json.
(keyboard clattering)
I picked a really poor colors here.
Let's see what this file does.
W CG W.
Oh, look at that.
Seven 0 seven one.
No job functions found.
Try making your job classes and methods public.
Yeah, wow it just winked at me!
What?
Let's try the verbose.
Wait, why does it think I'm running Python three six?
I guess we could run it in visual studio
and see what happens.
Oh, this takes a while.
What is it doing?
Let's see if we can restart code with
path equals PWD slash
node module slash
bin path code dot.
Are you going to think that you have it installed now?
"Could not I find the task funk host start."
All right, what does it want me to install for this?
Okay, whatever this isn't working.
That's fine, we don't need that.
We can already simulate it locally
by doing our flask entry point instead.
And I'm just going to assume that the Microsoft stuff works
so we can already do Python dash M app.
And we already know that that works cause,
we verified it before.
Okay, let's go back to step four.
Skipping the debug,
because it didn't work for whatever reason.
This actually looks different than what I had.
So maybe, diddly has dot json already.
What is this function called?
Maybe it's suppose to be in a directory.
(keyboard clattering)
Change my function.
Oh!
That's an improvement, but it failed.
Also it failed to import due to,
to the way that it's running this.
Let's see.
Let's see if that works.
Check, play by flask now.
No module named my function.
Usually touching in, in the py
is not gonna change anything.
But, let's look at their troubleshooting guide.
Use your favorite tech center to open the wheel file.
It's a zip.
Oh, they have the wrong terminology here.
This is not a wheel.
Let's just stick it all in one file and see what happens.
Yeah, It's my function app dot py.
So we'll just get rid of the flask main.
We're gonna run into some trouble.
We do this with frequency out yet.
But, let's try it, let's see if we can get there,
anything working first.
Okay, this is what I expect them.
Failure to import flask.
So it is for some reason picking python 3.6.
I don't understand why.
Maybe, if I activate this virtualenv,
it will forget about Python three, six.
I had installed Python 3.6.
Yeah, I could do that.
Okay, Python 3.6 is gone,
it's gonna pick three seven now.
Oh my God, it did.
Why?
Well we kinda,
get rid of three seven as well.
A bit of a weird choice there,
despite that Python three linked to three six.
No, they all go three, eight.
There's no reason for it to pick these older versions.
My guess is what it's doing,
is it's like incrementing the version
and finding the first one that matches.
So let's try this again.
Hopefully it should now work with three eight.
So, I mean works.
It's crashing due to, it checking type annotations,
for some reason.
And whatever type annotations they have
in their Python library are just wrong.
Oh, which means we could fix that for them.
Command line func host start
Python functions MyFunction.
Okay, now it works,
even though Python three six is installed.
Guess I understand what it's doing now.
That character be perched a minute ago.
Yeah, but now they're now they're installed again.
Okay, so let's search for this,
'cause this seems to be a problem.
Well, and that should clean up their unused no QA's.
Hey, look at that!
So one of these is not in there double under all.
These are just for their side effects.
We'll leave those there.
Zelig data structures.
We're going to ignore that one.
Using chat for the error log.
It's true, it's true.
Okay, so this is working,
but the code is not working,
and I got to do a little bit of debugs here.
Okay, so we should have a function in here.
It says that it's running.
What, how is it possibly running?
Oh, this is for, okay.
Now we're going to create a function.
The Azure dashboard looks kind of like outlook.
It does kind of look like outlook.
Okay, all right.
Let's read this again.
A storage account,
we don't have a storage container though.
Storage container.
Function app deployments.
Those tools terrify me.
I mean, they can't be a little scary
'cause with one command,
you can just delete everything.
Functions, work or runtime equals node or Python.
Okay, let's do that. Let's get rid of this thing for now.
I don't know if this is needed.
Oh, I'm gonna cover this up as well.
This is a bit more complicated than it is on AWS.
Let's just try and build one and upload manually.
Az function...
Az function app.
Create, delete, list.
Kind function app.
This is a lot.
Each function app deployments.
Manage function app functions.
Function.
This is helpful, thank you for that person.
Oh, OS type Linux.
(keyboard clattering)
Let's see if that changes things.
Oh, is it replacing it?
Oh, forces replacement.
That's why, destruction complete after three seconds.
Okay, so in theory, we have changed this to Linux now.
Let's refresh.
Nope, still says windows.
So let's actually just do the same,
build output as they have.
Which means we're gonna set up these other
weird connections, string things.
And then I'm going to manually build a bundle
and upload it, and see what happens with that.
And all of that.
Let's see what this does.
This changed anything?
Oh, I must have failed to recreate last time.
So that's why it says windows.
Yeah, it's not applying my changes.
So we're gonna destroy and then create.
Uh, also love that, it just puts the password here.
Yes.
Let's build this thing.
Watch an error 'cause the old one still exists.
Okay, no longer says operating system here.
No, why windows again?
It's for some reason using windows.
I guess we're going to do this visual studio.
You ready for me to use vs code again?
Now I'm about to try and debug,
a Terraform module.
VS Code, yeah.
Well VS, visual studio prepper, doesn't run on Linux.
It's doing something there.
Create function app in Azure,
enter a global unique name.
Asottliedemo2.
Okay, what does this do now?
Hey, your functions 3.0 app is up and running.
This is a weird 404.
Oh, maybe you gave a blank response.
Okay, so I think what I need to do is,
functions
function MyFunctions.
Okay, cool.
The plushies are just out of, just out of frame.
There we go.
Now, we've got all the plushies in frame.
How do I, how do.
This is what I get for only following half a tutorial.
Create function.
We already did that right?
These windows are really difficult to click on.
Execute function now.
Oh, that's kind of cool, deploy to function app.
That's the button that I want.
"Are you sure you want to deploy?
"this will override any previous deployment."
Deploy.
Okay, it's doing something.
It's doing something.
What is possibly in this giant package?
We're just gonna let it go.
Or we can get rid of the terraform.
Cause we know it didn't work.
I actually, we can probably just do Ella and dashes.
All right, we're gonna re-deploy this thing.
Anyway, it did upload.
So in theory, we should be able to look at it now.
Theory, this should say "Hello hello world."
Hey!
Hello, hello world from my function.
Oh my goodness.
It's sipping get.
Oh, maybe, I think I'm kind of exhausted.
I didn't quite figure out how to change the URL
to something that's not just my function name here.
Oh, wait, this looks like a thing here.
Let's see, across parameter name, is that.
Do you think if I just do route slash it'll work.
Route route, see if we redeploy this now.
That will change that there,
we'll find out, completed.
Ooh.
Oh, it works!
It works!
Okay, so you can change the route using the route thing.
Azure sample application.
This is a small sample application using flask
and deployed in Azure functions.
Findings zero dot route.
That's enough of like kind of an explanation
for what this is.
And I'm gonna push that up,
and I will link that in the chat.
So you guys can check that out.
Azure sample application.
And hopefully at some point,
I'll get this deployed with Terraform instead.
This, worked well, four hours of streaming,
and we got, got goal one done.
Goal two is...
was a little bit ambitious to get done in one stream.
So anyway, my name is Anthony.
I upload previous content to YouTube.
That's youtube.com/anthonywritescode.
Thank you all for watching,
and let's go find someone to raid.