How to easily Continuous Deployment with Cloud Run

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi my name is Kevin and I am a organizer of the GD cloud Copenhagen and I gave this workshop yesterday and I want to give the same now I want to show you how you can do continuous deployment with cloud run and cloud built it's a cloud build and clove run is two amazing products from from google cloud and cloud run is actually just now getting general available but the cool thing is like these products are super simple individually but putting them together can be a little bit tricky because cloud Google cloud is a platform that really caters for everyone's needs and therefore there are some security stuff but in this demo I will show you how you can get started with Google cloud and cloud run using any computer it doesn't matter if you want Mac or Windows or Chrome OS and in the end we will have a website we're on github you can make a commit and see it life building with docker in just around 40 seconds that's pretty cool so first off I would maybe just show you a little bit about Google cloud the how looks so I always switch to my screen here so you can see here I created a new project here called Kevin awesome project you can create a new project here by clicking new project if you want to do so I recommend creating new projects always because it's just much easier to separate if you are trying out something new you can always delete it later on so what I want to do now it's like a we need to test the law application first and Google Cloud actually has this really cool awesome like called cloud shell and cloud shell is this where Google actually give you a micro instance so by just click on this they will actually spin up a small instance for you where you can do all kinds of stuff like it's basically a machine that you are and you're not paying for it which is pretty cool but you're are you have access to all the cloud products through that show so now we have it ready and you can see this is just a normal shell and we can just expand a little bit here if I can pull up and we can see here we have a G cloud the command line if you so this basically allows us to do anything from just a web browser but Google cloud also has this a cloud shell editor so you can click if you click here launch editor it actually opens up and where you have all your projects here in this so you make it a little bit smaller you can see here I have a lot of different projects over the side yeah but we're going to do if some of the things through the terminal down here so this takes a little bit while to load but while we're doing that we can begin to make our new project down here in the editor because what we're going to do is like make it a folder the similar way that what our project is called and that's just where we're going to store all our all our source code files so we call the Kevin awesome project and we can then change the directory into that Kevin awesome product so here what we need we're going to build an odious application it could be any application but in this example I just have a lot of expansion note yes but you can follow the project if you don't know not yes it's pretty simple but we're going to need a server guess which is pretty normal and not yes and we can say touch which basically then creates the file name t1 cloud shell has this built in where you can they say cloud shell edit server yes and here we basically pop up and open it here and this editor is not really where you can just we don't even have to save it all to safe whenever we are finished typing so a basic node.js server looks like this it's called we just need to load first T yeah not this we need to require HUP oh it's like a little bit tricky what require and we need to require the HTTP module then we can create a server here say speed create server and this takes requests responds and here we say send end here this end I'm gonna say hello awesome and also just for good measure we want to say console just so we have something we'll see whenever get a new connection new connection so this is so and then we need to listen on airport this is actually one of the only thing that is likely a requirement for how to use cloud one is that you need to listen on the port like that is coming from the environment and you can do that by say process dot E and V dot port or if it's undefined we will just say you listen on 8080 then we will say server that listen listen on that port and then we can give it a call back that will basically run whenever it is listening so you can say here listening this will just tell us like that service Tyler correctly and it's actually listening on the board so save this file and we can test it down here see so ever guess I think this is some of the things it's really important to continuously test this so that you are none other points you're basically trying to get something Runyan cloud run that you haven't tested before Google cloud has another cool feature where you can actually get access to this cloud shell through the interface so if you click here web preview you can see preview on port 8080 and what that would do is it would open a web browser and actually proxy the connection into this container you have running on your micro instance you can see how awesome so we know that works so we can switch back here and a/c control C and stop that what we need now is a docker file and docker file so we can describe how we're going to what dependencies our application has and how we're going to package our application and that is called just docker file and we can touch it and we can say cloud shell edit docker file again and then we will see it up here we could also edit it in vim on nano if you know that but I think this is a cool way for everyone to get started I'm Clara London daughter or group out so we can see here from node and we want to say 13 which is later on and a slim then we will take all defining work dear because this defines where all our commands inside the hotel will be run by default if we don't define it it will run inside the root folder because the default user is root that's a lot about docker but that's just some details they there's a lot of information you can find on docker documentation about this then we need to add all our files into the app folder and then we need to define what is our start command and that is note server so this basically explains our container how we are going to run this and we can test it out by saying here darker build that's T we need to give it a name the tag and we can say awesome project and then once we stand inside the folder we can say just save dot and darker only over like we already know the context where to take all the files and also how to find the docker file so we build it here and it should build in a little under minute so here you can see building it's pulling the image slim version and you can see it's downloading really fast it's actually downloading fast and it's extracting place actually in this machine we are connected directly on the internet which is super fast so it's also a good way to save bandwidth if you are in a in a place where you don't have a fast internet connection to pull down docker images so here we can try to run it again we can say docker run IT to interactive to see the terminal then we can say P for port we want to expose 8080 again and 88 inside the container and then we want to say awesome project which is the name of our container that we just defined now we can see here it says listening again and we can try it out and see if it works still and our container says hello awesome and we can go back and we can see we've got two new connections and the reason just a small fact the reason why we've got two new connections because by default browser will try to fish the favor favorite icon also a small small fact so we now have a proper application and have a docker file a explains like how our application is going to run and we can now go on the next step so here we actually have to to do a cool things but I want to show you how you can do this with github because a lot of developers use github and and github is super cool we just we could deploy to a cloud run from here but it wouldn't be that workflow you would normally have so i actually recommend that we go now to github create a repository so we can link it together with clout bit later on so with that I will just show you here let's go to here github create just github calm we can go here and say here is a new repository create a new one and it will be here Kevin awesome project and we it's fine if it's just public and this is also fine so here we have an empty one and what we can basically just do is we can copy basically the files from I obviously I don't condone this is not how you do probably but we just need to do it fast so let's just do that again so here we have to say docker file and we can go here in and copy the darker file say commit and we need to create a new file as well server yes and you can copy that from here and we're basically now have a github project with two files where we are ready to do continuous integration because the continuous integration is that we're for each time we commit each time we make a change we also mainly testing that this whole thing works without having to do anything manual actions this is important because like once you have to do something manually your most much more likely to actually make a change and forget to test it because you have to test them anyway so that's why we have to continue to test it so what we now need to do is like we need to go to a something called cloud built in cloud build we can configure to connect to to github and ultimately build our requester whenever we get a change so you could find it or here in the build and it would be down here under a on tools so cloud though but one thing I like is it's always like you can say a shift a slash and then you can search for it this is often much quicker if you have to switch between products so this is what you see first time when you're open new project you basically have to click enable to out the lazy eye and it will add this correct service accounts and the reason why they are not enabled by default you can say is because like that google has a lot of projects and they were if they were all enabled they will both take a lot of like service accounts which is just like for permissions and so it would be unnecessary because not all projects had it needed but now we enable it and now it will work so now we just need to go to triggers and we can say connect the repository google has nowadays like github a cloud bill github at this is probably their preferred but little in beta and I have experience and problems so I still recommend going with the github mirrored yeah it's just easier to use what you what I already know and this has this has been working for quite some time so you see that continue then you need to if you're not already authenticated with github it would show you a indicator github like it off but you can see here I'm already authenticated so we will just switch straight to it and here I can say awesome project search from my one and I have a little bit more than hard the repositories so that's why my latest one is not showing up here you can see it showed up because I searched for it and I can select it now so Kevin awesome project connect repository and I can now after this basically what what Google will do is it will set up a web hook and also give itself an SSH key so it can clone the project so with now this we can add a trigger so every time now where Google sees a commit get the web hook it will run what we do here and this is by default like normally good enough if you're just starting out this is here you can say like when should run this yeah but by default we just want to run everything whenever everything changed and the interesting part is here the the build configuration so the build configuration is whether we want a dog or fall and or cloud but the cool thing will out build this that we can basically be a little bit progressive in that in that we start out very simple and then we will be more and more advanced and this is super awesome so by default we just go with docker file super simple and we will say like did this in the root it's called docker file and here I will just make the name a little bit shorter so it's a little bit easier to type and see but the first one is mandatory it has to say Kevin awesome project because that is our Google Cloud project ID so we can say create trigger and it also just to mention short sorry will be replaced by eight of the first characters of the our github hash or I should get hub the char get sha so we say create trigger and because we haven't committed we can make the first time you can say run trigger and if it only seized us one branch it would ultimately start the own master so you can click show here and you will see that our build has now started its cloning the repository is building our Duggar image you can click this your show news then you don't need to scroll your basic short news one at the top it's pretty cool and you can see that it actually finished successfully and it's now pushing it to TCR which is Google container registry so this is super cool we are nearly ready to deploy our first cloud run so the its screen is very important to check that and you only took 32 seconds and the majority the time was spent like pulling and pushing so that's not much to our to improve there so let's go to cloud run instead of just clicking let's search for it so here cloud run so this also needs to be enabled and we just save stock using cloud one then it was pretty quick enabled me sometimes this would take one minute to minute but you can see when it is enabled down here then we will click create service and you see a cloud Run has been enabled yeah no normally it takes a few minutes and you can see that it's wide redirect us back crepe service again and you should see a screen where you can select we can now select our container image and right now we only have one and you can click here and say this one and this is actually a unique char off the image and this is our github a not akihabara get char this is just the continuous yeah yeah and some teachers but this is if you are looking for something you already seen so here we can select and I am in Europe so I want to close me and we have to say allow of indicated on earth indicate indications and this is because you can both use cloud run for a inter services like micro services to micro services but if you want to allow users that just use a web browser it has to be unauthenticated because by default their requests will just come by them typing in the you are so that is all we need and we can just say create so this is super awesome now we're basically using cloud run yeah and cloud run is actually a super cool project it's a project that's built on top of a lot of open source project and so in fact you if you want to deploy it yourself you could do that yeah so while this wait this builds it takes around a couple of minutes I will just explain you a little bit about cloud run a cloud run is a it's a it's a basically the hosted version of a open source project called kami T and K native is a project that runs on top sto and Easter is a service mesh hub swish and that runs on top of who believes em it's pretty amazing because this open-source software means that you can actually deploy key needs if yourself you wanted to and actually get the same experience but of course it's not as easy to apply all this software so that's why I like Google is helping you by doing it for you but the cool thing is like you're not locked in if you wanted you could deploy the this if you want and not like other service projects where you're basically locked into the platform because you have no way of like taking it and deploying the same software yourself but you can see now it's actually deployed it's green and we can now click this URL and see if it works so it says hello awesome and that's just perfect because we are now running our container and we can refresh and see it again and to check out some of the details about like cloud run we can go to logs for example and see that our container were actually have like started and now our new continuous and even more cool is like this cloud run it's actually all built on top of the stack driver and all this done stuff so if you click here you would actually go to stack driver the whole locking viewer and and the same here with the metrics is from stack driver and there will be available once you have a little more more traffic so this is super cool so now we have continuous integration with loud thud but we haven't combined those projects now so what we need to do is now we need to make cloud built also mentally it reply when they won't make a change so that's a few things we need to do first off we need to go and change our cloud belt to use cloud built a demo so let's go back here under triggers we're going to change our trigger and over here we can say edit then we can scroll down and change build confirmation stuff dagger file we're going to choose a cloud build so this cloud build is basically our own steps that we want to define a for what steps you want to run so that's a few steps you want to one we want to take darker builds and we want to say docker push this is exactly the same that we just have over here but we need to define it because we need to define a first step which is a g-cloud beat to run deploy so we can save this and it doesn't change anything now just listens on cloud filter demo then we can go to our github project a police first like search for a cloud build the Gamo because that helps us because we can just copy the llamo a little bit here because it helps us keep started a little bit the one that you can take here is this because normally you can write this your hell itself but does not really need to learn this by hand a or two by memory because you would need to do that always so here we basically have a few steps the first step I will just blame like here what we have so we have few steps and the X out build basically contains of many steps and the name and the name is is the name of the container that you want to run your step in because each step is a docker container where you can run some commands inside and the first one here is called cloud builders and docker and cloud builders the reason why you would use those because they're already cached and they can they're very quick to that because they are the over often already there on the machine so we want to run docker and we want to build our container and we want to run the same project in our name which is our pertinent ideas here called Kevin awesome project and let me to see what was our container name you can go in and look for that so we can use the same and it's it was this one here we can copy that and I have called it the same as a project that's really good let me just eat this so it's called Kevin awesome project basis Department and also the ID and we have here we need to define a name that unique wishes would be the short gr so here we can say short char which is something that Google Cloud bill will be placed for us with our 8 characters so this looks collect and then we want to also include another step which is going to talk or push so we're going to change it to push and then push the image to a Google container registry and also delete the center dot at the end oh you cannot see this yeah so here you can see short shot we're basically doing a push in the end so we can commit this file and we will now see that a cloud bill has picked up now again I'm gonna save refresh and we will have a new bill started with our cloud build a yahwah so now we have two steps and it was defined in our own file so you can see a step one is this one and it's building now and step two would be pushing so this is all good and and that went really well it only took 23 seconds even quicker it's amazing and we can now actually try to deploy this container so let's take this image and deploy it from the command line because that's actually what we can do so let's start our terminal here and we're going to basically make cloud bill run the same commands as we are running so we can say T cloud and we're going to say beta run even though it's still general available now you're using vo-tech because there's still some features we need and we can say beta run and you want list you want to see provisions though run services list yes it's always helpful and when they want to show you a little bit what is going on I want to say fully managed and you can see here I just want to see our service name a little bit bigger here our service name and it's called Kevin awesome project so here we want to say just easier to read we want to deploy this new docker image and so we have this image here and we can say T cloud beta run deploy and there's a few arguments we need to deploy first need the name and the name we had a Kevin or some project we can then say here region because I still need to read it to also have the region it can be a little bit annoying because you think you could just guess it but you can I think you can have it you can reply to most of written and that's why it needs to know up front even though you have to find it when you're creative so it's called your best one and we also need to say which platform is because everyone can now run on multiple platforms so we need to say cloud platform equal managed and then late lastly we say image equal the new one so with this command D cloud beat run deploy our yeah service name the region platform and image press enter and we will actually see now that with this command we can deploy a new version of our cloud run easily and we create a new version and is now routing all the new traffic to this one cool so to do continuous deployment we need to take this command and make it run from cloud that easier said that done but let's try to do it let's just copy this command and let's go to github let's go and change our cloud builds let's go and edit here and let's go and paste it in the end here so we have it and let's copy this step we want to add this step here at the end and we want to say g-cloud you can go and actually find this cloud builders if you google it there are in a github project and you can find it they have a few of them but while I'm is T cloud so we can remove the first one here and then we want to add this inside here inside the array so we want to add single quotes around them all and come us because it's actually in an array so betta run deploy and the reason why we're doing this is because of some way to pass it and the bash and so we will basically do this between all of them and also the platform and lastly here the image and we now have our whole string encapsulated so pizza run deploy or fret or project or a suicide e the region the platform manage and image and we need to replace this as the line above with the short sha sha sha and we can commit this so this will actually work it will deploy our service automatically every time these two previous steps has been successful so let's commit this and go to cloud build and see our new build has started so we can see here you will basically we don't need this anymore so it will begin to a poll and build building the docker container pushing but our second step fails so what happened I in kind I already knew that it wouldn't feel because it's a step that is easy to all look so I want to show you what actually happens it says here permission deny the call does not have permissions what that actually mean is because cloudbuilt is trying to run a cloud run commands and it doesn't have access to that by default so by default the cloud run agent doesn't have access to do a lot of stuff inside your project you actually have to give it permission to deploy a cloud run for you this is super good but it's also a little bit complicated it's good because it's keep separating it doesn't give you're not leaking permissions or you actually have control or Hoover access to what and why but normally that would have been long step but they actually improved that so you can go to settings and you can go here to a cloud run and you can say enable it so what this Gus is that it gives the cloud the service account access to cloud run and you can click enable it and you will say here additional step may be required and this is this is not what I decided but on Google cloud you need to grant a service account permissions to also emit like take the role as other service accounts because normally it would be a user that would have the permissions but you can grant it access that by the sink grant and what we can do is then go back retry it and you should see it it actually working so this should work and it will work but let's just do some fun and make a little bit Krieger let's go and say here sir would yes go and edit this and we can say hello awesome now with continued deployment just so we could see we actually made a change commit this far we can go to cloud build and see it would actually also build this one both of them has started and let's see how long this will take we are building building we are pushing now and we are now deploying deploying container and this also depends on how big your container is the smaller this the Kreuger is to supply a container I don't know it's pretty small we use the slimmer version but obviously if you have a really large container this take longer and now we can take this URL and see it in our hello all so now we're continuous deployment yeah because this is super awesome like now we can basically go on github it will ultimately test our dog container if it can build and would also me deploy it so we can now share this with anybody you can also go here and like this year-old looks a little bit weird but you can go to cloud build cloud run sorry and then add your own domain so if you click here you can easily add a new domain with just DNS records yeah so this is so awesome like you are basically having the full power of the Google cloud platform at the same time that you're doing something really easily really cool achieve link because this will not cost you anything to run the only paper requests and how long the container runs and you get two million requests for free and three 300,000 say gigabyte seconds so it's small enough for your side projects or even if you're a small start-up so super awesome and this is so important to setup because you're basically saving time and you also allowing yourself to continues to integrate it continues testing it and continues to plowing it and getting it out to customers so that was just all I want to show you I hope you will ask comments if you have any questions ask in the comments or send me an email I will be sure to answer everyone so thank you all and that was basically hey how could they
Info
Channel: Kevin Simper
Views: 17,323
Rating: undefined out of 5
Keywords: google cloud, cloud run, cloud build, continuous deployment, github, deploy
Id: GhSAQ19f4HA
Channel Id: undefined
Length: 34min 23sec (2063 seconds)
Published: Thu Nov 21 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.