How To Create And Use Github Packages For Docker Containers

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi i'm adam kolp and you're at beachcast i'm going to show you how to create and use github packages so stick around and we'll get on that [Music] welcome back if you've used docker or any other type of containerized service one of the things you may have grown accustomed to is being able to include an image in your containers dynamically and that it is just as simple as doing a docker run or docker up and telling it where to find an image to pull in to make creation of the container much simpler now docker made this very easy with docker hub where you were able to store images on docker hub and then when you called them or when they were called directly from within a command to create a container docker would automatically go to docker hub to see if that package exists or that image existed now there's a new player in that space and that is github now github also has github packages and using github packages you can function much the same as you did still using docker you just have to change the address slightly as you're including the package so let me show you how we get that done the first thing that we need to do is create a personal access token i'd like to take a moment to introduce the sponsor for this video cloudways cloudways allows you to focus on your business and avoid web hosting hassles go live in minutes by selecting your application selecting the vendor your server should be housed with then select the server size for your chosing provider and you're ready please use the affiliate link in the description below to support the beachcast channel and to claim your one month of free hosting the discount code beachcasts will be automatically applied to your signup so on github if i go to my in the menu if i go to my settings and from my settings if i scroll down and look for the item developer settings click there you'll see that there's personal access tokens as a third item in that list now i have a few different personal access tokens here because i like creating a different token for every use case one for command line one for phpstorm one for pycharm whatever the case might be so you want to create a personal access token for use with github packages now you'll notice i already have one in the list here for package management but for the sake of this video i'm going to go ahead and create another one so i'm going to generate new token then we come to the new personal access token screen now you'll want to add in some sort of title here and so i'm going to go ahead and put a title of temporary package management and you also want to set in an expiration date now i recommend that you set an expiration date of about 90 days you can go shorter or longer as the case might be but i would recommend that you you know keep it relatively simple um i can you can see here that the token by default expires in 30 days that's probably not a bad idea um the next thing that we want to do is we want to set in the permissions that are going to be needed for packages so if i go down to this section we see that there is write packages and read packages now because i want to use this access token to create packages i do want to be able to write packages read packages is selected as an add-on to write packages and then i'm going to go ahead and select delete packages as well because i want to give this access token complete control over you know the the package creation process and then i would generate the token so click and generate token then it's going to give you the access token in this case it's right here now i'm not going to keep this i'm going to delete it before this video is published so just know that it's not going to be there so so with that i can click this icon and copy it and then use that in my in my command line as i'm going to show you in a minute so back at the command line i want to uh add this to my current uh environment so that way i can issue commands so and how i would do that is i would type at the command line export and then do cr underscore p-a-t equals and then i would paste in that token so in this case i would paste in the token that i received from the interface and it would add it into my environment so that way i can use the command now with that added into my environment then i could do something like echo and then see cr pat and then i'm going to pipe that to docker login and ghcr for the container repositories and then i could put in user adam kulp and then put in password and put s standard in now hitting enter on this would use the password that i just exported into my environment and it would do the login and docker and then it would answer back and tell me that the login was successful so that's what you'll want to do on your setup as well and i'll make sure to include all this in the description so that way you can do it on your end so with the permissions added into your environment the next thing you want to do is navigate to the location where you have your image files created now i've got that here on my screen if i look in this directory i can see that i have the docker file i have my license my readme.md and then i've got some other files as well that coincide with this specific image so now that i'm in that directory i want to build this image so then i can send it to the packages repository so i'm going to issue the command docker build hyphen t and i'm going to put in ghcr.io now that's the address that's going to be used as we pulled that package for use with docker and put slash and i'll put adam kulp is my namespace and then this app is php hyphen code hyphen quality and i'm gonna attack on an extra little bit of the name and just put temp on it because i'm basically creating this this package but i've already created a package for this repository before so i want to have a new one with a different name so because i can have multiple packages so i'm going to go ahead and create that as hyphen temp and we're going to say it's latest and put the dot because i want it to build i want docker to build an image using the current working directory so i'm going to go ahead and click enter on that now docker is going to use the files in the current directory and create a new image to put into docker desktop in my case okay so docker has finished setting that up if i bring up docker desktop we can see here that i do have that image right here the images starts out ghcr.io atom cult namespace and then php hyphen code hyphen quality hyphen temp so that image has been created with the image created the next thing that remains then is to push the package to github packages so for that i'm going to issue the command docker push and ghcr dot io atom called namespace and php hyphen code hyphen quality and we'll do temp and then we'll tell it latest and now it's going to push that image that docker image that i just created is going to push it to github packages so it's preparing to push and it's getting everything set to send it up so if i go to my packages here on github we can see that i now have a new package php hyphen code hyphen quality hyphen temp and it's showing as private because by default packages are created private and if you want them to be available public then you would need to go into the package and set it up to be public so people can see it publicly from within the package if i click into the package we can see first it is it is private uh we can also see that there are additional package settings here uh we can see also the poll command is available here and it's telling you docker pool ghcr dot io slash atom called slash php code quality temp and the latest and that's the command that you would use from docker to pull that package if i go into the package settings we can see that there are actions you so you can add rep add a repository to this package now i'm not going to do that because i've already got a different package associated with that repository so i'm not going to do that but it is relatively easy to click this link and associate it with a repository and then you can also add a repository using codespaces i can involve invite additional team members now one thing that i do recommend as well is once you have this linked up to a repository you can there will also be a box here for uh managing access there'll be a check box for linking it up to the same permissions as the repository and that's once you've linked it up to a github repository and i'd recommend doing that so that way when you any accesses that you have for your github repository just carry over to the package and we can also change visibility here and this is where we would change it from being private to being public and making it available for others to be able to pull the package additionally from within the package if i wanted to add a readme here i can do that and that is you can do that after connecting a repository when i connect the repository here then the readme will automatically be pulled in so folks would be able to see okay that package now here is how i can use that as an example if i go back to my packages and go to php code quality this one is public and if we scroll down you can see the readme is available here so folks can see how to use this package and we can see that all the all the other bits and pieces including collaborators are here open images and everything because now it is associated with my github repository of the same name now there is a site with good documentation on github packages and i'd recommend you to check that out it's it's pretty full featured includes a lot of information about github packages a lot of documentation and how to's one of those is how to create a github action to keep it updated by default even if you associate the package with a github repo it's not automatically going to update as you're pushing new changes to that github repo instead they recommend that you create a github action to then update the github package i'll show you how i did mine so if i go into php hyphen code quality the repo and i click into my actions we can see that i do have an action here called create and publish docker image and you can see that i have some previous runs here where it was updating um the github packages by clicking into the docker publish yml we can see that it's pretty simple it's just on uh on a push request on branch master and then on pull request to branch master same thing it's uh telling the environment which is the github packages uh the registry and then it's giving it the name and it's also you know telling it how to build so we're doing uh we're saying to use ubuntu latest we're telling it to check out the code and then we're also telling it you know where to put the code you can also find an example in the documentation which is what i used i just copied and pasted it and made some changes for my own repositories but for the most part it's pretty cut and dry and easy to create the github action that will then update the repository anytime a push request is done or a pull request which has been approved is done on the github repo thank you so much for watching i hope you found this useful and i hope you it helped you get started in github packages this was the first one that i've done so i decided to create this video so i can come back to it if i need to and also to help you get started with github packages if you have any questions please leave in the comments down below if you found this video helpful please leave a like hit the thumbs up button so that way other folks can find this video on youtube as well i really appreciate the help above all be good to yourself and others and i'll see you next time
Info
Channel: Beachcasts Programming Videos
Views: 20,926
Rating: undefined out of 5
Keywords: how to create and use github packages, github package registry tutorial, github package registry, github packages, github actions, docker image repository, docker container image, container package repository, docker tutorial, docker container tutorial, github packages registry, docker images tutorial, github container respository, github tutorial, github container registry, personal access token github, github, github tuturial, programming tutorials, beachcasts, Adam culp
Id: qoMg86QA5P4
Channel Id: undefined
Length: 14min 4sec (844 seconds)
Published: Tue Nov 30 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.