04 | Dedicated Server using Docker & Unreal Containers

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so we've got our dedicated server all built locally and working the next step is to basically put this into a form factor of what is known as a docker image and this will allow us to run that image in kubernetes in google cloud once we have all of our deployment stages set up now just a heads up you're going to need quite a bit of disk space and a bit of time and some patience thrown in there because it can take a while to build these docker images the docker images themselves can be built using a cli tool a lot of this work is all built from a person called adam wren who's basically put all this stuff together and figured out how to build docker images with unreal engine now if you look at some of the supported host configurations that uh is in the extensive documentation that um adam runs put together you'll notice a few sort of uh optima optimality um sort of descriptions around what operating systems work best when building these images for our example we're going to be using linux as the host os even though we're running windows right now what we're going to do is actually install the windows subsystem for linux this will allow us to run ubuntu on our local machine which will allow us to then basically have linux available to us when building these docker images so the steps are we have to install the windows subsystem for linux basically get ubuntu up and running locally the next step after that would be to install uh docker for windows which then works with the windows subsystem for linux and then after that we can then use the cli tool uh ue4 dash docker that adam ren's put together that'll allow us to build these docker images so that we have them locally this part is the the part that takes the longest takes a while to build the images and it takes quite a bit of disk space as you can see a minimum of 300 gigabyte of available disk space will be needed in order to build these images all right so i'm just going to quickly run through the windows subsystem for linux installation guide it's a good guide it doesn't take long but ultimately we need this installed so that we can get ubuntu running on our windows machine locally so we're going to go through the manual steps because they're quite straightforward it's pretty much a few copy and paste commands and then we'll be up and running we're going to be running wsl2 the latest version what you need to do to get going is literally get to windows powershell and run as administrator and then ultimately you can copy and paste the first command to enable wsl copy and paste this will enable a feature you can check the requirements i'm presuming that you are on windows 10 as you're working through these videos but it's worth just checking the docs around this just to make sure that you're all good to go to be able to run wsl 2 enable the virtual machine feature again a simple copy and paste and then we move down to downloading the linux kernel update package uh so you just need to download that so small install and away you go and then set the default version for wsl to be version two the last thing you need to do is then go through and pick from the microsoft store itself the linux os that you wish to to run in our case we're going to be using ubuntu so search for ubuntu and get that installed you'll then get a desktop shortcut which i've pinned mine down to the bottom taskbar down here uh just for ease of use and we're going to be using it quite a lot so you might want to pin that and that's basically getting windows subsystem on from running you should end up with a result like this when you run ubuntu your own pendup and you get your home directory uh and basically you can then start running all of your different linux commands okay next up on the list to install is docker for windows it's a simple installer it's a single executable you can just run it'll install everything you need and you'll be ready to go for all the documentation that i'm going through in regards to installation instructions i'll be putting that in the description below just for ease of use and quick links but uh all you gotta do is simply download run the installer and then ultimately because i've already got it installed you'll end up with docker desktop which will start up and in your bottom right of your taskbar it will start the docker engine for you in windows one thing to just uh make sure you enable or selected when you are installing is just to make sure that in your settings tab for general that you use the wsl2 based engine to provide better performance uh when running docker for windows okay now it's time to do the uh sort of final steps and basically get the cli that allows us to build these docker images installed into ubuntu so the first thing we're going to want to do is obviously ensure that docker for windows is running which it should be after your install uh the next thing will be to start up ubuntu so click your shortcut and get it up and running and then ultimately there's a quick guide once again a really good um guide from adam wren on this stuff and basically you just need to copy and paste these commands we're basically running ubuntu so the specific instructions for this on configuring linux but ultimately you can do the old copy and paste put in the relevant password i've already got those installed and then there's basically a python pip package that you can then uh install as well so if we do that head back to ubuntu copy and paste and basically we're saying that we're already there and then once you've done that you can then run the setup command and away we go all we need to do is run ue4 docker space build and then the unreal engine version we wish to build so basically go to ubuntu and run in ue4-docker and we're going to be building the version which we specified in our previous videos as 4.26.2 now i would recommend maybe doing this overnight or in a time where you do not need your machine for a while when i did this on the original execution of it it took roughly i think around about two hours on this pc i think it can probably take two to four depending on your specs but ultimately once you run this you then need to provide git credentials that will be used to clone the ue4 repo now you can use the account that we created in the previous videos when we were getting set up with github and actually pulling the unreal engine from source in the very first video so for me it's trashart-demo and then i put my password and then ultimately if all is well and good you should see it basically get to this point and clone the repository successfully leave that for however many hours it takes to build these images and then we can jump back into the video and actually then start packaging up our dedicated server using the docker images now been built okay so the docker images are now built and now we're ready to use them to actually now build our dedicated server using a docker image rather than our local windows environment so the first thing we're going to need to do is basically go into our project file and what we're going to do is create a docker file a dockerfile basically is a file that states how you wish to build your image and basically you put in in essence commands or a little bit of syntax configuration that then docker will understand and then build that image for you so to do this we're going to basically first off create a docker file that's going to build the the dedicated server for linux so let me open up visual studio and what we're going to do in the root of our project for the unreal game itself so versus game unreal so we're going to create a couple of new files we'll create a an empty text document we're just going to call this for now docker file dot server and we'll say yes we want to change it not to worry about that extension and then the other file we're going to need and you can think of this file that we're going to create as similar to the dot git ignore a dot docker ignore ensures that when it builds its context when you build the image it doesn't include files that it doesn't need to know about so let's create that file as well dot docker ignore awesome i'm just going to regenerate the visual studio project files just so that the solution then can see them it'll ask us to reload the solution once this happens and we'll just do reload all and now we can see that we have a dockerfile.server and a docker ignore with a tongue twister um so ultimately now we can add in the relevant uh configuration again just to save a bit of time and rather than you have to watch me type i've got an example of one that i created earlier again i'll put a link in the description but ultimately this is literally just listing out files extensions and folders that should not be included in the docker context in our dockerfile.server what we're going to do is basically take the other examples i've pre-made and we can go through it line by line just to sort of understand what's going on so once you've built your docker images you've got a list of them here if you just search for adam in here you'll bring up the list of them the ue full image is what we're going to be using to basically build our project and ultimately we have that here and we denote the tag that we want to use which you can see here which is the unreal engine version of 4.26.2 and this is a multi-stage build dockerfile which i won't go too much detail but ultimately we're saying we're going to use this image as the builder and we're going to copy the dot which is basically stands for the current directory all of its files into a folder within the docker container of slash tmp slash project and obviously this command here will basically set the permissions to be the ue4 user that's part of this docker image once it's copied those files it will then set the working directory to the temp project folder as this is where we want to sort of run our ue4 package commands now the next one we see is run which basically is just running a command and you'll notice it's using a cli tool called ue4 and then the next um argument is package and then we're saying what target and we're denoting that it wants to be a server build and no client so what that uf e4 cli relates to is basically within the container it has already installed for us the ue4 cli and it is using the package command from this cli there's some documentation around this uh on the adam ren docs that can go through more detail what you can pass through to it but for this example we're basically wanting to build a development server for now so that we can have logging and all the other goodness so that we can debug if there's any problems what then happens is that we're basically saying we want to use this image after it's built the and package the development server think of this as basically doing that command as if we were in the ue4 project and going file package project you know and then win64 in this case we're just doing it via a command line this image is a publicly accessible one and it's worth noting that these build images that you've created for uue4 cannot be published to a public docker registry the licensing agreement does not allow that there is some documents on the website for unrealcontainers.com that specify they are talking about potentially making it uh possible to authenticate to a private registry and to pull these images which would save you having to build these images and like spend hours doing so which would be absolutely awesome but for now uh that's not possible so you had to go through that step to build those images um the ue4 runtime image if we go to that is hosted on the standard docker hub if i can get to it so this is a pre-built image that provides a minimal configured environment for you to be able to run your unreal engine project which is what we want and basically this command underneath specifies we want to copy from builder which we've denoted up here from that container we want to basically copy the linux server that was built into this temp project folder and it ended up in dist linux server to a new folder within this container image of home ue4 project the expose argument down here basically allows us to expose ports so obviously we want to connect from our client game clients to this server via that port and so we need to expose those and we'll need to run and publish those ports which is a different thing when we run the container image and then the entry point is basically saying which file when you do a docker run and you start this container what should i basically start from what should i execute to sort of run um as it boots up the container in this case there's a vs server.sh file that is created for us as part of this package process and we're adding the dash log like we've done before when we did the shortcut on windows in our previous video to then allow the logs to be displayed now we have our docker ignore file and our dockerfile.server we can now test this by bringing up ubuntu heading to our unreal guide versus game unreal directory so in the root of our project and then basically type docker build and we're going to basically point it to the file of the docker file dot server and we're going to tag it as vs server test and dot to give it the context of the current directory i should think about it for a little while and basically then run it it runs a bit quicker on mine because i've got cache layers for this uh but ultimately that's now built our dedicated server as a docker image and you should be able to see that if you go to docker for windows i'm going to take that away you should see that we've got vs server dash test and that is the image we have built ultimately now what we can do is now run that so if i do docker run and i give it the tag name v vs server test what i should see is uh unreal dedicated server up and running as it was before but rather than it running in windows it's now running using docker in linux as a built linux dedicated server now we have our working docker image that builds our linux dedicated server and can run that dedicated server within docker the next thing we're going to do is test our game clients functionality just to make sure that it can connect to our dedicated server that now runs in docker rather than our local windows dedicated server i'm going to bring up the unreal project and we've made no changes to this from our previous videos we're still in the play mode of number of players of one and the net mode play standalone we'll bring up ubuntu and basically what we're going to do is start up our server so we need to do docker run we need to publish the port so that we can then connect to our container once it's running so we know that unreal runs on 7777 so the first is the port of the host and then to the container and we're going to say the protocol is udp by putting forward slash udp and the tag t that we built was called vs server dash test so we'll hit that and you can see our game server is now up and running we'll go back to unreal engine and hit play and we'll do what we've done before where we'll basically hit the tilde key hit open as the command and we'll connect to localhost and you'll notice it flickered and for some reason we're not in the server map going to the logs you can notice that ultimately it did try and connect but unfortunately the error was that it did some kind of version mismatch now i've not 100 sure on the answer to this but i'm quietly confident it's basically because i've built the dedicated server using the unreal um engine via linux and there's some network mismatch for some reason i think it's because i've done that building whereas this obviously on our local windows machine is built using the source that we downloaded from github into windows ourselves so they're not the same there is a fix in later videos we'll go through maybe more of a production ready fix but for now i'm just going to go through how we can fix this just so we can move forward with these videos to fix the issue we're going to create a new game instance class to do this we go to c plus plus classes and we're going to add a new c plus class we'll show all classes and we're going to pick game instance as our base class click next and then we're going to name this vs vs game instance from there we'll create the class and in visual studio we'll then need to reload just so that we can see the new file okay now the files have been created we're going to basically go into these files for the vs game instance cbs file i've got one that i prepared earlier just so that you don't have to watch my bad typing and what we're doing here is including the miscellaneous network version header file and then we're basically doing an implementation of a virtual function that exists on the game instance class uh called init and within here we're basically saying here's a directive to say when we're not in shipping mode on the build target which we're not when we're building because we're currently doing development we basically say on the is network compatible override buying this lambda to always return true so we don't care whether they are a mismatch uh just just basically allow it the next thing we'll do is obviously add this to the header file so we need to create a decoration for that we've added that into the header file now and that should build successfully so if we rebuild we should see everything works as expected now we've created our game instance class we now need to tell unreal engine in our project sends to use this new game instance class rather than the default one so if we jump over to the unreal project now and go edit project settings we should be able to search in the details field for game instance you'll notice that we have a game instance property section here that we can just switch out to use vs game instance we'll save that and close and we'll do this to compile and everything's all well and good currently we have our dedicators server running in docker so we're just going to need to stop that server just now so if we go into docker for windows and go to container slash apps we should be able to find a green box on one of these which is the running running image so we're going to stop that and it'll take a couple of seconds and we should finally get our terminal back there we go and then what we need to do is just rebuild the container and we can use the same command as we did previously to do that so if we just search for the docker build command and name it the same this will just take a moment to run through okay so our docker image is now rebuilt we can run it again so if we just do docker run and we publish the port once again and set the tag now we'll start up our server that's been rebuilt we can go back to the unreal project and we should be able to now hopefully test to see whether we can connect to the server so we're in our client map still and we're going to use the tilde key once again open up the connection to the server and there we go you can now see we're connected to the server map once again that wraps up this video of creating your linux dedicated server and running it via docker using docker images from the unreal containers project all credit to adam rent and all the excellent work that's been done thus far around that stuff in future videos we're going to talk about how we can now deploy this docker image and also use it for continuous integration with github actions so stay tuned for that
Info
Channel: trashart
Views: 1,772
Rating: undefined out of 5
Keywords: unreal engine, dedicated server, unreal, unreal engine 4, docker, server, game servers, dedicated, game engine, scaling multiplayer game servers with kubernetes, kubernetes game server, server backends, unreal fest europe, engine, multiplayer server, udp server, kubernetes, agones, ci, cd
Id: tvNIJfigDlY
Channel Id: undefined
Length: 21min 55sec (1315 seconds)
Published: Tue May 04 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.