Latest / Talk Python To Me / #166: Continuous delivery with Python
Transcript
- 0:00We've evolved from, if it builds, ship it, to continuous integration, where every check-in
- 0:06is automatically verified by something like Travis CI.
- 0:09Taking that further, some people today are using continuous delivery.
- 0:14This means once a check-in is validated by the CI system, it's deployed automatically.
- 0:19There are many moving parts in these processes.
- 0:22On this episode, you'll meet Chris Medina, who has put together a world-class CI CD system.
- 0:27And he's here to share how he did it and what tools and libraries are involved.
- 0:31This is Talk Python To Me, episode 166, recorded June 11th, 2018.
- 0:36Welcome to Talk Python To Me, a weekly podcast on Python, the language, the libraries, the
- 0:55ecosystem, and the personalities.
- 0:57This is your host, Michael Kennedy.
- 0:59Follow me on Twitter, where I'm @mkennedy.
- 1:01Keep up with the show and listen to past episodes at talkpython.fm.
- 1:05And follow the show on Twitter via at Talk Python.
- 1:07This episode is sponsored by Linode and Rollbar.
- 1:11Please check out what they're offering during their segments.
- 1:13It really helps support the show.
- 1:15Chris, welcome to Talk Python.
- 1:17Hi.
- 1:17How's it going?
- 1:18Glad to be here.
- 1:19It's going great.
- 1:20Yeah, I'm happy to have you here.
- 1:21It feels like we were just hanging out in Cleveland just a little while ago, right?
- 1:27Just a little bit ago.
- 1:28Yeah, everybody's scattered back to where they came from.
- 1:31And it's sad that PyCon is over.
- 1:33But that was really fun to spend some time together there.
- 1:35Yeah, for sure.
- 1:36It was great to meet the PyBytes guys, too.
- 1:38I hadn't met them before.
- 1:39So that was pretty cool.
- 1:39Yeah, they traveled quite far to get there.
- 1:42From both sides of the globe.
- 1:43So, yeah, I mean, PyCon is such a special place.
- 1:46And PyCon US seems to be where the most gravity is.
- 1:49I know EuroPython is also large.
- 1:52But I feel like that PyCon US is probably the biggest.
- 1:55Just get the sense that I get.
- 1:56Anyway, I think just, you know, recommend that people next year, if they didn't get a chance
- 2:02to go, definitely go.
- 2:03Like, wouldn't you say?
- 2:04Did you have a good time?
- 2:04Yeah, definitely.
- 2:05So, like, I started doing PyCon maybe three years ago now.
- 2:09And it's definitely been a lot more interesting to so much stuff from so many different people
- 2:15doing so many different things with the language.
- 2:17Because Python has such a wide usage.
- 2:21It's just great to just be out there and just see what everybody's doing at.
- 2:24And I like just hanging out in the expo hall and just kind of just talking to everybody.
- 2:29So you're like, oh, what do you do with Python?
- 2:31And definitely the open sessions, people don't quite, you know, understand how cool that is
- 2:38versus, you know, your average conference where everything is just kind of like pre-configured
- 2:42for you.
- 2:43Yeah, definitely.
- 2:43Both you and I ran some open sessions, right?
- 2:46That's true.
- 2:46Yep.
- 2:47Yeah.
- 2:47What were yours on?
- 2:48I did two.
- 2:48I did one on just blogging and stuff, folks that are creators for Python.
- 2:53And I did one on virtual reality, augmented reality, and to see how, you know, experiences
- 3:00with people and Python and that type of stuff with those environments.
- 3:03Yeah, that's pretty awesome.
- 3:05So now that you're back to doing what you do day to day, maybe we could get your story
- 3:09and your background.
- 3:09Like, tell us how you got into programming in Python and what you do day to day.
- 3:12My story is more like a classic story.
- 3:14Dad grew up doing software.
- 3:16He had a consulting business.
- 3:18There's stories of two-year-old Chris sitting in his lap typing in the keyboard somehow.
- 3:23Not that any of that was intelligible, obviously.
- 3:25But yeah, so he started stuff with old IBM systems.
- 3:30Like, you know, monochrome monitor, eight and a half inch floppy integrated keyboard,
- 3:33no hard drive things.
- 3:34No hard drive.
- 3:35That still blows my mind that computers came with no hard drives.
- 3:37Yeah.
- 3:38So I remember the first time I actually got an idea of what, like, software was.
- 3:43It's because my dad wrote something for me to sit in front of his computer and learn the
- 3:50times tables.
- 3:52And it was just a short little program, but I could go into the program and fiddle with it.
- 3:57So I was really young for that.
- 3:59And I still remember it.
- 4:00It was pretty cool.
- 4:01It was an IBM system 23.
- 4:02Nice.
- 4:03Would it, like, randomly pick, like, two numbers, multiple, you know, and ask you what the answer
- 4:08was and say you got it right or wrong, basically?
- 4:10Pretty much.
- 4:10That's pretty nice.
- 4:11Like interactive flashcards, basically.
- 4:13I remember doing a data entry forum back in the days where you can't slurp anything in
- 4:17from any APIs or anything like that, right?
- 4:19Somebody would just hand deliver an invoice and you had to type it into the computer.
- 4:23When computers were not actually connected to anything, they were just there on a desk.
- 4:28How weird, right?
- 4:28Right.
- 4:29Exactly.
- 4:29So some of the first stuff I did was system 360 basic.
- 4:34My hello world was like a menu for, like, opening an invoicing app or something like that.
- 4:40Back when you had to type line numbers and make sure you left enough room between them in
- 4:45case you needed to add more lines before.
- 4:47Yeah, that's right.
- 4:48Like, if people don't know this, that used to be a big deal.
- 4:51So it used to say, you know, 10 would be like a line number and you would put a command and
- 4:56then 20, you'd put like another.
- 4:57And the reason it didn't go one, two, three is you might have to do 11, 12, and 13 someday
- 5:02and you don't have to rewrite the whole program.
- 5:04It's so insane that you had to explicitly call out the line numbers.
- 5:08But I guess with like the go to navigate, like a sort of branching mechanism, you had to say
- 5:14go to this line.
- 5:14So it had to be really clear what line that was.
- 5:17Yep.
- 5:17And then we added go sub.
- 5:19Oh, man.
- 5:19I was advanced concepts right there.
- 5:21Huh?
- 5:23That was amazing.
- 5:25All right.
- 5:26So you started there.
- 5:27Like, did you go and get a computer science degree?
- 5:29So I did computer engineering.
- 5:31I actually was like, well, I kind of halfway understand at least some of the software stuff.
- 5:36So let me see what all the software is built on.
- 5:38And I went off and figured out how to do hardware.
- 5:41So I did computer hardware, computer architecture, that type of stuff.
- 5:46And, you know, from there I went into IBM, which was the first guys that hired me.
- 5:51So I spent many, many years with IBM doing systems tests.
- 5:54Were you doing hardware stuff for IBM?
- 5:56I was on the side of we developed a new server.
- 5:59It would come into our organization and we ran validation on it.
- 6:04So before I made it out to the customer, we would go and check a bunch of things.
- 6:08Like it was gigantic organization, tens of thousands of tests that would execute.
- 6:11So we had like a small piece of that that had like integration with more on the integration
- 6:16level of the server with the firmware and the hardware.
- 6:20So I'd have to do hardware tools that I'd have to code and say like some sort of what is today
- 6:26embedded systems, right?
- 6:28All the way up to like high level software tools to, you know, maybe interface with that stuff
- 6:33or even business apps too, which was the biggest thing I wound up doing,
- 6:37which was kind of a management system for keeping track of all our test organizations and stuff,
- 6:42including status reporting, test execution, procedures, all that type of stuff.
- 6:47That sounds pretty interesting.
- 6:48I don't know a whole lot about the hardware side of computers.
- 6:52I mean, obviously I have some concepts, but like I couldn't, you know, design RAM or anything like that.
- 6:59Right.
- 7:00It's just, that's always, that's sort of like where, you know, the Darby Dragons sort of aspect
- 7:04of programming is for me.
- 7:05Like I have a conceptual idea of it and I don't know how close that is to reality.
- 7:09So it's, it's pretty cool that you kind of get a bridge to that world.
- 7:12Yeah.
- 7:13So some of the most interesting, so why some of this stuff is important too,
- 7:16is because you get to understand a little more, some of the more recent security things called
- 7:21Rowhammer, if you've heard about that.
- 7:22Oh yeah.
- 7:23Tell people what Rowhammer is.
- 7:24So Rowhammer is a way of essentially kind of hacking your machine to run code by accessing
- 7:33certain parts of memory at certain speeds such that you would make an adjacent memory cell
- 7:39have the data that you wanted or the code that you wanted to execute.
- 7:44And then maybe that adjacent memory cell is the one that's in like the privileged memory.
- 7:49I see.
- 7:49That's so tricky.
- 7:51Does it use like a cache hits and misses and stuff like that?
- 7:55Are there the prefetch stuff or where, where does that come from?
- 7:57So this is actually winds up in your actual, so it's a, it's a general problem with DDR3 in
- 8:03general.
- 8:04So anything that has a DRAM from DDR3, you could do that in as long as the refresh rates, you
- 8:12know, memory, your processor kind of controls how often memory is refreshed.
- 8:16So it would go in and blank out, you know, whatever charge is accumulated.
- 8:20So if your refresh rates are, if you wait a long time between refreshing, you have a larger
- 8:26window in which you can get in and make those changes.
- 8:28So, so it'll actually happen on your DIMMs.
- 8:30Oh, wow.
- 8:31These are crazy ideas.
- 8:32Like we're seeing a couple of these, right?
- 8:35So there's a row hammer, there's spectra, there's meltdown.
- 8:39I mean, these are like not even software problems, right?
- 8:42These are down in the chips.
- 8:44Yeah.
- 8:44So then the other, the other ones you mentioned are down at the processor level.
- 8:48And a lot of things, a lot of those are because optimizations to trying and execute instructions
- 8:55faster.
- 8:56And the way, the way that processor pipelines work, you want to prefetch some information.
- 9:01So I know some, I know one of them, I don't remember which one, which one was what, but I
- 9:06know one of them was more related to branch prediction.
- 9:09So if you, if you're going through code and you have an if then else kind of thing, it'll
- 9:14prefetch both sides of your if, whether it meets the condition or it doesn't.
- 9:18And then you can play with that a little bit and have it prefetch some memory information
- 9:25that, or data that, you know, it shouldn't have because it's at such a low level, stuff
- 9:31like that.
- 9:31Yeah.
- 9:32It's crazy.
- 9:32Yeah.
- 9:32It's going to be interesting.
- 9:33I think we'll probably see more of those types of things, but it, you know, it really gets
- 9:38scary when you mix that with cloud computing and we're going to talk about cloud computing
- 9:41a lot, actually.
- 9:42So maybe start with, yeah, maybe start with what you do day to day, let people know what
- 9:46you're working on.
- 9:47So I'm part of a small group of folks that worked for a company called Nimble Storage that was
- 9:52acquired by Hewlett Packard Enterprises last year.
- 9:55And Nimble makes storage arrays.
- 9:58So as in external enclosures where you have a bunch of hard drives that you access through
- 10:05iSCSI or Fiber Channel.
- 10:06And these are for like data centers, right?
- 10:07These are not like NAS for your home, are they?
- 10:10Right.
- 10:11These are built for data centers.
- 10:12So these are expensive things that have a performance, you know, way higher performance that you get
- 10:18something out of a consumer product.
- 10:19And so they have a bunch of systems management and stuff around that as well.
- 10:22And a bunch of guarantees in terms of data savings due to deduplication or compression and
- 10:31things like that.
- 10:32Enterprise class features, snapshotting and things of that nature.
- 10:36Okay.
- 10:36So nice.
- 10:38So if you run like a hundred VMs, like most of the OS is probably the same across all of
- 10:43them.
- 10:43You just need that one copy of those files.
- 10:45Right.
- 10:46So we do instant snapshots.
- 10:47So if you, if you have a virtual machine, so one of the use cases is say you have like
- 10:51a database in a virtual machine with like, say your database in it, and that's all contained
- 10:55in a couple volumes of which you can group together.
- 10:58You can go in and say snapshot that and it happens like instantly and then spit off a
- 11:05new VM based off of that, those volumes you just made over there.
- 11:08And now you have a copy of your data essentially.
- 11:10And it keeps track of the diffs.
- 11:12So it's kind of like a, if you, if you bring it back to the software world, it feels a little
- 11:17bit like you were playing with Git really.
- 11:20And, or Docker where you have like a special commits, which have your data.
- 11:26And then you have the diffs of your data into the next set of commits kind of thing.
- 11:30So when you do your snapshots and your clones, instead of having a, an entire duplicate of
- 11:35all of the data, you only have the difference that you write afterwards.
- 11:38So that's also pretty helpful.
- 11:40So those are the arrays that we make.
- 11:42And so one of the things that we're kind of experimenting with cloud stuff, we decided
- 11:46to go off and built what is cloud volumes.
- 11:49So the product is called HPE Cloud Volumes.
- 11:52We can, and the purpose is if you have a, an Azure or an AWS virtual machine and you want
- 11:59to tie it to some of our storage arrays, you can go to the website and request volume of
- 12:07certain size and other characteristics along with it and configure it so you can plug it into
- 12:15your, your VM.
- 12:16That's pretty interesting.
- 12:17So tell me why would I like pick that say, instead of just like creating a volume in AWS
- 12:23or Azure in their mechanism, right?
- 12:26Right.
- 12:26So one of the main things is that you can go cross cloud.
- 12:29So you could have your volume that you made with say your Mongo data or something.
- 12:34And, you know, it's attached to your AWS, but you know, if you're running a super critical
- 12:39application and say your AWS region goes down, you can just clone that volume and attach it
- 12:45to Azure and you can use it on Azure side of the world.
- 12:49The other thing you get out of it is we can do a higher IOPS when talking, when, when doing
- 12:56the IOPS is a measure of how many storage operations, IO operations you do on your drives over the
- 13:01array.
- 13:02Then you can get out of a regular EBS.
- 13:04And as far as I understand the instance snapshots as well, I forget if EBS does instance snapshots
- 13:11or not.
- 13:12I don't think they do.
- 13:13So you also get that ability.
- 13:14There's also extra stuff that we provide for our actual physical enclosure customers.
- 13:21So if you own one of our physical arrays, you can actually replicate your data up into the
- 13:27cloud through our service.
- 13:28And you don't have to worry about the ingress costs through AWS or Azure.
- 13:32So we provide a way of seeding information out to say different regions and things like that
- 13:37as well.
- 13:37Oh, that's pretty interesting.
- 13:38Cause yeah, that can get pricey real quick.
- 13:39Yes, it can.
- 13:40Yep.
- 13:40Yes, definitely.
- 13:41I know a little bit about bandwidth charges and whatnot.
- 13:45I think last month I paid $600 in AWS bandwidth.
- 13:48Oh, geez, man.
- 13:49You're getting lots of downloads.
- 13:50Woo.
- 13:50No, these are good problems to have, but that's a lot of bandwidth.
- 13:52This portion of Talk Python To Me is brought to you by Linode.
- 13:58Are you looking for bulletproof hosting that's fast, simple, and incredibly affordable?
- 14:02Look past that bookstore and check out Linode at talkpython.fm/Linode.
- 14:07That's L-I-N-O-D-E.
- 14:09Plans start at just $5 a month for a dedicated server with a gig of RAM.
- 14:13They have 10 data centers across the globe.
- 14:18They're going to run a lot of data center near you.
- 14:18Whether you want to run your Python web app, host a private Git server, or file server,
- 14:23you'll get native SSDs on all the machines, a newly upgraded 200 gigabit network, 24-7 friendly
- 14:31support, even on holidays, and a seven-day money-back guarantee.
- 14:34Do you need a little help with your infrastructure?
- 14:36They even offer professional services to help you get started with architecture, migrations,
- 14:42and more.
- 14:42Get a dedicated server for free for the next four months.
- 14:45Just visit talkpython.fm/Linode.
- 14:48Another thing you do is you spend a little time writing some fairly popular articles on
- 14:55your blog.
- 14:56I know because Brian and I end up covering them often on Python Bytes.
- 15:00Yeah, no, I appreciate that too.
- 15:01So I don't know if it's like a chicken before the egg thing.
- 15:04It's like something comes up a little bit, but then you guys post it up, and then it gets
- 15:07a lot more reads.
- 15:08But yeah, so I have tryacceptpass.org, and we do the posts include a bunch of stuff, usually
- 15:17things I play with.
- 15:18Most of the articles that get the most views usually are how-tos.
- 15:23I try to do a lot on async.io stuff because I'm trying to do more async.io, and that is not
- 15:28an easy concept as it is today in Python.
- 15:30Yeah, the work that you're doing there is really nice because I feel like that's a lot of
- 15:34areas where there's really not very much coverage.
- 15:37I'm definitely planning on writing a course on async.io because I feel like either people
- 15:42are just, they know about it and they're confused, or like, ah, it's too hard, or they just don't
- 15:47even know, right?
- 15:47They're like, I'm switching to Go because Go has better async than Python, but you don't
- 15:52understand.
- 15:53It does too.
- 15:53You're just not using it.
- 15:54I understand it's not as integrated into the web frameworks as it should be, but still.
- 15:58Great.
- 15:58But even that's changing now, so it's getting pretty good.
- 16:02And so I just want to try to keep playing with that and post that up there.
- 16:06And I also do a couple of things just on general engineering and software and a little bit of
- 16:11testing since I spent so many years in tests.
- 16:13I got this series going on called Practicality Beats Purity, mostly about that part of Python
- 16:22and how to, one thing sounds great, but how good is it really when you implement it kind
- 16:28of thing.
- 16:28Right.
- 16:29Like one of the popular articles you had was microservices versus monoliths and all
- 16:34the interesting trade-offs you make there.
- 16:36So we'll definitely dig into those, but I kind of want to focus on the whole reason we started
- 16:41talking about having you on the show, which is the continuous delivery you're doing around
- 16:45your work you're doing in HPE, right?
- 16:47And so maybe let's just start with what is continuous delivery.
- 16:52Like I know there's continuous integration and that's like something watches my repository
- 16:57and does some sort of build verification on check-in.
- 17:00So what's continuous delivery?
- 17:02How's that typically work?
- 17:04So continuous delivery expands on top of the continuous integration concept and say that
- 17:08build I just built, I want to do everything that I need to do to that build to make it deployable
- 17:14to production and have it available to be deployed to production, if not already deployed in production
- 17:20automatically.
- 17:21And so the idea is to set up your, be able to deliver code into production as quickly
- 17:27as possible in a way that that's maintainable while still having a set of status checks around
- 17:33that, that you can, that makes your job easier.
- 17:36Right.
- 17:36Okay.
- 17:36So maybe the Holy grail is like, I've got a GitHub repository and it has different branches.
- 17:42So maybe a branch is called production and a branch is called staging.
- 17:46And if you commit into staging it, you know, after some delay of the builds and creation
- 17:53of the servers and whatnot, there is now a new staging server or services based on top
- 17:58of that where you did nothing but wait a little bit.
- 18:00And that's kind of how we have our stuff set up.
- 18:03We have two branches and every, everything that's on our production stuff.
- 18:06Production branch is things that have gone already out to production.
- 18:11So everything there is a known working build that we can deliver to a customer.
- 18:14And we have our, we actually use the master branch for all our staging stuff, which is things
- 18:19that are fully tested or all the, we've guaranteed, we can guarantee that all the basic functions
- 18:25are tested.
- 18:26And the whole thing is completely built into a deliverable that we can actually go and put
- 18:33out in staging.
- 18:34And so as we go through our, our pull request cycle flow, GitHub flow type thing, get flow,
- 18:41we can automatically put the build up in our staging environment.
- 18:46Right.
- 18:46Okay.
- 18:47So you guys use the get flow style of work.
- 18:49Now this is really common in open source.
- 18:51Like some random outside person wants to make a contribution to a project.
- 18:56They don't have right privileges.
- 18:58So they'll fork the repository, make the change, do a PR back, and then the people can review
- 19:02and accept it.
- 19:03But some organizations, sounds like you guys, do that even for yourself on your own projects
- 19:08as a way of sort of like formalizing it, right?
- 19:11Right.
- 19:11So we use GitHub enterprise internally, but things like GitLab also have a similar concept for
- 19:17this.
- 19:17It's just called differently.
- 19:18So we have brand, our master and production branches are protected branches.
- 19:23And the only way to get in there is to go through a pull request merge.
- 19:28So we don't necessarily require the developer to have a separate, like a forked.
- 19:33repo.
- 19:33They just have permissions to push their own branch into our main repo.
- 19:38So once they push their branch and they open a pull request, we have a whole set of automation
- 19:44systems in place which receive the webhooks for the pull request and kick off automated builds,
- 19:50our style checking, linting, and all of the testing that goes around that pull request.
- 19:57And so you can even in GitHub say, I require the following statuses because the pull request
- 20:04object in GitHub has the concept of statuses.
- 20:07As you run those webhooks, the code that kicks off from those webhooks, the status is reported
- 20:15straight back into that pull request.
- 20:17And in GitHub, you can say, well, if all of these have passed, only then is your pull
- 20:23request valid to be merged into whatever branch it is that you want to go.
- 20:26Yeah, that's a really awesome feature.
- 20:28And to me, it sounds like this is a really nice way to sort of pre-vet what would be standard
- 20:35code review, right?
- 20:36Like instead of going, well, you've done your work.
- 20:38Now let's review it and see if it's good.
- 20:40It's going to be like it's on the verge of being merged.
- 20:43And then you've already had all the tests done and everything is good.
- 20:46You push the button.
- 20:46And when that happens, it automatically deploys with no further work as well.
- 20:50So it's just like that one gate, right?
- 20:52Right.
- 20:52Once all our tests are done and once the review is approved, we click our button.
- 20:57We do some other niceties around it.
- 20:59We kind of squash every right, our merge commit a little bit so that it's useful.
- 21:04And we press the button.
- 21:06Right.
- 21:06Maybe talk about that a little bit because, you know, Git can like if I'm going to do, excuse
- 21:11me, I'll create a branch, I'll do like 20 commits, a bunch of little tiny ones.
- 21:16And then eventually I'm going to create a PR from that.
- 21:18You might want that to not look like 20 small operations, but one holistic one, right?
- 21:23Right.
- 21:24So we try to follow a system where we abstract more as we go down the production side.
- 21:28So we have as much detail as possible on the branch that the developer put their things
- 21:33together in.
- 21:33So all the commits on that branch are going to be the itty bitty things.
- 21:36Started to work on this feature, went to lunch, came back.
- 21:40Oh, didn't work.
- 21:41Trying it again.
- 21:43Yeah.
- 21:43Yeah.
- 21:43Yeah.
- 21:44You know, there's like a bunch, there's a bunch of really funny commits that go into that.
- 21:47And then you say, okay, so I'm ready.
- 21:49So here's what I'm going to take all that group of 20 commits and merge it as one commit
- 21:54up into my master branch.
- 21:56And so I go back and clean all that stuff up and say, these are the features that are
- 22:01going in.
- 22:01These are the issues that are getting closed because GitHub has all that automation.
- 22:04And for us, you can say closes hashtag issue number and automatically closes the issue for
- 22:09me.
- 22:10And then when I press a squash and merge button, all that stuff gets squashed and you only get
- 22:16one bubble in your master branch with the summarized changes.
- 22:18Yeah, that's really awesome.
- 22:19And of course, you can go back to the other branch and see it, right?
- 22:22And see all the details.
- 22:23Yep.
- 22:23Yeah, that's really nice.
- 22:24I wonder how many people actually use that GitHub automation around like interacting with
- 22:29issues.
- 22:29I use that all the time, even just for myself, you know, hashtag some ID of an issue or PR
- 22:36and say, this is related to that.
- 22:38And it's really nice to just get those automatic links in there.
- 22:40Yep.
- 22:41And like, I'm very opinionated on issues.
- 22:43So I love the way that GitHub does issues, not in the UI or anything like that, just like
- 22:48the idea of it's an issue.
- 22:50It has a title, it has a description, some comments in it, and some tags, some labels,
- 22:54right?
- 22:54I don't need anything more than that.
- 22:57Everything else can be described with labels.
- 22:58Like Jira to you feels like you're swimming in too many, like UI soup.
- 23:03Yes.
- 23:03And so I've used like half a dozen different issue trackers.
- 23:07At the moment, the one we use internally actually is Jira.
- 23:11So, you know, we have the usual GitHub versus Jira thing.
- 23:16So we actually wound up writing a kind of a bridge to help us out, follow our business
- 23:21logic in Jira as we do stuff on GitHub.
- 23:24So we also listen for issue webhooks and update Jiras for us automatically.
- 23:28But this way I can go open an issue in two seconds by typing it into GitHub.
- 23:32And then all the stuff just kind of that goes into Jira gets all rolled into place as it
- 23:36should be.
- 23:37Oh, that's a really, really awesome way.
- 23:39Like, I don't really want to work in Jira.
- 23:40So I'm just going to automate working in Jira like my robot will.
- 23:44Yeah.
- 23:44And you got to be careful with that stuff because then you'll wind up maintaining it.
- 23:48But right.
- 23:50Nice.
- 23:51But yeah.
- 23:51So once our pull request is actually merged, more of our webhooks also say, oh, there was
- 23:57this pull request that got merged into master.
- 23:58So that means we need to deploy code.
- 24:00So we open a new pull request to go to production.
- 24:03And so that's what we call our deploy pull request.
- 24:06And so that one does a little bit of the different thing where it actually builds.
- 24:12So our deliverables are container images.
- 24:15Docker containers, right?
- 24:16Because our service runs in using Docker and AWS container, elastic container services.
- 24:23So just to step back on that a little bit.
- 24:27So a lot of people get confused.
- 24:28Docker containers is one thing, but there's really two concepts.
- 24:34There's the image.
- 24:35And then there's the instantiation of that image, which is your actual container, right?
- 24:40So when I go and say, I want an image of my REST API, that means I have the file system in
- 24:47place.
- 24:47So that when I say Docker run, I can instantiate a version of that image and execute my code inside
- 24:56that environment.
- 24:56So we deliver our two different images, one for our web service or web UI and one for our core stuff.
- 25:04So all of the orchestration that we have to do in order to make our service work, which involves cloud
- 25:11orchestration with AWS and Azure, some third party data center orchestration, switch management,
- 25:18array configuration, and then all resource allocation algorithms, user management, all that stuff.
- 25:25That's all kind of bundled into one container image.
- 25:27And we run it with different environment variables to have it perform different functions.
- 25:32So we have a microservices architecture, but with two images.
- 25:37The way we manage the way that AWS works, when you have the container service in it, you define
- 25:44a service like my core REST API service.
- 25:48And I say, I want this to run several tasks or one task.
- 25:55And I want, I wanted to run this container, but I want this image tagged in such way.
- 26:03So for example, in our repository for that, the REST API backend, when we deploy an image, we push up the code
- 26:12and then we say, okay, we're ready to move to staging.
- 26:15So we tag it with staging latest.
- 26:17So then I can go to AWS and my deployment activation work of make this image.
- 26:23Now the valid one in this environment is just stop the containers.
- 26:27And then AWS will automatically restart them.
- 26:30And when they start to come back up, they say, oh, there's a new staging latest image.
- 26:33Let me download that and use that one.
- 26:35I see.
- 26:35That's really cool.
- 26:36So basically the AWS container service just knows I'm going to run out of this, this get repository
- 26:43with this tag.
- 26:45And I just always look for that.
- 26:47If necessary, rebuild it.
- 26:48Right.
- 26:49A Docker image.
- 26:50A Docker image.
- 26:50Yeah, yeah, yeah.
- 26:51So, and right.
- 26:53So everything just builds off of that.
- 26:55And it's really helpful also because if you broke things for one reason or another, all you
- 27:03have to do is move your staging latest tag back to your previous one and restart the containers.
- 27:09Go now, undo it, undo it.
- 27:12Yep.
- 27:12That's all you got to do.
- 27:13You don't have to worry about anything else because you know that was working code and you're
- 27:16back in time.
- 27:17Now, there's other.
- 27:18That's really nice.
- 27:19Complexities when it comes to database migrations and things like that.
- 27:25But 90% of the time, you don't have to worry about it.
- 27:27Right.
- 27:28Okay.
- 27:28That's really nice because like it's one thing to roll the code back, but you're potentially
- 27:32making infrastructure changes and OS changes at that level as well.
- 27:37And the ability to go, oh no, just put everything in the back of, put it back like it was.
- 27:43It was working.
- 27:43It's pretty cool.
- 27:44Yeah.
- 27:44Because like once, so the code underwent all the testing and all that worked and the
- 27:49container image that we used to build that code.
- 27:53And I'll get a little bit into that in a minute is, it's slightly different than the one I actually
- 27:58wind up putting in staging because it has more stuff in it to maintain the test infrastructure
- 28:03or be able to get to the test infrastructure.
- 28:06The one that actually makes it up into staging, which is equal to the one in production at that
- 28:11point also has a bunch of other things like an NGINX configuration that's a bit different
- 28:16or a uWSGI config along with it.
- 28:20So I can easily like mess that up.
- 28:22And it's only a problem I see when I go to deploy it.
- 28:25Right.
- 28:25Right.
- 28:25I just, today I would have liked to have something like this.
- 28:28I mean, I have multiple like staging and production servers for my various things.
- 28:34And one of them, I got an indication there was an upgrade for IDNA, I think some, which
- 28:41is some low level dependency on my, my system.
- 28:44And then there's requests.
- 28:46And so I upgraded the low level thing and said, oh no, requests forces, you know, to use an
- 28:52older version of that.
- 28:53So guess what?
- 28:54Your site won't even start.
- 28:55It's just dead.
- 28:56But luckily it was like running on, like I had taken that one out of the load balancer and
- 29:00like, oh my goodness.
- 29:01But I had to do a lot more work than just move the tag back.
- 29:04Right.
- 29:05It was like, all right, well now how do I unravel this?
- 29:08How do I make it know that it's supposed to install the right one and all that kind of stuff.
- 29:11So it, yeah, it sounds, I can definitely see the advantage here.
- 29:14And that actually happens quite often with a bunch of things, not just your Python libraries
- 29:20that you have to worry about and their interactions, but also your Docker images.
- 29:23So what happened to us in the past couple of weeks while we were going through testing, like
- 29:27in the middle of I'm tests are passing and then all of a sudden everything's failing, what's
- 29:31going on?
- 29:32Like a couple minutes.
- 29:33We actually hit where whoever maintains the base Python Docker image that we depend on
- 29:39iterated on it.
- 29:40They changed it.
- 29:41Oh boy.
- 29:42Yeah.
- 29:42Yeah.
- 29:43And the new one, and obviously we can go back to the older one, but at this point we
- 29:47wanted to move with a new one.
- 29:48The newer one changed the base.
- 29:51I think it moved the major version.
- 29:54So all the app packages and stuff like that had updated.
- 29:57So I needed to use different, different names to pull some stuff.
- 30:00So that was fun.
- 30:02Yeah, that's fun.
- 30:03And if you do that on the real machine in production while it's running, not so good.
- 30:07Yeah.
- 30:08Not so good.
- 30:08Right.
- 30:09That's why all this stuff is in place.
- 30:10That's right.
- 30:11This portion of Talk Python To Me has been brought to you by Rollbar.
- 30:16One of the frustrating things about being a developer is dealing with errors.
- 30:20relying on users to report errors, digging through log files, trying to debug issues, or getting
- 30:26millions of alerts just flooding your inbox and ruining your day.
- 30:29With Rollbar's full stack error monitoring, you get the context, insight, and control you
- 30:33need to find and fix bugs faster.
- 30:35Adding Rollbar to your Python app is as easy as pip install Rollbar.
- 30:40You can start tracking production errors and deployments in eight minutes or less.
- 30:44Are you considering self-hosting tools for security or compliance reasons?
- 30:48Then you should really check out Rollbar's compliant SaaS option.
- 30:51Get advanced security features and meet compliance without the hassle of self-hosting, including
- 30:57HIPAA, ISO 27001, Privacy Shield, and more.
- 31:01They'd love to give you a demo.
- 31:02Give Rollbar a try today.
- 31:04Go to talkpython.fm/Rollbar and check them out.
- 31:08One question I did have while you're describing what you're up to, and we talked about the
- 31:13GitHub hooks like hashtag closes, hashtag one, two, three, or whatever.
- 31:17Is there a way to make that happen only when it merges into the main branch?
- 31:23Or does that PR commit itself trigger the closing of that issue?
- 31:28Yes, I understand what you're asking.
- 31:29Yes, it only happens when you do the merge.
- 31:32Oh, really?
- 31:33Okay.
- 31:33Because I type it in my commits all the time.
- 31:36Interesting.
- 31:36Okay.
- 31:37Well, that's awesome.
- 31:37Yeah.
- 31:37Very, very nice.
- 31:38All right.
- 31:39So maybe one of the things, I think maybe the most interesting thing to cover is like,
- 31:43we've now set the stage of what you're building, but all the various pieces, there's so many
- 31:48cool little libraries and packages and things involved in the act of building this whole pipeline
- 31:55that you've created.
- 31:56So do you want to walk us through that?
- 31:57In order to run all the testing, we have a Docker swarm internally on premises in our data
- 32:03center where we orchestrate all of this stuff.
- 32:05So I have a container running that is my webhook receiver.
- 32:09And I built that one, that REST endpoint for that using a hug.
- 32:15Hug is a Python 3 REST API, kind of like Flask, but it's a bit smaller and a little more expressive
- 32:23because it uses annotations when you're defining your functions to define the input type of your
- 32:30parameters from your REST API.
- 32:32It also automatically generates documentation.
- 32:35Yeah, that's cool.
- 32:36Hug is really interesting in that it's like one of these REST only frameworks.
- 32:42It's not built from as far as I understand it, mostly for building web applications,
- 32:46but more for building web services.
- 32:48And there's a...
- 32:49Yeah, there's a host of these that are really amazing at sort of leveraging Python 3.
- 32:54So hug is definitely in there, which is super cool.
- 32:58API star.
- 32:59And API star.
- 33:00Yeah.
- 33:00Yeah.
- 33:00That's the new one I'm playing with because API star fully supports asyncio.
- 33:05So I can have an async function and have API star serve it up.
- 33:11That's awesome.
- 33:11Yeah.
- 33:12I can just await in the function.
- 33:13And in the meantime, it'll go off and do other things.
- 33:15It's pretty cool.
- 33:16How about hug?
- 33:16Does it do asyncio?
- 33:17Do you know?
- 33:18I don't think so.
- 33:19Last I checked, it did not.
- 33:21But it was...
- 33:22I think it was able to handle it better because it was all Python 3.
- 33:27Yeah, it's definitely all Python 3, which is cool.
- 33:29And if you look at the performance, Hug is built on a framework called Falcon.
- 33:33Falcon, yes.
- 33:34Which is also another cool web framework that probably no one else has heard...
- 33:38Not many people have heard of.
- 33:39But I had the guys building Falcon on my show.
- 33:41And it's like a really low level, high performance...
- 33:43It is.
- 33:43...web framework.
- 33:44And then Hug is actually built on top of Falcon,
- 33:46which is pretty cool.
- 33:47But they're definitely...
- 33:48Both of those are like right near the absolute top of performance in terms of request per second on some random piece of hardware.
- 33:55So, yeah, pretty cool.
- 33:56I find that a lot of things like Django, Pyramid, or Flask, right?
- 34:01These things have been along for a while.
- 34:03So they have a bunch of things they do for you.
- 34:05And the higher level of abstraction that you get out of a framework, which is what you want from a framework, usually.
- 34:12The more careful you got to be with performance, because in order to give you that abstraction, they needed to put you through a number of other levels, especially...
- 34:23Usually, function calls, which in Python are a little bit expensive.
- 34:27They're surprisingly expensive, actually.
- 34:28Yes.
- 34:29Yes, they are.
- 34:30Yeah.
- 34:31And so, for example, one thing that Hug says, and I think this is partly coming through the Falcon side of things, is it's compiled with Cython to basically get much higher performance, which is a pretty cool aspect as well.
- 34:44Yep, yep.
- 34:44Okay, so you've got this, and this is one of the really important things about this Docker stuff, is it's awesome to have your database in a Docker container and your web framework and then your backend services.
- 34:56But they all need to know, okay, where are you?
- 34:59We just all got rebuilt.
- 35:00Where are you now?
- 35:00Who are you, right?
- 35:01How do I find my backend?
- 35:02Right?
- 35:04So that's the role of this thing that you built.
- 35:06Right.
- 35:06So that receiver, the web receiver also can communicate with the Docker swarm using Docker Pi.
- 35:15And then orchestrate, oh, I need to build a new container.
- 35:18I need you to start a new container.
- 35:21I need to build a new image.
- 35:22I need you to start a new container with this existing or newly built image.
- 35:26So, for example, one of the things we do is when the webhook comes in, we go in and do use requests to go up to GitHub, grab some information on the repository, search for a file.
- 35:36That kind of works kind of like how Travis CI does.
- 35:40We have a YAML that says, oh, here to set up for testing.
- 35:43Here's your install instructions.
- 35:45The actual tests are these things.
- 35:48And there's a bunch of other settings we can do.
- 35:50So one of the things in there might say, well, I want all these tests to run in parallel.
- 35:55So that means I got to orchestrate getting the container built, the container image built off of the repository the way that the instructions say they're supposed to be done.
- 36:04Then taking that and committing that new image to an internal registry that we have and then telling our Docker swarm to start five to six parallel images to go and execute tests based off of that new image.
- 36:22And then those tests all have to require resources of their own.
- 36:27So we have another infrastructure piece, which is a resource manager that all it does is it sits there and receives, waits for a WebSocket.
- 36:39So I can, in order to pull, essentially check out a resource, I open a WebSocket connection and I say, oh, I want this type of resource.
- 36:49And while that WebSocket connection is open, I have a reservation on that resource.
- 36:55So that makes it so that I can write tests and not worry about releasing the resources when they fail.
- 37:00Oh, that's pretty interesting because when the thing goes away, it just, it, because it breaks.
- 37:05Yeah.
- 37:06Socket closes.
- 37:06Boom.
- 37:06It's all done.
- 37:07Huh.
- 37:08I didn't realize, I thought you were just doing push notifications.
- 37:11I didn't realize the WebSocket like session had such an important role.
- 37:15That's pretty cool.
- 37:16Yep.
- 37:16So we do that.
- 37:17And so for that, I used Autobom before, which is something I used inside Sophie, one of my open source modules.
- 37:23But I recently moved it to WebSockets.
- 37:26It's a module called WebSockets.
- 37:28It's a lot more, it's built around AsyncIO a lot better, more Pythonic using Async4 and AsyncWith.
- 37:35So it makes it a lot easier to interact with in a coroutine kind of way.
- 37:39Yeah.
- 37:39Interesting.
- 37:40So your test might just do AsyncWith WebSocket connection and then do its stuff?
- 37:44Something like that.
- 37:45So the test will, the test will, the receiver will do an Async4 around the WebSocket, around receiving something in a WebSocket.
- 37:55And so that's on the server side.
- 37:57On the client side, we just open the socket and do, I think on the client side is an AsyncWith where you just sit there and just kind of wait for messages.
- 38:06Interesting.
- 38:06That's pretty awesome.
- 38:07So then another thing that you do after the test pass, then you build your artifacts, right?
- 38:13Like your packages.
- 38:14And you use proper Python packaging as part of this, right?
- 38:19My two main deliverables are container images, but I also have a, those are built on top of a bunch of other repositories that I have.
- 38:26Two or three of those repositories are, their deliverables are actual Python packages, which are internal.
- 38:33And we use an internal Python package index for that, which we later migrated to a tool called Artifactory.
- 38:41I had never heard about Artifactory.
- 38:42This is a thing by JFrog.
- 38:44Yep, it's by JFrog.
- 38:46It is, oh my goodness.
- 38:47That is one serious piece of like enterprise software management software there.
- 38:52Yeah, it's a lot of stuff.
- 38:54A lot of stuff.
- 38:55Python package indexes, npm indexes, whatever those are called, just NFS, Docker registries.
- 39:02And then you can mirror.
- 39:03So if you have stuff in the outside world, you can mirror those and you can have it automatically push things for you.
- 39:09And you can, you can add like tags and properties to things.
- 39:14It's, it's quite complex.
- 39:15It has a REST API too, to get to it.
- 39:17It's pretty interesting.
- 39:18Yeah, it's really interesting.
- 39:20Their website has like a bunch of cool little animations.
- 39:22It just makes you, it kind of draws you in.
- 39:24So to me, it looks like you've taken, you guys in general have taken a lot of the awesome stuff from the public open source and maybe sort of made your own private version of it.
- 39:34So you've got, you know, GitHub Enterprise.
- 39:36You've got like a private PyPI server, private Docker repositories, all sorts of stuff, registries.
- 39:43Yep.
- 39:43It just makes the whole thing easier to work with because you have, you have an existing ecosystem that can work with all of this.
- 39:49You don't have to build your own modules to talk to them.
- 39:52Yeah.
- 39:52Super cool.
- 39:53I'd never heard of Artifactory, but it definitely looks like, like worth checking out.
- 39:57It's no small piece of software as far as I can tell.
- 39:59It looks like a big, a big thing that does a whole bunch of stuff, but it definitely looks like it.
- 40:04It's pretty cool.
- 40:04Yeah.
- 40:05And it comes with its own complexities.
- 40:07So if you want, if you just want an internal package index, really, there's a bunch of existing things already you can use, or you could just build your own.
- 40:15I built one with Hug before Artifactory.
- 40:17It's just a web server.
- 40:18Right.
- 40:19It's just a web server and a couple of interactions.
- 40:21It's not super complicated, but yeah.
- 40:22Pretty cool.
- 40:23And so we talked a little bit about some of what happens next.
- 40:26You have your GitHub hooks and your PRs and all that kind of stuff.
- 40:31What else is involved?
- 40:32So you have your Hug service that you've talked about.
- 40:35That's pretty awesome.
- 40:36You used PyDocker, which you mentioned in passing there.
- 40:40DockerPy, sorry.
- 40:41Which is just pip install Docker, right?
- 40:44Yes.
- 40:44Yes.
- 40:45Nice.
- 40:46Pip install Docker.
- 40:46Okay.
- 40:46So if you wanted your Python app to, say, orchestrate creating new containers or spinning them up, that would be what you use?
- 40:54Right.
- 40:54And it's got two client layers.
- 40:59One is like a lot lower level, which is an API client kind of thing.
- 41:03I think they call it API.
- 41:04I forget what they call it.
- 41:05And then there's one which is like the Docker client.
- 41:07So the Docker client operates more at an object level.
- 41:11So you can say, so you point it to where your Docker, your main Docker master is of your swarm.
- 41:19And you can just do .images, .lists, .create, stuff like that.
- 41:27Same thing for .containers.
- 41:29And then with the swarm in general, things get pretty complicated when you go out to swarm or Kubernetes, mostly because things are your containers that are managed by the swarm are not really containers.
- 41:42They're services.
- 41:44And it all makes perfect sense if you're running, say, a web service.
- 41:48And you say, I want a web service that needs to always be up and I want two instances of it.
- 41:53So you run one service with two tasks, each one of this type of container.
- 41:59But for us that are actually creating essentially one container or two containers individually to run every time, we have to make a new service for it.
- 42:08So there's a lot of layers there that complicate things a little bit.
- 42:12But it's very easy to manage with Docker Pi because it's all kind of built by the Docker guys.
- 42:16Yeah.
- 42:16Okay.
- 42:16That's really, really cool.
- 42:17And then another thing that you use is something called ChatOps.
- 42:22What is ChatOps?
- 42:23Is that like something for DevOps?
- 42:25Sure.
- 42:25When our deploy PR is complete, that means it built a container image and it pushed that image out to our Amazon container registry.
- 42:37So then we need to, we could automate this, but I still want to have some manual checks in place.
- 42:44So what we did was we have a chat system and just made a bot.
- 42:52And I can tell the bot, hey, I want this image to be my staging image.
- 42:57Go do it.
- 42:58And then the bot will go in and tag that image with staging latest and it'll go in and stop all my containers in AWS and which will automatically restart and essentially do my flip over from to a new version.
- 43:12That's awesome.
- 43:12Now, ChatOps in general is kind of like a concept of being able to run, to manage a bunch of services or deliverables or code or whatever you want to do over a chat system using a bot, essentially.
- 43:26Yeah.
- 43:26That's a pretty cool idea.
- 43:27I mean, we saw Kelsey Hightower's thing at the 2017.
- 43:32Yeah, it was 2017 PyCon where he got basically Google's voice assistant to do his Kubernetes stuff, right?
- 43:40Yep.
- 43:41So I was kind of laughing through his presentation a little bit because I was like, yep, that's what I do, except I can't talk to it.
- 43:49But, you know, not through voice, right?
- 43:52Well, you're not far away from getting some Google Home or some Alexa.
- 43:57Yeah.
- 43:58You could use some of the Alexa stuff going.
- 44:00And my, sorry if everyone's Alexa is going off, mine is as well now.
- 44:03The Amazon assistant, let's call it that.
- 44:06There's a Python one called Calliope we were just looking at today.
- 44:09And there's another one, I forget the name, that's also pretty famous in the Python world.
- 44:15We were just laughing at it this morning saying that we should hook all our stuff up together and just say, hey, deploy to staging.
- 44:21Hey, restart our stuff.
- 44:24There's some pretty easy ways to do it, actually.
- 44:27Yeah.
- 44:27Just some random dude walks into the cubes and just kind of kills all our stuff.
- 44:32Deploy production.
- 44:33No, no, no, no.
- 44:34Yeah, that's pretty awesome.
- 44:37Another tool that I don't think I've heard of that was really impressive to me is Locus.
- 44:43Yes.
- 44:43Yeah, tell us about that.
- 44:45Like, use pytest for your standard level, your automated testing.
- 44:49But Locus is more on the performance side, right?
- 44:51That's right.
- 44:52So, Locus, the idea of Locus is to test web services.
- 44:58So, you can write tasks in the forms of scripts or actions that represent users of your service.
- 45:09And you can have, like, all set of kind of like setup and teardown and type of stuff, kind of like your regular type of test environment.
- 45:16But then Locus can manage that over a large amount of virtual machines to go off and test your API and then come back and tell you, well, you managed to receive these many requests per second in this endpoint and these many in that endpoint.
- 45:32And this one was rate limited at this point.
- 45:34And this one was, you know, errored out when you did this thing.
- 45:37And so, you get a report.
- 45:38That's really cool.
- 45:39So, you've got, like, all the different parts of your site.
- 45:42And it shows you, here's the number of requests in a big grid.
- 45:45Like, this URL got this number of requests with this many failures.
- 45:48And, you know, average response time is this.
- 45:50And, yeah, it's super cool.
- 45:52Like, one of the big problems with the load testing is actually it can be at least getting enough pressure on your web server, right?
- 46:01Like, if you just do that over, say, your broadband connection at home on your laptop, like, maybe the limit is your outbound network or something, right?
- 46:10Something like that.
- 46:10Whereas, like, if you could put it on 100 VMs, spin them all up and, like, you know, turn those loose in a slowly way.
- 46:17Like, that's awesome, right?
- 46:18Yeah.
- 46:19You can have a different amount of virtual machines and it just kind of orchestrates all of them for you.
- 46:23You just got to have Locus installed on them and the scripts that they got to run.
- 46:26But, yeah.
- 46:27Yeah, this is looking super cool.
- 46:28I definitely would like to look more into it.
- 46:31So, yeah, it says define user behavior with Python code and swarm your system with millions of simultaneous users.
- 46:37You know, when tools like this exist, I'm just blown away when there are websites that fail so badly when they get a lot of traffic.
- 46:47You know, like, I understand there's some limit where it's like, okay, it just is not going to take more.
- 46:52But that limit should be many thousands, not a couple hundred, right?
- 46:57Right.
- 46:58And so, another thing we did, so we used Locus to figure out where we might break.
- 47:03And then what I do is there's in our Docker image, whenever that actually gets executed into a container, there's a few instructions that go in and replace environment variables in our Nginx configuration.
- 47:20So, I can go in and tweak the request per second.
- 47:25So, I do it at the Nginx level so I never hit the Python code.
- 47:28So, if I know I'm going to break at whatever, I can put in a limit at 8 or whatever on my...
- 47:37And then it just queues in Nginx until...
- 47:40Correct.
- 47:41...until Microwezky's done it.
- 47:42So, you can configure Nginx to do that per IP address or just in general and what error codes to return, all that stuff.
- 47:52Oh, that's awesome.
- 47:53So, a couple of other tools that are at play here are some of your projects.
- 47:59One is Sophie and one is Corv.
- 48:01So, Sophie falls to a pretty interesting realm of Python, I would say.
- 48:07Yeah.
- 48:08Maybe tell people what Sophie is.
- 48:09Some people talk a lot about user interfaces and Python.
- 48:15I don't know any of those.
- 48:17Oh, yeah.
- 48:17Actually, I think it was after one of your very first, like a long time ago, conversations about user interfaces and stuff.
- 48:23And I was like, oh, you know, I'm pretty sure this is exactly what I was thinking.
- 48:28I've built so many, you know, Bootstrap-based quick interfaces with like some just jQuery default stuff.
- 48:37I don't want to write that anymore.
- 48:38I want to just write it in Python.
- 48:40Yeah.
- 48:40So, what I did is essentially...
- 48:43It's a module that lets you do that where I kind of wrapped the widgets that you'd get out of Bootstrap, the HTML kind of library to help put that together.
- 48:52But it evolved because the way I do it is through WebSockets and AsyncIO.
- 48:58So, in the back end, you can kick off a web page that loads off a basic JavaScript library that you only have to write once, which tells that web page how to interact with Sophie.
- 49:11And you run a Python web server, WebSocket server, which is Sophie, that actually sends commands out to the web page.
- 49:19So, you open up a website and all of your interaction and eventing can go all the way back to your Python code and you can react on that and come back out to the UI.
- 49:29And after that evolution, I realized that Sophie is actually really a WebSocket protocol to help you do all of this and kind of like library to help you do all of this.
- 49:40Because you can just drop in and replace other ways of doing these conversations between client and the server.
- 49:46And so, what I did after that was I went to a game engine, Unity 3D, and dropped in a WebSocket client written in C#.
- 49:57So, now I can, from Python, spawn game objects and things like that in Unity.
- 50:04That's pretty awesome.
- 50:05So, it's a little, a tiny bit like Electron.js type apps where there's like a Python backend.
- 50:12It's some sort of web front end, at least the first incarnation of it.
- 50:15It's also deployable kind of like that if you want as well.
- 50:18But you can also do it.
- 50:20So, the original idea was to go down a desktop application type thing, in which case you would want to build it like that, like an Electron.js thing where you distribute Chromium, the browser that Chrome is based on, which is completely open source as your front end.
- 50:34But you can just deploy the backend by itself onto like some service in a Docker swarm, which is what we do.
- 50:40And just open up a web page and talk to it.
- 50:42Yeah, nice.
- 50:43And your other project, Corv, is about sort of skipping the whole REST API entirely, right?
- 50:49And using actually SSH?
- 50:51So, in the process, over the years, working on different services, right?
- 50:57You always want to have, there's always the customer facing one.
- 50:59But then you always want some data or something you want to have in some admin mode for.
- 51:04So, it's always a risk to put those admin endpoints in the customer facing one.
- 51:08Because if they're there, somebody's going to fiddle around and bump into them.
- 51:11And then you've got to worry about security and all that.
- 51:15Right.
- 51:15It just takes one forgotten security check and all sorts of badness happens.
- 51:19Right.
- 51:19Especially when those checks are usually decorators around Python functions, which you could forget to put in.
- 51:24Right?
- 51:25Yeah.
- 51:25So, the idea is, instead of using HTTP, use SSH.
- 51:30And there's, the first time I came up with this was when I ran into Async SSH, which is the base library for this.
- 51:38Because I wanted an async way of doing SSH calls.
- 51:41And they let you do this.
- 51:43So, I let SSH take care of the authentication.
- 51:46You've got to have your client cert the allowed clients, known hosts as well on both, you know, your known hosts on your client and your acceptable public keys for your client on the server.
- 51:58And so, SSH handles your authentication.
- 52:01And then after that, you open a TCP socket over SSH and just send information back and forth.
- 52:07I just wrapped it in JSON and kind of used kind of HTTP-ish REST-like mechanisms for, like, get, store, update, and delete.
- 52:16So, I do that as my admin interface.
- 52:19It's only accessible to me.
- 52:20But even if I break, even if I mess it up and it somehow exposes the ports out to the internet, it's still SSH.
- 52:27So, you still need the proper keys to get in.
- 52:30Yeah.
- 52:30That's really awesome.
- 52:31I think that's quite a cool idea.
- 52:33Like, I have certain things where you can only get to them through SSH.
- 52:38You can't access them or interact with them, you know, without that.
- 52:42And this is kind of like, instead of just exposing, like, tunneling that through or something, you're like, no, let's just make that the API network layer.
- 52:50Yeah.
- 52:50Exchange layer.
- 52:51Both of those are async.
- 52:53So, you can just have it kick off long-running things.
- 52:57Doesn't matter.
- 52:58You'll get a callback when it's done.
- 52:59Kind of thing.
- 52:59Yeah.
- 53:00Really cool.
- 53:00Let's see.
- 53:01Another couple of things that were really interesting that you're using.
- 53:03One is PyAutoGUI.
- 53:05And that's from Al Swagger.
- 53:06What's that?
- 53:07These are kind of more of an experimentation thing.
- 53:10So, we have pytest to execute all of our tests, which is great.
- 53:14We use Selenium for a few things.
- 53:17And then we use some other JavaScript node-specific runners for the WebUI stuff as well.
- 53:24But you just, like, browser compatibility is always going to be an issue.
- 53:29We want to try to do something more at the...
- 53:33We ran into a couple of issues where you say, you open this thing in Firefox, but if you open it in Chrome, this one little piece of it is kind of wonky.
- 53:42It's larger than it should be or it's off the screen and things like that.
- 53:46Yeah.
- 53:46So, PyAutoGUI lets you...
- 53:49Does a lot of stuff.
- 53:50It's about automating your OS through GUI things.
- 53:55Move the mouse here.
- 53:56Click on this.
- 53:58Type this from the keyboard and things like that.
- 54:01Now, it also helps you take screenshots.
- 54:04So, one of the things that I was thinking was we could put something together that says, open browser, type this into location bar, load web page, type username, type password, click login.
- 54:18Right?
- 54:18And then take a screenshot of the result and then use OpenCV to compare that screenshot to an already existing screenshot that I should have and maybe find the next button I have to click on.
- 54:33And if that button is not on the screen, then error, move on.
- 54:37Kind of way.
- 54:37The advantage of using the OpenCV stuff is you can have a confidence level on it.
- 54:41So, if things are off, you'll know.
- 54:44That's totally cool.
- 54:46Yeah.
- 54:47There's a project by a friend of mine named Llewellyn Falco called Approval Tests.
- 54:52And it will do something similar, basically.
- 54:55It will go and instead of having a whole bunch of tests, it just says, here's the output.
- 55:00Is that good or bad?
- 55:01You say, yeah, this is good.
- 55:02And then it records that.
- 55:03And then unless that output changes.
- 55:05Oh, sure.
- 55:05Right?
- 55:06And it could do that.
- 55:06I think it does that with pictures as well.
- 55:08Right?
- 55:09So, you could screenshot something and go, this is the verified version.
- 55:12If this changes, I need to check it out.
- 55:14Otherwise, just keep running the tests and saying they pass.
- 55:16Cool.
- 55:17Yeah.
- 55:17So, something like that is what we wanted to do.
- 55:19Yeah.
- 55:19Yeah.
- 55:20That sounds really cool.
- 55:20And you were talking about using OpenCV as well, huh?
- 55:22That's cool.
- 55:23And I actually tried out a few different things and OpenCV wound up being the faster one.
- 55:26Yeah.
- 55:27Awesome.
- 55:27Cool.
- 55:29All right.
- 55:30There's just so many little interesting tools and steps along this whole process that I think a lot of organizations are trying to get to, right?
- 55:38Like I said at the beginning, right?
- 55:39I check in, I merge a PR, I wait, magic appears on the other side, right?
- 55:44With zero downtime.
- 55:45But it sounds like you guys have really got it pretty nearly there.
- 55:49That's awesome.
- 55:50So, was it worth it?
- 55:51Oh, for me, it is, right?
- 55:52I mean, you have to, but you have to step back.
- 55:55You have to do your engineering work behind it, right?
- 55:58Don't just do it because everybody's doing it kind of thing.
- 56:00If we have a service, right?
- 56:05So, it is in our best interest to make it as fast and as easy as possible to release a fix out to the customer.
- 56:16Yeah.
- 56:16And the last thing you want to do is like try to release a fix and then take the whole thing down and make it worse.
- 56:21Exactly.
- 56:22So, the way to go through all of this is you have to step back.
- 56:26You have to look at your process.
- 56:27You have to, it's a lot of pieces and a lot of moving parts.
- 56:31So, you have to say what checks do I need at which point in time of my delivery flow does it make sense to check what?
- 56:41So, if I say all these tests need to pass here, that means I've guaranteed this basic function is working.
- 56:47These tests pass here, that means my infrastructure is working, et cetera, et cetera.
- 56:52Right.
- 56:52And it also depends on the quality of your test, right?
- 56:55Like you need to know that if the tests pass, pushing to production without further question is okay, right?
- 57:03Whereas if you only test a few things and maybe they don't test that well, like if a lot of stuff slips through, then this isn't so helpful, right?
- 57:11It's got to be a good net.
- 57:12Right.
- 57:12And we made the decision early on to put, to invest into that because, you know, we think it's going to bear fruit for us and it has been very useful.
- 57:21We very, very seldomly have a really broken function into staging.
- 57:26And when we do, the first thing to fix is not the function.
- 57:30It's the test to make sure that you can't push again with it broken.
- 57:36Yeah.
- 57:36That's a really good point.
- 57:37It's like, why did this get through?
- 57:39There's actually a problem in the continuous delivery system that it got this far.
- 57:44Now let's fix that, right?
- 57:46That's awesome.
- 57:47Yeah.
- 57:47And take advantage of the situation that you're in, which is you have a real failure, not something that you thought you might have.
- 57:55You have a real one.
- 57:56So make sure that your tests fail when you have a real failure and then go fix the code to make sure that it passes.
- 58:02That's awesome.
- 58:03I think that's really great advice.
- 58:04All right.
- 58:05I want to take just a moment, let you maybe list off some of your popular articles that you've written, but don't want to take too much time since we're running out of that.
- 58:13The most viewed article over time from the blog has been Threaded Asynchronous Magic and How to Wield It, which is pretty much about an intro into AsyncIO and what you can do with it.
- 58:25Yeah, it's a really good one.
- 58:27Just how to manage tasks and stuff like that.
- 58:29The one that's like most read, as in like the most time people have spent going through all the details was the Python Ate My GUI, which was the starter article for making Sophie and kind of the state of GUIs in Python.
- 58:45And the most recent one I have, which is now no longer true, the most recent one is about GDPR.
- 58:54And the implications of the European, the new European regulation on, for software developers.
- 59:01But the one before that, which was the one in my list was Practicality Beats Purity about microservices and monoliths, which we talked a little bit about already.
- 59:10Yeah, people should check that out if they're considering one or the other.
- 59:13And there's a lot of interesting trade-offs that you highlight there.
- 59:16All right.
- 59:17So if this was a few weeks ago, I might ask you a little more about the GDPR and get your thoughts on that.
- 59:22But there's something bigger to talk about.
- 59:23So you talked about using GitHub Enterprise.
- 59:26Like I'm super invested in GitHub.
- 59:28I just checked like right now, the time of recording, I have 134 repositories in GitHub.
- 59:34That's a lot.
- 59:36And many of those are private ones, like supporting my various things, but a lot of them are public as well.
- 59:40So the big news, like last week, was that Microsoft acquired GitHub.
- 59:45Yes.
- 59:46What was your first thought?
- 59:47Oh boy.
- 59:47That was my first thought.
- 59:49Yeah.
- 59:50I'm not a Microsoft fan, but I am willing to admit that they have a different direction, which I like, which is way more embracing of open source.
- 59:59They are the world's greatest, biggest open source contributor today.
- 1:00:05Which is like, think about where we are, just that you said that.
- 1:00:08Like, that's crazy.
- 1:00:09Yep.
- 1:00:10They have incorporated Linux into Windows, sort of.
- 1:00:17They have contributed a significant amount of work to Docker.
- 1:00:21And GitHub, or Git itself, actually.
- 1:00:23The Git virtual file system.
- 1:00:25And Git, yes, with the Git virtual file system, which was a huge contribution, especially for folks doing large single repository code bases.
- 1:00:33So that's, for me, that's a good direction.
- 1:00:38Unfortunately, the track record so far hasn't been all that great, even with their most recent acquisitions.
- 1:00:44The most common one that I hear and that I have problems with is Skype and where that wound up with.
- 1:00:50But some folks also complain about how LinkedIn is going.
- 1:00:54I don't know.
- 1:00:55So I don't know.
- 1:00:57Internally, there was a lot of outcry from the community.
- 1:01:01But equally, there's a lot of Microsoft developers that are like, well, but we at Microsoft love GitHub just as much as you guys do.
- 1:01:09And I genuinely believe that.
- 1:01:11It's not about whether the folks contributing to the code like it or not or want to keep it going or not.
- 1:01:19It's the fact that now you've concentrated the majority of open source projects in a business that has its own languages, its own platforms, its own software, which you could maybe wind up getting biases for.
- 1:01:40And once it's there, it's just going to be more complicated.
- 1:01:43There's also questions about IP that people brought up.
- 1:01:47I don't know how much that's a thing.
- 1:01:50But, you know, technically, everybody had access to all those repos anyway.
- 1:01:55But I guess now they get access to all the private ones, too.
- 1:01:57So I don't know.
- 1:01:59Yeah.
- 1:01:59So a couple of thoughts.
- 1:02:00Yeah, I definitely sort of felt similar to what you're saying.
- 1:02:03Like, I don't think Microsoft has any sort of bad intentions towards GitHub.
- 1:02:08I think they do.
- 1:02:09Right.
- 1:02:10I think they do really love it.
- 1:02:11They're really invested in it.
- 1:02:12However, you know, they could fumble, fumble it and just make it not so nice.
- 1:02:17Right.
- 1:02:18I don't think they would like intentionally shut it down or do something to make it less good.
- 1:02:22But they certainly could try to make it better and make it worse.
- 1:02:25That is a thing that could happen.
- 1:02:27The IP part is pretty interesting.
- 1:02:29What really surprised me is there's an article called, it was on Ars Technica.
- 1:02:34That's one of my favorite places to read this kind of stuff because the comments are great.
- 1:02:38It says, everyone complaining about Microsoft buying GitHub needs to offer a better solution.
- 1:02:41And they really went through point by point, like how GitHub was actually in pretty big trouble.
- 1:02:47Yeah.
- 1:02:47And at some point, this is almost like, would you rather not have GitHub or have a GitHub that Microsoft owns?
- 1:02:54Rather than, well, I want GitHub to be this free thing.
- 1:02:57Like to me, the biggest negative here is, it's just consolidation.
- 1:03:00Right.
- 1:03:01Like there was this sort of independent place where open source could go be its thing.
- 1:03:06And everybody was on sort of equal footing.
- 1:03:08And now it's been consolidated into one of the big five tech companies.
- 1:03:12And that just, that's just different and not necessarily better.
- 1:03:17But after reading this, this Ars Technica article, I felt much better about it because I didn't realize the alternative was as bad as it.
- 1:03:24It could be.
- 1:03:24But I mostly don't like the fact that it's just consolidating further in the whole tech space.
- 1:03:31I think that is the main concern.
- 1:03:32I agree.
- 1:03:33I think after going through this, I think it becomes a bit more obvious that we kind of, I think I said this over Twitter, we kind of need like a Mozilla software foundation of open source repositories kind of thing.
- 1:03:46Yeah.
- 1:03:47Like an independent body that's somehow funded that whose sole purpose is to just, you know, you put stuff up there and it's going to stay there and, you know, we'll keep it up kind of thing.
- 1:03:57And that would alleviate the concerns a bit.
- 1:03:59It would.
- 1:04:00I think on the positive side, I think, you know, Microsoft has done a good job with Xamarin, right?
- 1:04:05And that was open source sort of, you know, they, I think that that's stronger now than it has been as part of them taking it over.
- 1:04:12So there's one, you know, check for maybe the win, win box, you know, Microsoft's part of the Linux foundation.
- 1:04:17And they're like, there's signs that this is going to go well.
- 1:04:20There's like you said, Skype example.
- 1:04:22So there's also signs where it might not go so well.
- 1:04:24So I think it's, it's up in the air.
- 1:04:26My concern is the two things like it could just get fumbled and messed up.
- 1:04:29But the fact that they're running GitHub as an independent organization, it's really good.
- 1:04:34The fact that Nate, the guy that was one of the co-founders of Xamarin is running, going to be the CEO of GitHub, where apparently they were struggling to get a CEO at all.
- 1:04:44There's like a big problem there.
- 1:04:46So anyway, it's, I think it's, it's pretty interesting.
- 1:04:49Fingers crossed for a positive result.
- 1:04:51Yeah.
- 1:04:52And from the business perspective as well, you know, Microsoft, I'm sure it makes perfect sense for them.
- 1:04:57They just spent all this time into the Git virtual file system stuff and they just moved all their stuff over to that.
- 1:05:03So they want to secure a future for that.
- 1:05:06Right.
- 1:05:06And this is their, this is their way of doing that.
- 1:05:09Yeah.
- 1:05:09I guess the other thing is that sort of gives me sort of a positive outlook, I guess, is at least the way I've seen it these days.
- 1:05:17It's like, if you want to understand what Microsoft is doing or why they're doing it, the answer is Azure.
- 1:05:22And then you've got to figure out what the question is.
- 1:05:24Like, obviously it's for Azure, Azure, Azure.
- 1:05:26They're just trying to grow Azure.
- 1:05:28Like they could just care less about windows or to some degree office, right?
- 1:05:32Like they see like the new lock-in is the cloud.
- 1:05:35And how do we go be part of that?
- 1:05:37And you know, all the different technologies run there.
- 1:05:39So I think that that's going to put some pressure to keep it more fair handed rather than say it's only .NET or it's only windows or any of these sort of pressures that you kind of hinted at at the beginning.
- 1:05:49Yep.
- 1:05:49Agreed.
- 1:05:50All right.
- 1:05:50Well, I guess we'll leave it there.
- 1:05:52We could go, we could have a whole show on the thoughts of the Git application.
- 1:05:54Maybe I will at some point.
- 1:05:56At first I was like, oh boy, this is probably going to get messed up somehow.
- 1:06:01But after spending a week doing more research, I'm kind of like, well, it looked kind of like it was necessary and it's probably the least bad outcome that we're going to get.
- 1:06:10So, you know, fingers crossed.
- 1:06:11Yeah, for sure.
- 1:06:12Cool.
- 1:06:13All right.
- 1:06:13So let me hit you with the last two questions before you get out of here, Chris.
- 1:06:16So notable PyPI package.
- 1:06:18We covered a bunch actually.
- 1:06:19The two that I would bring out out of the whole list, which since we're kind of talking about async stuff as well as async SSH.
- 1:06:27Forget about Parameco.
- 1:06:29Async SSH does it better.
- 1:06:31And there's, and the WebSockets module, which it's pretty good if you're doing anything with WebSockets.
- 1:06:37Nice.
- 1:06:37And so final call to action, people want to bring continuous delivery into their whole workflow, their life, their team.
- 1:06:44How do they get started?
- 1:06:45The first thing to do is to, we kind of touched on it a little bit earlier, is step back, analyze what benefits you get out of it and what problems you're trying to solve.
- 1:06:55And then slowly go through it and put something in place where, you know, my end result is going to be X, a delivered package of this here.
- 1:07:03And I need to guarantee that it works in pieces at different steps of the way.
- 1:07:08And figure out the effort to make that happen.
- 1:07:11If the effort is really, really, really, really, really large, then maybe it's not worth it for you.
- 1:07:16Cool.
- 1:07:17Well, I really appreciate you coming and sharing what you guys are up to because you definitely have it pretty dialed in.
- 1:07:21Yeah.
- 1:07:23Yeah, no problem.
- 1:07:24Glad to be here.
- 1:07:24It's always fun to have these conversations.
- 1:07:26Yeah.
- 1:07:26Thanks, Chris.
- 1:07:27This has been another episode of Talk Python To Me.
- 1:07:31Our guest has been Chris Medina.
- 1:07:33And this episode is brought to you by Linode and Rollbar.
- 1:07:35Linode is bulletproof hosting for whatever you're building with Python.
- 1:07:39Get four months free at talkpython.fm/Linode.
- 1:07:44That's L-I-N-O-D-E.
- 1:07:45Rollbar takes the pain out of errors.
- 1:07:48They give you the context and insight you need to quickly locate and fix errors that might have gone unnoticed until your users complain, of course.
- 1:07:56As Talk Python To Me listeners, track a ridiculous number of errors for free at rollbar.com slash Talk Python To Me.
- 1:08:03Want to level up your Python?
- 1:08:05If you're just getting started, try my Python jumpstart by building 10 apps or our brand new 100 days of code in Python.
- 1:08:12And if you're interested in more than one course, be sure to check out the Everything Bundle.
- 1:08:15It's like a subscription that never expires.
- 1:08:18Be sure to subscribe to the show.
- 1:08:20Open your favorite podcatcher and search for Python.
- 1:08:22We should be right at the top.
- 1:08:23You can also find the iTunes feed at /itunes, Google Play feed at /play, and direct RSS feed at /rss on talkpython.fm.
- 1:08:33This is your host, Michael Kennedy.
- 1:08:35Thanks so much for listening.
- 1:08:36I really appreciate it.
- 1:08:37Now get out there and write some Python code.
- 1:08:39I really appreciate it.