 Hey everyone, this is Grant your friendly neighborhood OpenShift team member in today's video I'm going to show you how to create a custom stack on Red Hat code ready workspaces The first thing we want to do is head over to our OpenShift container platform and authenticate Now I am running OpenShift container platform version 3.11, which I installed on a bare metal machine with 16 cores 32 threads and 128 gigs of memory and because I have the amount of resources available that I do I want to use code ready workspaces in a fashion that will allow me to have an 8 gig development machine For my daily development. So if I click over Onto the code ready workspace and if you need to install code ready workspaces I have another video to where I show you how to do that You can see I have two workspaces running right now and code ready workspaces itself consumes three pods One is the web UI for code ready workspaces The second is key cloak which handles authentication and authorization for the platform and then third we have a Postgres database So let's go ahead and access the web UI for code ready workspaces And we can see that I have one workspace running now if you recall from the web console There's actually two workspaces running. So what why is only one showing up? Well, that's because my particular user G ship Lee is using a workspace and then another user on tech dope.io Is also consuming a chair workspace right now So if we look at this workspace, we can see that it is consuming eight gigs of memory And if we drill down into it and click it We can get some more information about it. We can see we have one project running we have an 8 gig Java machine running and Inside of that Java stack is I've installed a few things such as the OC client tool the odo client tool and the Z show So if we go ahead and look at this workspace We can see what it looks like and then I'll walk you through the process of how to create it So it's loading my workspace up now and this is my application I'm working on and if I open up a terminal the first thing you'll notice is I have Z shell available to me Which is the shell that I like to use if I do OC who am I I have OC installed and if I do odo I have odo installed as well So let's see how we actually created this stack if I look at my workspace Dashboard that allow me to see all of my workspaces and I click on stacks That's what we would actually want to create here You can see what I have highlighted is the custom stack that I created and it's the JDK stack with open shift Which is what I called it as two components odo and OC So if we click on that we can see some more information about it I gave it a description. We can see that's using the JDK 8 gig machine Which I created and I also created two custom commands odo push and package which will run a maven clean package If we look at the recipe we can see that it's using docker.io Slash g shipley slash stacks dot java So let's go ahead and take a look at the stack that I inherited from Which is this java 1 8 stack that ships with code ready workspaces If we go down and show the recipe This will show us the docker image That the built-in Java 1 8 stack is using registry dot access dot red hat dot com code ready workspaces slash stacks dot java So if we go over to our command line I created a directory called my stack And inside of that directory is a docker file that I created So if I look at that docker file, I just want to run through what I did to create this custom stack The first thing I did is I inherited from that stacks dot java image And if you recall I got this stacks dot java from the web console If I again look at the java 1 8 Default stack that comes installed. This is where I got that information from So if we go back to our docker file The next thing I say is I want to run as the root user And then I want to run a docker command and in this command I'm going to download the open shift client tools for the version of open shift container platform that I'm using which is 311 And then I want to move that client tool Into my user bin oc directory and then chmod it so that it's executable I then do the same thing for odo. I curl the odo install script and then I run it with the bash command Now this is where it gets a little bit tricky because with the base image It's not actually subscribed to the red hat enterprise linux repositories So what I wanted to do is actually subscribe and add the sentos 7 Repository for my image So to do that I just echo out a repo file And it's in this line right here and I save it to etsy young dot repos dot d sentos repo And once that repo has been installed I just cat it out to make sure that it was written correctly Then I can yum install z shell then I can set my z shell theme to agnostic And then I can install oh my zsh as well. Okay. So once I have this Docker file I can run a docker build. So let me find the command for that Docker build And we can see that that build ran successfully Here's the command docker build dash dash tag And I'm going to tag it gshiply stacks dot java dot dash latest or colon latest And we can see that all of that ran successfully Now I want to push this up to my Docker repo So I do docker push gshiply stacks dot java And that's going to push it up to docker.io And this will be the url for my image. So I'm going to copy that All right. Once that push was completed, let's go back in and clean our docker file up just a little bit Come on vi the docker file again, and there's a couple things I want to cover here The first one is this cat command that I'm running now I was just using this during testing to make sure that I was adding the repo correctly So we can go ahead and delete that we don't need that and then also The environment variable for setting the zhs thing the problem with this and this is why I Illustrated it as you notice that up here I specified I'm running the user as root When we're actually running this container that will not work And that's because I'm running the jboss user is part of the default stack that I'm running here So we'll go ahead and delete that line as well And then we can go ahead and save this and we can go ahead and run a docker build again Just like we did before And we can see that it's installing the zsh package from our sentos repo And it was having a few issues connecting to github, but it seems like it solved the problem And then it installed the oh my zsh So let's go ahead and push this up to our Docker registry and this will take just a second And then once this is done We'll actually go back to code ready workspaces and we'll create a new stack Based on this docker image that we created All right, so let's head back over to code ready workspaces And if you click on stacks, you can look at all the available stacks that you have What we want to do is actually click on add stack And then we'll click on the docker image and we want to paste in The image name that we use So let's find it here. It is right here docker io stacks Dash javas. Let's go back to code ready workspaces paste that in remove the Brackets there and click on okay This is where we can define define some data about our stacks. So let's just cost call this java odo stack Okay, and we can give it a description Java stack with odio and oc with the zshell. Okay And we can also create a new machine So let's go ahead and click on new machine there and it's going to use the stacks dot java image as the base Let's set this to four gigs And then we need to enable several agents that will run. So let's enable the exec Agent and then the java language server Let's add the terminal and then of course the workspace you are Our workspace api that we need as well And we can call this machine We'll call it java four gig and we'll update that So now we have a java four gig machine defined We can also add some environment environment variables. We can add some commands So this is where I added odio push and the maven clean package From the um from earlier in the video. We can also add components now components is just a key value pair To let people who are consuming your stack knows what's in it So we can type in odio here and we can do version dot 20 and again, this is just metadata And then you can add tags. So let's go ahead and save this stack So now we have this new stack if we go back over to our stacks tab We can see that we have the java odio stack here. So let's go ahead and create a workspace Based upon that stack. So if I click on workspace, I want to click on add workspace And let's give this workspace a name. We'll say java four gig We want to use our new stack that we created. So we'll scroll down till we find the java Odo stack. So I'll select that we can see that it's going to be using four gigs of memory And I'm going to click on create and open what this will do is it will actually create a new workspace for me based on the name we gave it And it's going to pull the image down docker.io gshiply stacks dot java So it's pulling that down from the hub dot docker dot i o And then once it's pulled that image, it's going to create a container and then start the container And now it's actually going to pull in all of those workspace agents that we specified when we created the stack Okay, that took just a few seconds to create but here we can see that we are in Our new workspace based off of the custom stack that we created And if we click on the terminal icon, we can type in z shell and we see that we have z shell running We can see that we have oc running just like I showed you Previously and we can see that we have odo running Okay So now let's actually add a Source code repository to this and let's actually make sure that everything's working So let's import a project So i'm going to import it from github. So let me pop over to my github account here and we'll pull in a repo And i'm going to use this pdf rack application that i've been working on So i'm going to copy that and i'm going to paste that url in and you can see that Code ready workspace has already specified the name for me. So let's import that And that's going to clone the repo and then I need to specify that this is a maven based project And i'll just click on save So you can see it's already pulled in the source code there and we can see the source files here And if we look at the pdf rack application We can see it there. So let's go back down to our terminal and the bottom of the screen if I type ls You can see that I now have a pdf rack application So i'll go into that directory and I will just do maven clean package just like I normally would And that's going to download all of the dependencies. So again, this is running in four gigs of memory on my server And this is going to take just a few seconds here as it downloads all of those Dependencies for the first time now the great thing is that they'll be cached from here on out You can see the total time there was 16 seconds So if we run it again, we can see that this project compiled Much faster. It's took 5.8 seconds if we run it again It should even be a little bit faster Okay, so we just have a few other things to clean up here before we end the video The first thing is we want to save our docker file in a repository on github So that if other people want to use it they can do so So i'm just going to create a new repository here and we'll call this chay custom stack And i'm going to create that repository And then i'm going to Copy this get init command go back over to my terminal paste that in And then we're going to get commit java stack And we see we have untracked changes. So The first thing we want to do is actually add that file. So we'll do a get add docker file And then we're going to get commit And then if we go back over to our browser, we can add the remote repo So i'll copy that command go back to our terminal paste that in And then lastly we just need to push these changes Up to github And i will authenticate And now if we go back over to our Get repository, we can see that that docker file has been saved here And again the repo is gshiply slash chay custom stack feel free to fork The docker file to build your own custom stack. That's it for this video. Hope you enjoyed it