GitHub Actions - Self-hosted runners - Installation & Calling

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
with github actions you can use github hosted runners managed by github to execute your workflows you can also use self-hosted runners which are runners that you maintain on your own infrastructure whether that is a data center or in your own cloud let's look at how you can install and configure these self-hosted runners [Music] hey y'all i'm mickey gousei and today we are looking at how to install github action self-hosted runners and how to use labels to trigger workflows on those runners self-hosted runners are vms or containers that you maintain including the software installed on them and the operating system for users that need access to internal resources or have restrictions on external access self-hosted runners provide a way to utilize github actions when you install a self-hosted runner you can install it at three levels the enterprise runners installed at the enterprise level can be assigned to all organizations or to a specific organization the organization runners installed at the organization level can be assigned to all repos or just specific repos and finally the repository runners installed at the repository level can only be used by that repository to identify runners you apply one or more labels to utilize a runner in the runs on command in the workflow file you list one or more labels github actions will then look for a free runner that matches your labels and trigger the workflow now let's look at how we can install a self-hosted runner and trigger a workflow on it using a label to get started installing a self-hosted runner the first thing we have to decide is where we want to install the runner we can install it at the enterprise level at the organization level or in a specific repository for this example i'm going to install it at the organization level though you'll follow similar steps regardless of where you're installing it so if i go to settings and i go under actions and i select runners this is where i could see any runners that i have installed at the organization level or any runners that were installed at the enterprise level that this organization was giving access to i don't see any runners so i will click new runner and this is now going to walk me step by step through setting up a new self-hosted runner you can see i've got three a potential runner images depending on whether i'm using a mac os linux or windows machine to install the runner on so i'm going to go with linux and i'm going to choose x64 architecture because that's what i'm using you can see it gives me step by step what i need to do to make this runner work on my vm so the first step is we need to go to the vm and we need to create a folder to put the files in so here i am i'm using wsl 2 and i'm going to this is these are all the same vms just you know three different panes and so i'm going to create a folder called actionsrunner and i'm going to cd into it and you can see obviously i just created this so there's nothing in there and then it says download the latest runner package so this is going to go out and grab the latest runner from the actions runner releases which is a public repo that you can go out and see and it's just going to curl it down there's probably a variety of other ways i could have pulled that runner down i could have you know just downloaded it straight from the website and copied it over but this works just fine and remember the runners are going to be smart so once i get it installed it will update itself automatically as new releases come out so if we take a quick look we can see we have that tar gz file with the runner so optionally we can validate it to make sure that the everything's valid in the file it looks okay so let's extract it and once it's extracted you can see we have a variety of different files that were um and folders that were created we've got this bin folder that was created for us and then we have these three shell scripts config environment and run.sh the config and the run are going to be the shell scripts that we're really going to be concerned with now we need to actually configure the runner so that's where we use this step where we're going to run config.sh we're going to point it to our org and it gives us a short-lived token to use to set the runner up this token doesn't last very long if you wait around too long on this page then the token will expire and you'll have to regenerate the page to get it to get a new token so let's copy this and let's run config.sh and see what happens oh ascii art so i'm asked to provide a name for the runner or for the runner group sorry so the first thing it asks me is what runner group do i want to add this runner to so you can group your runners into runner groups by default it's going to add it to a group called default and i haven't created any other runner groups that's another video so we'll just hit return to add it to the default group next what do i want to name this runner so we will just call this my github runner one now runners can have labels and labels are how you're going to target your workflow files to access those self-hosted runners by default your runner is going to get a label called self dash hosted a label with the operating system and a label with the the the framework so linux x64 self-hosted but you can add other labels if you want to and you can add them now or you could add them late later so just because we can let's add a couple of labels here we'll call this label1 and we'll call it label 2. now the work folder is where it's going to download when you know when it downloads the actions that it's going to run or when it checks out files that's where it's going to do all of its work so i usually just take the default underscore work and there you go if we now take a quick look we can now see that we've got some dot credential files that weren't there before we've got a dialog an underscore um not dialog and underscore diag for for being able to diagnose things in fact if we look in there you can see we've even got a log that's tracking in this case our initial installation of the runner now at this point we have the runner installed however if we come back out here let's open this in a new tab you're going to see it's currently showing is offline because we've installed it but it's not actually running so to start the runner if we want to start it manually we can just run the shell script run.sh and this will start up the runner connect it to github and now it will be listening for jobs you can also set this up to run as a service if you look there's a service.sh shell script you can use the service dot sh shell script to install this as a service so that it would start every time the machine starts back up for demo purposes and for sometimes when i want to troubleshoot i usually just run it manually because then i get a little bit more interaction and i can kind of see what's happening you know if it picks up the job etc and right now you can see it is listening for jobs and if we come back over here and refresh this page then under runners you can see there's our gh runner one with the labels that we gave it it's in the default running group and it's currently set to idle so let's go see if we can trigger something to execute on this runner so i'm going to go to my oh one other thing i meant to show you which is important let's go back up to the organization level and we go to settings and let's look at the runner groups by default the default runner group has access as is giving any runners in that group access to any of the repositories but they have to be internal or private they can't be public because that's not checked so by being in the default group i'm allowing any repository any private repository in my org to access that runner but i could also apply it to just select repositories as well i just want to show you why that runner can be accessed from my repository it's because it's in this default group and the default group allows runners or reposit any repository to access runners in the default group the way it's currently configured so let's go to this workflows private which is a private repo and i've got a simple workflow that i've previously created and this workflow is triggered manually and i am telling it to run on a machine with a label of self-hosted now i've only got one machine with a label of self-hosted um but if i had multiple machines with a label of self-hosted it would just pick one at random that was available to it i could also provide multiple labels so i could say i want a machine that has a label of self-hosted and also a labe a label of label dash one so you're able to use the labels to drill down to the specific machines that you want and then you can see that this code is just going to check out my repo which there's really nothing there it's going to do some echo outs and do a short 15 second sleep i see added runs on label one so let's commit the change that we made and if we go to actions and we choose our workflow and we run it if we watch right now it says listening for look running job build so we can see as each job in this case i've only got one but we can see is each each job gets picked up and we can come back over here and we can see that our workflow is running as we expect so that's the 15 second wait and then it finishes running shows completed successfully here and if we go back over to the runner we can see that the job completed successfully with the results exceeded so we have now successfully triggered a workflow to run on our self-hosted runner now just to tease a little bit if i look at in my actions runner folder you can see that i've got two folders the underscore diag for diagnostics and the underscore work which is where we said it was going to check out and do um all the code and that's where it does you know the actual work force and if we do a quick little tease if we look at what's in the diag folder let's do it this way then you can see that we have logs related to the runner and this worker log which is a log that is related to the specific workflow run that just happened and if we do a quick little look in the underscore work folder we have lots of things in there pipeline mapping actions and our workflows private repo where we checked out the code i hope you've enjoyed this video on how to install and use a github actions self-hosted runner if so please comment and like this video subscribe to my channel and smash that bell to be notified of my next video thanks for watching
Info
Channel: Mickey Gousset
Views: 27,056
Rating: undefined out of 5
Keywords: github, github actions, runners, pipelines, ci, cd, ci/cd
Id: SASoUr9X0QA
Channel Id: undefined
Length: 14min 55sec (895 seconds)
Published: Tue Mar 08 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.