Overview
Join Trevor Sullivan as he explores GitHub Codespaces!
Recommended Experience
- None
Related Certification
- None
Related Job Functions
- Software engineers
- Front-end developers
Trevor Sullivan has been a CBT Nuggets trainer since 2020 and has received a variety of AWS certifications. His areas of expertise include Amazon Web Services, Docker, Microsoft Azure, and PowerShell automation.
Intro to GitHub Codespaces
Trevor Sullivan introduces the GitHub Codespaces feature and describes its capabilities.
Knowledge Check
GitHub Codespaces gives you the option to use Microsoft Visual Studio Code or the Atom Editor. True or false?
Enable and Provision GitHub Codespaces
Trevor Sullivan demonstrates how to create a GitHub Organization with the Team or Enterprise pricing tier, create a repository, and provision a GitHub Codespace.
Knowledge Check
Which cloud vendor do virtual machines for GitHub Codespaces run on?
Customize GitHub Codespaces Dev Container
Trevor Sullivan demonstrates how to use devcontainer.json and Dockerfile to customize the GitHub Codespaces environment.
Knowledge Check
Which file would you modify to install software packages into the custom GitHub Codespaces container?
Add User-Specific Customizations to GitHub Codespaces
Trevor Sullivan demonstrates how to apply customizations to GitHub Codespaces that only apply to a specific GitHub user, not the entire team.
Knowledge Check
Which of the following is the first script filename that GitHub Codespaces will look for to apply user-specific customizations?
Add User-Specific Secrets to GitHub Codespaces
Trevor Sullivan demonstrates how to configure user-specific secrets such as API keys to GitHub Codespaces as environment variables.
Knowledge Check
You must specify the individual GitHub repositories that have access to a user-specific secret in GitHub Codespaces. True or false?
Conclusion
I hope this has been informative for you and I would like to thank you for consuming.
View Transcript
Intro to GitHub Codespaces
0:11Hi, guys, my name is Trevor Sullivan,
0:13and welcome to another CBT Nuggets skill.
0:16In this skill, we are going to be continuing our learning
0:19about the GitHub platform.
0:21In particular, we're going to be focusing
0:23on a relatively new feature known as GitHub code spaces.
0:28Now, as of right now, code spaces
0:30is not available for free users of GitHub,
0:34it does require that you either have a GitHub
0:36team or an enterprise plan.
0:38So if you are building a free open source project on GitHub
0:42and this feature isn't currently available to you,
0:45then that's probably the reason why
0:47is that you'll have to upgrade your organization to a paid
0:50plan, so that you can unlock the capability of using
0:54this feature.
0:55But before we get too deep into all the details on it, first
0:58of all, what exactly is code spaces?
1:01Well, as you may know, some years ago, Microsoft actually
1:05purchased GitHub.
1:06And so GitHub is actually now part
1:08of the Microsoft organization.
1:11As you also may know, Microsoft is also
1:14the developer of a utility that is
1:16used very commonly in the software and DevOps industry
1:20around how to edit code, and that
1:23is known as Microsoft Visual Studio code.
1:26So if you head over to code.VisualStudio.com,
1:29this is one of the most popular editors
1:32that's currently available.
1:34And one of the great things about this editor
1:36is that number one, it's cross-platform.
1:39It runs on Windows as well as Mac OS, as well as Linux.
1:44So you can get a consistent development environment
1:46across different operating systems
1:49if you're switching between perhaps a Windows
1:5111 workstation like what I'm on right now over to maybe
1:54a MacBook Pro that's running Mac OS,
1:57you can get that consistent tooling experience
2:00across multiple operating systems.
2:03Now, Visual Studio code itself is actually
2:05built on a generic framework known as the electronic JS
2:10framework.
2:11And this is a cross-platform framework
2:12that's built in JavaScript, that allows application
2:15developers to build cross-platform apps that
2:18have that similar look and feel with a singular code base
2:22rather than having to have three separate code bases depending
2:26on which operating system the user is actually using.
2:30Now, because the Visual Studio code editor
2:32is built on the electron JS APIs, one of the benefits of it
2:37is that because it's JavaScript, it's actually running inside
2:41of a browser environment.
2:42It's actually running, I think, on Chromium
2:44or some kind of derivative of Chromium essentially.
2:47And so what you can actually do is take a Visual Studio
2:51code, which is, again, built on electron JS,
2:54and you can actually run it in a web browser.
2:57In fact, there is a company, I believe
2:59it's coder.com, that originally was actually
3:03working on kind of a web-based port of Visual Studio code.
3:08They were originally working on this project
3:10called code server.
3:12We're not sure if that's still up to date,
3:13it looks like it is.
3:15But this was essentially a project
3:16that allowed you to run Microsoft Visual Studio code
3:19right here in a web browser.
3:21So you can see that they've got a screenshot right here
3:23with Firefox running, and they're actually
3:25running this Visual Studio code interface right inside
3:28of their web browser, instead of having
3:30to install Visual Studio code on their actual dev system.
3:35Now, this has some obvious benefits.
3:37One of those benefits is that if you
3:39are running on an unsupported platform
3:42that Visual Studio code doesn't really run natively on--
3:45think of like Google Chromebook, for example.
3:48So if you're using a Google Chromebook,
3:50and Visual Studio code isn't fully supported
3:52on the Chromebook, I think you can probably
3:54get it running on there.
3:55But if it's not really supported on there,
3:57you can actually just fire it up in your web browser
4:00and use VS Code in the web browser instead.
4:03And so what GitHub has done is because GitHub
4:06is part of Microsoft now, they're
4:08actually taking Visual Studio code,
4:10and they're now hosting it in the web browser.
4:14And they've called it the GitHub code spaces feature.
4:18Now, you can actually use your Visual Studio code editor
4:21natively on your workstation as well.
4:24And then you can actually connect your local VS Code
4:27instance up to a code space that is running
4:29in GitHub in the Microsoft Azure cloud platform
4:32actually behind the scenes.
4:34But you do have that choice.
4:36So you can run it in the browser or you
4:38can run it in the desktop here.
4:39And you can see that when you kind of switch this back
4:42and forth on their marketing page here,
4:44you actually have that consistent user experience.
4:46The only real difference is that when
4:48you're running it in a web browser,
4:50you have the typical address bar.
4:52Whereas, when you're running a desktop application,
4:54you don't have that browser address bar there.
4:57So that just kind of shows how seamless
5:00the experience is between running
5:02VS Code as a native desktop app on your dev system
5:05locally or running it in your web browser.
5:10Now, one of the great things about code spaces in GitHub
5:13is that it gives you the flexibility
5:15to choose how much system resources, how many system
5:18resources you would like to allocate to your development
5:22environment that's hosted up in the cloud.
5:24So you can choose up to 32 CPU cores, or you can--
5:28and you can also choose up to 64 gigabytes of memory.
5:32So you have a lot of flexibility there
5:33in choosing anywhere from two CPU cores all the way
5:37up to 32 CPU cores, depending on how much compute
5:40capacity you actually need.
5:42If you're running some kind of compilation step
5:45in your code that takes a really long time,
5:47then you might want to bump it up to 32 cores,
5:49or if you're just doing some lightweight development
5:52testing, DevOps type of stuff and you're just
5:54kind of playing around, you might
5:56be able to get away with a small two core system.
5:58And there's different pricing tiers available, of course,
6:01depending on how many system resources
6:03you assign to your GitHub code space.
6:06Now, the great thing here as well
6:08is that VS Code running in the browser in code spaces also
6:11integrates with GitHub itself.
6:13So when you create a GitHub repository,
6:16you can very easily create a development environment
6:20that's directly connected to your GitHub repository
6:23with a couple of clicks.
6:25So GitHub will take care of cloning, spinning up
6:28the virtual machine, it'll get VS Code up
6:30and running in your browser, and then it'll
6:32clone your GitHub repository onto the virtual machine that's
6:35actually running your code space.
6:37And then you'll be able to work and edit your code,
6:40and build and test your code inside of that development
6:43environments as long as that code space is running.
6:46So this is a really neat feature.
6:48And as I mentioned before, this is limited to teams
6:51if you're on a paid team plan or the enterprise plan.
6:55So it's not currently available for free plans,
6:57but it wouldn't surprise me if eventually, they
6:59make it open source or not open source,
7:02but available for open source projects rather.
7:06And one of the great things about VS Code
7:07as well is that you have this really rich ecosystem
7:10of extensions.
7:11I mean, there's extensions for pretty much every language out
7:13there, whether you're using Python, or C-sharp,
7:17or PowerShell which I very regularly use in VS Code,
7:20and lots of other languages and frameworks,
7:23just different tooling to help make you a more productive
7:26developer.
7:27So what we're going to be doing in the rest of this skill
7:30is kind of exploring the code spaces
7:32feature and some of the customizations
7:35that you can apply to it.
7:36So we're going to create an empty GitHub repository,
7:38we'll just kind of start out from scratch.
7:40And then we'll add some files to that repository or maybe
7:43just a single file.
7:44Then we'll open it up inside a code spaces
7:46and kind of explore what that environment looks like.
7:50And then how you can actually customize that environment
7:53so every time that you're deploying a code
7:54space into your account, you can actually
7:57customize the different utilities,
7:59the different configuration files
8:00that are on that code space environment,
8:03so that you have a seamless experience across all
8:05the different repositories that you're
8:07working on inside of GitHub.
8:10So as you can see right here, this
8:11is just kind of a table showing the different pricing plans.
8:13We've got anywhere from two cores
8:15with 4 gigabytes of RAM, that's going to be $0.18 per hour.
8:19So you do pay per hour for this particular service
8:23all the way up to $2.88 per hour for a 32 core
8:28and 64 gigabyte of RAM system.
8:31So we're going to go ahead and jump in
8:33to our AWS-- oh, sorry, not AWS, GitHub organization
8:37shortly here.
8:38And then we'll take a look at the billing
8:39for this particular feature and how that works.
8:41And then we will actually start taking a look at the feature
8:44itself.
8:45I hope this has been informative for you
8:47and I'd like to thank you for viewing.
Enable and Provision GitHub Codespaces
0:11Hey guys, and welcome back.
0:13So let's go ahead and jump into the GitHub user interface.
0:15And we'll actually take a look at how
0:17to enable the codespaces feature by setting up
0:21Team or Enterprise billing on your organization,
0:24as well as how to actually create your very first GitHub
0:27codespace.
0:29So what we want to do is navigate over
0:31to the GitHub user interface.
0:33So you can just go to GitHub.com.
0:34You should already have an account and be signed in.
0:37And one of the features that you can just use inside of GitHub
0:41is called an organization.
0:42So if you click on this little plus sign
0:44up here in the top right corner, you
0:46can actually create a brand new organization.
0:49And when you sign up for an organization,
0:52you have a few different pricing options.
0:53So you can do the basic free tier,
0:55where you have public and private repositories.
0:58You have limited 2,000 minutes of free private repository
1:04minutes for GitHub actions.
1:07You also have 500 megabytes of storage for the packages.
1:10But one of the things that you don't get here
1:12is the ability to use codespaces.
1:15And so you'll want to upgrade your organization
1:17to either the Team plan right here or the Enterprise plan.
1:22And you're going to pay for those
1:23plans based on how many users are actually
1:26added to your organization.
1:28So if it's just you, you're just an independent developer,
1:31perhaps, maybe an independent contractor,
1:33and you have your own organization,
1:35then you can get away with paying $4 a month for the Team
1:38plan.
1:38However, you also have to pay for the actual minutes
1:42and hours that you're using of codespaces
1:44on top of that base plan.
1:46So it's not like codespaces is just unlimited
1:48once you pay for $4 a month.
1:50You also have to factor in the additional price of the time
1:53that you're spinning up that codespace environment, which
1:56is actually just running on a virtual machine
1:58behind the scenes up in the Microsoft Azure Cloud platform.
2:02So once you've created your organization,
2:05you should be able to utilize the codespaces feature.
2:08I'm just going to go back because I already have
2:11an organization created here.
2:13So I've got an organization called CBT Trevor.
2:17GitHub.com/cbttrevor.
2:19And if I head over to the People tab here,
2:21I can see that it's just me and Dan Charbonneau,
2:25who's the founder of CBT Nuggets.
2:27And we are the two users, or members,
2:30of this particular organization.
2:33Now if I go over to the Settings section
2:36right here and then drill into Billing and Plans,
2:39you can see what the currently active plan
2:42is on my organization, my CBT Trevor organization.
2:45And so right now the current plan
2:47for that CBT Trevor organization is the GitHub Team plan.
2:52And you can see right here, it shows
2:54me the pricing for the members.
2:56So I have two members.
2:58And that costs $8 per month, of course, $4 for each user.
3:03Now as you scroll down under this Billing section
3:05on the organization, you're going
3:07to see the usage of some of the different billable features
3:10within the platform.
3:12So again, the Team or Enterprise feature
3:15that you get when you register for that level
3:18of a plan in your organization doesn't give you
3:21just unlimited access to all the different features.
3:23You still have to pay per minute for things like GitHub actions.
3:27If you're using GitHub actions to do CI/CD workflows
3:31on your different repositories, then that is going to be extra.
3:35They do include 3,000 minutes with the Team plan.
3:38But if you exceed that, then you are
3:39going to pay additional costs for that.
3:42You also have packages.
3:43And that's basically just package storage
3:45for things like Docker container images
3:47or NPM packages or Python packages, that kind of thing.
3:51And so you get 10 gigabytes included here.
3:54But again, if you exceed that 10 gigs,
3:55you're going to pay for it.
3:57Same thing for storage for both GitHub actions and packages.
4:00That's billed separately from the actual packages
4:03and actions workflows themselves.
4:05But as we scroll down here a little bit more,
4:06you're going to see codespaces as its own little table here.
4:10And you can see that you're actually
4:11billed separately for storage and the compute capacity here.
4:16So of course, you are going to be consuming storage
4:18on your codespace in addition to the virtual CPUs and the memory
4:22that you're allocating to your codespace.
4:24And so that's broken down for you right here.
4:27And you can see that it even breaks down
4:29the different sizes of the compute nodes that are being
4:32used to deploy our codespaces.
4:34So you can see right now, I've exclusively
4:36been using the 2-core, the smallest size, virtual machine
4:40here in order to run my codespaces.
4:42You can see the fractional hours that are being billed.
4:45And you can see exactly what your bill
4:47is going to look like.
4:49You can also set a spending limit.
4:50So if you exceed that spending limit,
4:52you can get notified about that.
4:54So that you know that, hey, maybe somebody's
4:57overprovisioning Github codespace.
4:59Maybe they're using a 32-core virtual machine
5:02when they really could just get away with something like maybe
5:05a 4-core virtual machine.
5:06And so that just gives you some controls
5:09over your spending on the platform.
5:11But how do we actually create a codespace, right?
5:14This is just the high level stuff
5:15in terms of enabling the feature on your organization
5:19and GitHub.
5:20But once you've enabled that feature
5:22and you're signed up for Teams or Enterprise plans,
5:24how do you actually use the feature?
5:26Well, I'm going to come back to my actual organization here.
5:30This is my organization's home page, GitHub.com/cbttrevor.
5:34And what we're going to do is start out just
5:36by creating an empty repository.
5:39So let's just do a new repository here.
5:41And I'll call this GitHug-codespaces for now.
5:45Feel free to just name your repository
5:47whatever you'd like to.
5:48And I'm going to make this a public repository for now.
5:52And I'm just going to click on Create Repository.
5:55Now, this is a completely empty repository.
5:58There's no files in here, obviously.
6:00We haven't actually created anything.
6:01And so it's giving us the standard home page
6:03where it's saying, all right.
6:04Here's how you can add some files
6:05if you have an existing project locally that you'd
6:08like to push up with Git.
6:09Or you can just use the GitHub UI here
6:11to create new files and things.
6:13Now, what you're not going to see,
6:14at least as of this recording on this home page here,
6:17is an option to open this empty repository
6:21inside of codespaces.
6:22And this actually confused me at first
6:23because I was kind of expecting to see an option here
6:26to open the empty Git repository inside of a codespace
6:30so I could start adding files, adding folders, and building
6:34out my project.
6:35However, that option is not available
6:37until you actually create a file here.
6:39So I'm just going to create a dummy file.
6:41We'll just call it readme.md and just put
6:44some random text in there.
6:46And then we'll just commit that file.
6:48And once we have a file in our Git repository,
6:51now you can see that we have this little code dropdown
6:54right here.
6:54And when you drop that down, normally you just
6:56have this option over here, this local tab where
6:59you can clone your repository locally on your dev system.
7:03So you can choose HTTPS or SSH-based cloning.
7:06Or you can use the GitHub CLI as well,
7:08if you are using the CLI tool.
7:10But then there's this new tab right here called Codespaces.
7:14And this allows you to provision a new codespace.
7:17And it'll automatically open up this particular repository
7:21in that brand new codespace.
7:23Now when you click on Create New Codespace,
7:25you're going to be given the option in terms
7:27of how many CPU cores and how much memory you
7:31would like to allocate to your GitHub codespace.
7:34And for most intents and purposes,
7:35if you're just doing some pretty lightweight stuff,
7:38the 2-core virtual machine is going to be plenty.
7:41So go ahead and just click on Create Codespace.
7:43And that is going to pop open a new tab here.
7:46And it'll give you this nice little landing
7:48page that shows you the status of where your setup is.
7:52And basically, what it's doing behind
7:53the scenes is it's spinning up a virtual machine.
7:55It's spinning up a containerized development environment.
7:59And then it's going to take you directly
8:01into Visual Studio Code running in your web browser.
8:05Now because my browser is currently in the full screen
8:09mode-- if I hit F11 in here, I can come out
8:11of full screen mode.
8:12Or actually, it's not going to take that.
8:14Let me just hit Escape a couple of times here.
8:18All right.
8:18That's not working for some reason.
8:20I think VS Code is actually intercepting my keyboard
8:22shortcuts there, which is fine.
8:24But you can see as I put my mouse up
8:25to the top of the screen here, I'm actually
8:28on this GitHub URL right here.
8:30And so VS Code, even though it kind of
8:33looks like it's running natively on my local system here,
8:35it's actually running on a virtual machine
8:38somewhere up in the Microsoft Azure Cloud.
8:41Now how do I know it's running in the Microsoft Azure Cloud?
8:44Well, if I come over to the documentation for the GitHub
8:47codespaces feature and you go to the Overview documentation,
8:51it talks to you about what exactly a codespace is.
8:55And it kind of breaks down what we talked about before, which
8:57is that you can use VS Code desktop locally,
9:00or you can run VS Code in your browser, which
9:02is what we're doing right here.
9:04And that's going to connect the editor over
9:07to a virtual machine that, as you can see right here,
9:11is running in Azure.
9:12And on that virtual machine-- it's a Linux VM.
9:15And it's going to spin up a Docker container.
9:18And it's going to clone my source
9:19code into that container.
9:21It'll pre-install some language runtimes for me.
9:24So I'll have things like Python and Ruby
9:26available inside of that containerized environment,
9:29as well as some common developer tools.
9:32So once you've got this environment open here,
9:34you can see it's automatically cloned my repository for me.
9:38And so that single file that I created just using the GitHub
9:41web interface is now available inside of this VS Code
9:46environment.
9:47Now, one of the other great features about GitHub
9:49codespaces and just VS Code in general
9:52is the fact that your settings will actually synchronize
9:55with the GitHub service.
9:57And so if you were to install extensions from the Extensions
10:01Marketplace for Visual Studio Code,
10:04those extensions will actually get
10:06synchronized to GitHub as set user settings, essentially.
10:10And then when you spin up a brand new codespace,
10:12because I'm logged in with my GitHub user account,
10:15you can see that it's actually doing a synchronization.
10:18And it's actually installing all of the extensions.
10:20You can see it's kind of incrementing that number right
10:22here.
10:23So it's actually going through and installing
10:25all of the extensions that GitHub has remembered that I've
10:28been using on my local development system
10:31when I was also signed in with GitHub.
10:33So this is just another level of seamless synchronicity
10:39between my local VS Code environment
10:41that I'm using on Windows 11, the MacBook Pro that I
10:44sometimes use for work as well.
10:46I'm also logged in there so I get
10:48that synchronization of extensions and VS Code settings
10:52there as well.
10:52Plus, when I spin up a GitHub codespace in the cloud,
10:55I automatically get that synchronization of extensions
10:59and user settings as well.
11:00So this looks and feels exactly like my Visual Studio Code
11:04editor does running locally on my Windows 11 system.
11:07And I didn't have to do any extra work in order
11:10to set it up.
11:11It just happened because I'm logged in with GitHub.
11:14Isn't that great?
11:15So now we've got this GitHub codespace environment running.
11:18And there's a lot that we could do here.
11:20But we're going to take a look at some of the customizations
11:23that you can actually apply to your codespaces.
11:26And we'll also take a look at how
11:27you can manage your codespaces once they're
11:29up and running inside of the GitHub web user interface
11:32as well.
11:33I hope this has been informative for you,
11:35and I'd like to thank you for viewing.
Customize GitHub Codespaces Dev Container
0:11Hey, guys, and welcome back.
0:13So in the last video, we deployed our very first GitHub
0:16code space and we took a look at how
0:19we're running a Visual Studio code in the browser
0:21with all of our settings and all of our extensions synchronized,
0:24which is a really great feature of this tool.
0:27Visual Studio code is a very versatile editor.
0:30It's usable for many different languages.
0:33You could be a PowerShell developer.
0:34You could be a c-sharp developer.
0:36You could be a JavaScript developer, Python developer.
0:38There's extensions for pretty much everything out there.
0:42Now, one of the things that you can do
0:43is actually customize this environment quite a bit
0:46because as we saw before in the documentation,
0:49we're actually just running our development environment
0:51inside of a Docker container somewhere on a virtual machine
0:55up in the cloud.
0:56And because we're running inside of a container,
0:58we can actually customize a lot of the environment
1:02that we're working inside of.
1:04Now, if you're familiar with Visual Studio code,
1:06and you've watched some of my other training
1:08here at CBT Nuggets on Visual Studio code,
1:10or perhaps on PowerShell automation
1:12and things like that, you may have
1:14seen me use a feature called Dev containers.
1:17And essentially, what that allows you to do
1:19is take your Visual Studio code editor,
1:21like what we have right in front of us here,
1:22and then, connect it to a containerized environment.
1:26And that container could be running locally
1:28on your system with Docker desktop,
1:30and you could configure it to talk to a remote container
1:33as well.
1:34But as we saw in the documentation right
1:35here in GitHub code spaces, it is basically just connecting
1:39that browser-based editor vs Code running in your browser
1:42right here.
1:43And it's connecting it to that containerized environment,
1:46running on a virtual machine.
1:49So what if you wanted to customize that environment,
1:52and maybe install some custom software packages as part
1:56of the build process, or you want
1:58to just apply some kind of customizations
2:00to that environment as it is being deployed.
2:04Well, there is a really cool capability
2:06called devcontainers.
2:08And you can actually apply the feature
2:11to your GitHub code spaces.
2:13And what this allows you to do is
2:15to build a custom container image that
2:18has your own Dockerfile instructions,
2:21or different software packages that you'd like to install
2:24or customizations that you'd like
2:26to apply to the environment.
2:27Maybe you want to change some configuration files or preload
2:31some data onto the file system of that container,
2:34as you are working in your projects.
2:37But we can use this devcontainer.Json file,
2:40to customize the build process for our containerized
2:44environment that is running on this Azure virtual machine
2:48like what we talked about before.
2:50So how do we actually do this?
2:52Well, you have this devcontainer.json file,
2:55and this sits under your project dot vscodehiddendirectory
3:00And so basically, once we create this file,
3:04we'll be able to customize some of the different packages
3:07that we pre-install on there.
3:08You can also do something known as a post installation hook
3:11as well.
3:12And so that's going to allow us to run some kind of automation
3:15task, after the code spaces environment has been spun up.
3:19And you can hook into there and just run arbitrary code
3:23to install additional packages after it's been spun up
3:27or do any other kind of automation tasks.
3:29Maybe you could send an email and just say,
3:31hey, my environment is up and running
3:33and just send yourself a notification.
3:34There's all sorts of types of automation
3:36that you could potentially do.
3:38It's actually the dot dev container folder here.
3:41Not the dotvs code.
3:43The dot vs Code folder is where your settings, dotjson
3:47exists, if you have a project specific vs Code settings file.
3:52So how do we get this devcontainer.json file, as well
3:56as this Dockerfile that we'll use to add in instructions,
4:02so that we can customize what software packages are
4:04being installed as part of our code spaces deployment process?
4:09Well, it's actually really easy.
4:11Because they actually provide an extension
4:14that's available inside of the interface here.
4:17And if we just hit F1 to pop open the Microsoft Visual
4:20Studio code command palette, and we search for code spaces,
4:25you can see that we've filtered down the list of vs
4:27Code commands here for ones that specifically are coming
4:30from the code spaces extension.
4:32In fact, if you go over to the extensions,
4:35you can either do Control-Shift-X
4:36on your keyboard, or click on this icon
4:39right here with the blocks.
4:40If we take a look at the installed extensions
4:44right here, we should see that there is a GitHub code spaces
4:48extension somewhere in here.
4:51So let's search for code spaces.
4:53And as you can see, here is this GitHub codespaces extension
4:56that allows us to get some additional functionality right
5:00here in our editor.
5:03So if we hit up one again and do codespaces as a search,
5:06one of the options that you'll have available
5:08here is to add development container configuration files.
5:13And so this will basically generate
5:14a stub file for the devcontainer.json,
5:18as well as your Dockerfile, that you can then go in and just
5:21start customizing, to add in whatever customizations
5:24you would like to add to your containerized development
5:27environment.
5:29Now, before we do that, there is also a bunch of other options
5:32here as well for code spaces.
5:34So if you need to resize your code space,
5:36you can actually do a change machine type option
5:40right there.
5:40And then, you can change the resources
5:42that are provisioned for it.
5:44There's also a common command that you're
5:45going to get familiar with too, which
5:47is to rebuild the container-- rebuild
5:49that devcontainer that's running up on that virtual machine.
5:52And any time that you're making changes
5:54to your Dockerfile or your devcontainers.json file,
5:57or any of the post installation hooks scripts
6:01that you're going to be using.
6:03You'll be using this rebuild container command fairly often
6:07to re-initialize your entire containerized environment,
6:11and make sure that all of the changes that you've
6:14made to your customization files are actually working properly.
6:19Also, if anything goes wrong during the provisioning
6:22of your devcontainer after you've
6:25made those customizations to the Dockerfile
6:27or to the devcontainers.json file,
6:29there is an option to view the creation log right here.
6:32And the creation log is just buried somewhere
6:35on the file system.
6:35It's under slash workspaces.codespaces,
6:39which is a hidden directory.
6:40And you have to drill down there to find it.
6:42But you can actually just hit F1, and then
6:45search for code spaces creation log.
6:47You can just do a partial search here,
6:49and open up that creation log.
6:50And it'll actually open up that log file for you,
6:53and show you where things have failed if anything does fail
6:57throughout that build process.
6:59And you can just do a Control-F and search through here,
7:02if there's a specific script that you're
7:04executing in your customizations that is failing.
7:08So let's go ahead and do some basic customizations here.
7:11So I'm going to hit F1, and then, we'll do codespaces,
7:14and I'm going to choose the added development container
7:17configuration files.
7:18And again, what that's going to do,
7:20is it's going to generate the option--
7:23the configuration files for us.
7:25And typically, what I like to do,
7:26they have these templates here.
7:28So you can base it your devcontainer
7:30off of an Alpine Linux, lightweight distribution.
7:33You could do it based off of a c-sharp environment,
7:36or a Debian Linux environment.
7:38I generally like to stick with something
7:40a little bit more generic.
7:41I don't want to pre-install the dot net environment
7:43or pre-install Golang.
7:46Oftentimes, I'm going to be working
7:48with a specific version, and sometimes
7:50these types of templates can get out of date very quickly.
7:52And if you're looking for the latest version of a runtime,
7:55sometimes it's better to just start with a base Debian build,
7:58or my personal preference would be
8:01to start with a base Ubuntu build.
8:03So I'm going to choose this Ubuntu template right down
8:05here.
8:06And then once I choose Ubuntu, Linux, it's going to say,
8:08hey, which release of Ubuntu do you want to use?
8:11Do you want to use vocal phosa, which is the latest LTS or long
8:15term support release, which is 20.04.
8:18We've also got bionic Beaver down here as well,
8:20which is 18.4.
8:22And, then I think hirsute is the 21.04 release.
8:27I'd have to double check on that.
8:28But that's I believe the latest non LTS release.
8:32That's a little bit more cutting edge.
8:35Oftentimes, I like to stick with the LTS releases,
8:37so I'll just choose vocal phosa here.
8:39And then, after you choose the version of Ubuntu Linux
8:42that you want to utilize, it'll then
8:44ask you if there's any features that you want to install.
8:48Now, this is, I did some research on this
8:50is actually a relatively new feature
8:52within the devcontainer.json file in the vs Code
8:55documentation.
8:56But what it allows you to do is to pre-install certain common
8:59tools.
9:00So if you need the PowerShell runtime,
9:01you can check that off.
9:03If you need an SSH server, so that you
9:06can access into the container for maintenance purposes
9:10or logging or monitoring purposes.
9:12You can enable an SSH server if you're
9:14using things like terraform in tflint
9:17to deploy terraform templates, then
9:19you can install that as well.
9:21Now, I often work with PowerShell.
9:23So I'm just going to go ahead and choose PowerShell for now,
9:25and click OK.
9:26And just select the latest version of PowerShell
9:29when prompted here.
9:31And after you have chosen all those options,
9:33it'll go ahead and stub out these configuration files.
9:37So at this point, we've got these this devcontainer folder
9:41in our project here.
9:42It's actually added that to our Git repository.
9:45So as you can see, we have two pending changes here,
9:48two new files that are currently untracked.
9:50And we can commit those into our source control
9:53repository alongside our other application source code here.
9:57But essentially, the devcontainer.json file
9:59is what vs Code is interpreting.
10:01It's basically saying, all right,
10:02these are the parameters that I'm
10:03going to use to set up my container based development
10:07environment.
10:08And if you scroll down just a little bit here,
10:10you see this feature's option right here.
10:12So this is that new preview option or I don't, I'm not sure
10:15if it's beta or preview.
10:17But it's not fully release ready yet.
10:19But this is where you can install
10:20some pre-defined features inside of
10:23your containerized environment.
10:24And then remember earlier, I was talking
10:26about how there's a post installation-- or post setup
10:28hook.
10:29So that is actually right here.
10:30It's commented out by default, but you can simply
10:33uncomment that.
10:34And the devcontainers.Json file has the option
10:37to run a post create command.
10:40So if there's some kind of script file
10:42that you want to execute after the devcontainer has
10:45been fully initialized then you can plug that in right here.
10:49And that's a handy option for any additional customizations
10:53that you don't want to build in directly to your Dockerfile.
10:56And then, right here, we, of course,
10:58have the Dockerfile itself.
11:00And it's very simple.
11:02It's basically just going to define an input argument, which
11:04is the variant or the addition of the operating system
11:08that we want to use.
11:09So the default value is hirsute.
11:12But when we run the devcontainer.json,
11:15it's actually going to be passing
11:16and it's going to override that default value with focal fossa
11:20instead since we chose that during the generation
11:23of these stub files.
11:25But then back here in the Dockerfile,
11:27we have just an example run command here in our Dockerfile.
11:31So if we uncomment that, we can now
11:33take advantage of the ability to install
11:36some additional packages.
11:38So I think one of the packages that you might want
11:40to commonly used is like tmux.
11:42And z sure enough, if I try to run tmux
11:44down here in the terminal, you can actually
11:47see that it's just not available by default in the GitHub code
11:50spaces container.
11:51So one of the things I could do, is just come
11:53into this run command, that it kind of stubbed out
11:55for me here.
11:56And where it has this little placeholder,
11:58your package list here.
12:00I could actually just add in tmux.
12:03And if I save that, you'll be able to rebuild
12:07this containerized environment, and then tmux
12:11will automatically be available inside of this environment.
12:15So as we talked about before.
12:16If we had F1, to search for rebuild
12:19there's the code spaces rebuild container option right here
12:22and it's going to pop up this morning saying
12:24that this is going to recreate your code space,
12:27and it will preserve the unsaved the uncommitted changes.
12:30So those in configuration files that we just generated
12:33will be maintained, so we can continue to work on them.
12:38But it's going to go ahead and basically just wipe out
12:40that container, and rebuild it using the parameters that we
12:45specified in our Custom Dev container and Docker files.
12:50So once this containerised environment
12:51comes back up and running, We should have tmux available,
12:55because we have now specified that we want that installed
12:58in our Dockerfile.
13:00Let's just give this a quick minute to finish running,
13:03and it'll spit us back into VS Code shortly here.
13:08All right, so as you can see, we are back in Microsoft Visual
13:11Studio code here.
13:12And you can see that we are in our containerized environment
13:16here.
13:17And I've actually lost the customisations
13:19that I had before when I was signed in with my GitHub user
13:21account because I have actually overridden the default
13:25configuration with these devcontainer files here.
13:29So one of the things that I'm expecting
13:30to see that's different in this containerized environment
13:33is that tmux should now be available inside of this custom
13:37container.
13:37In fact, this little welcome message right down
13:39here specifically tells me you are
13:41on a custom image defined in your devcontainer.json files.
13:46So GitHub Codespaces knows that we have overridden the default
13:51container configuration, the default Codespaces container,
13:54with our own customized container that's
13:56based on Ubuntu Linux.
13:58And then we have some additional customizations
14:00that we're running down here.
14:01Of course, you could add a lot of other Dockerfile
14:03instructions here to install other packages or download
14:07packages from other package repositories, besides apt.
14:11You don't have to use apt.
14:12But if there's like some custom scripts
14:14that you want to run to install a third-party utility,
14:16you could certainly do that there.
14:18But down here in the terminal, I should be able to run tmux now.
14:22And sure enough, because I've customized my Dockerfile,
14:25I am able to run tmux now.
14:28So using the devcontainer.json, as well as the Dockerfile,
14:32gives you the powerful capability
14:34of customizing your devcontainer to your project's
14:38specific needs.
14:39Just keep in mind that because these files
14:42are part of your repository.
14:44Well, at least they will be once we actually add them and commit
14:46them to the repository.
14:48But once they are part of your repository,
14:50any developer that's going to collaborate
14:53on your project using GitHub code spaces
14:56is automatically going to inherit these settings
14:59because they're part of the repository.
15:01However, git code spaces actually
15:03does provide another facility to allow
15:05you to provide specific customizations that only apply
15:09to your GitHub user account, not to the entire project
15:13and we'll look at that in a separate video.
15:15I hope this has been informative for you,
15:17and I'd like to thank you for viewing.
Add User-Specific Customizations to GitHub Codespaces
0:00[MUSIC PLAYING]
0:11Hey guys, and welcome back.
0:13In the last video, we took a look
0:14at how to utilize the devcontainer functionality
0:18in order to customize the software and configurations
0:21that are being used to provision our devcontainer that's running
0:26on that Azure virtual machine behind the scenes in the GitHub
0:29Codespaces feature.
0:31Now, one of the other things that you
0:32can do to customize your development environment
0:35is to make user specific changes.
0:38So these devcontainer.json and Docker file files
0:42are going to apply to the entire project.
0:45So anybody who is using this project over here, of course,
0:49once we've committed these, let's
0:51just say adding devcontainer files really quick,
0:54and then we'll just do a sync changes that push those up
0:57to the repository.
0:58Now, if we come over to the repository,
1:00we should see that folder show up.
1:02There's devcontainer.
1:03And then we've got our two files in there.
1:05So if any other developer that's collaborating
1:08on this particular project comes along and spins up a Codespace,
1:12they're automatically going to get these customizations inside
1:16of their Codespace as well, because the GitHub Codespaces
1:19feature will simply pick up automatically on the fact
1:22that these files exist and apply them to the dev environment.
1:26If there are customizations that only you, individually,
1:31on your team need to apply to the GitHub Codespaces
1:34environment, you can actually do that
1:36with a separate feature known as GitHub dotfiles instead.
1:41And that's actually going to be something
1:43that you apply at your specific User Configuration on GitHub.
1:47So if we come up to our user account right up here
1:50and go down to Settings, and we drill down
1:55into Codespaces, which is a little ways down right here,
2:00you'll see that we have this option right here.
2:02It's a little checkbox that says automatically install dotfiles.
2:06And then we have this option to choose a repository that
2:09contains our dotfiles.
2:11So how does this work?
2:13Well, if we drill over into the GitHub documentation
2:15here for GitHub Codespaces in particular,
2:18and then drill into customizing your Codespace
2:21and then choose Personalize Your Codespace,
2:24there are a couple of options that you have here.
2:26First of all, we talked about that Settings Sync earlier.
2:29So this allows you to share your Visual Studio code extensions
2:33and your configuration files.
2:35It sets your font, and your theme,
2:37your preferred color theme, and all those types
2:40of advanced options.
2:41That's one benefit of using the VS Code
2:43environment in Codespaces.
2:44But the other one is this dotfiles feature here.
2:48If I just click to jump down to dotfiles right here,
2:51let's do a little bit of reading about this.
2:54So dotfiles are special files that start with a period.
2:58They're just basically hidden files on the file system
3:01that control configurations.
3:02But if we drill down a little bit further right here, when
3:06you create a new Codespace, this is really important,
3:08so when you provision a new Codespace,
3:10not if you have an existing Codespace and just open it up,
3:13so it has to be either rebuilt or created completely
3:17from scratch, then GitHub will actually
3:19clone the selected repository that you
3:23selected on this screen right here in your user profile.
3:26And this only applies to your user account,
3:28not to anybody else that's collaborating on your project.
3:33And so what it's going to say is it's
3:34going to clone that repository locally
3:36that you select in your user settings
3:37there to the Codespace environment.
3:40And then once it clones that locally,
3:42it's going to look for some special file names
3:46to perform some additional configuration steps.
3:50So the first file name it's going to look for
3:51is something called install.sh.
3:55So if that file exists and it has
3:58a shebang that points to shell in the environment,
4:03like PowerShell, or BASH, or SH, or something like that.
4:06And it is set to be executable, so,
4:09of course, you have to have the executable bit set
4:11on that file, if that file exists,
4:14then the GitHub Codespaces environment will actually
4:17try to trigger that script and run whatever commands
4:21are inside of that script.
4:23And there are some other file names that it will try as well.
4:25So if install.sh doesn't exist, it'll
4:27look for one with install with no file extension.
4:31It'll look for a bootstrap.sh, bootstrap
4:33with no file extension, and so on and so forth.
4:36So you have a couple of different options here.
4:38So it's going to attempt to automatically run
4:41these scripts when you spin up your Codespace.
4:45Now, before we actually try to do that,
4:47one of the things we'll need to do
4:48is actually to terminate our Codespace.
4:50So I'll come over back to my GitHub user interface
4:52and go to Your Codespaces.
4:54And you can only have a maximum of 10 Codespaces running
4:57at a time.
4:57Right now, I only have two right here.
5:00But I'm just going to go ahead and just choose the option
5:03to delete this Codespace.
5:05And that's going to kind of reset it back to square one.
5:08And now, once we add in this customization,
5:12we'll be able to spin it back up.
5:14And it'll apply that customization.
5:17So let's go ahead and try this out.
5:19One of the things that we'll need to do
5:21is actually create a repository under our personal user
5:25account.
5:25So I'll go to My Repositories, not My Organization
5:29Repositories, just me individually, My Repositories.
5:32And I'll create a new repository just called github codespaces
5:37customizations.
5:39Again, you can name this whatever you want to.
5:42And you also want to make sure that it is set to public.
5:44In the documentation, they refer to ensuring
5:47that it is public, in the troubleshooting documentation.
5:50And then we'll hit Create Repository.
5:53Now in this repository here, we're
5:55going to go ahead and clone this on our local system.
5:59So I'm going to fire up a shell here.
6:02And then I'm going to go ahead and just
6:03go into my Git directory here.
6:06And I'll just do a simple git clone on this directory here.
6:11And I'm going to go ahead and do cd github codespaces
6:15customizations.
6:17And as you can see, it's just empty, right?
6:20So I'm going to do vim install.sh.
6:24And I'm going to go ahead and just do a shebang here.
6:27And we'll say usr/bin/env bash.
6:31And then let's say that we wanted
6:32to do something like installing a PowerShell module.
6:35So what we could do is invoke PowerShell,
6:38because PowerShell is going to be installed
6:40as a result of that devcontainer.json file
6:42that we had earlier.
6:43If you recall, it's under the Features,
6:45the kind of well-known features section there.
6:48But let's say that we wanted to install a module for PowerShell
6:51as part of the initialization process.
6:54So I could do a bash script that actually calls PowerShell
6:58and say PowerShell -command.
7:01And then we'll do Install-Module -name.
7:05I'm going to install the pode web server.
7:07It's just a web server module that
7:08allows you to create web servers in PowerShell,
7:11and then specify the -force parameter here.
7:13So I'll go ahead and do a colon wq to save that.
7:17And the other thing I need to do is do a git update index.
7:21And just to make sure that this has the execute bit set,
7:25we're going to do git update index, chmod equals plus x.
7:30And then we're going to do that on install.sh.
7:34And of course, I need to do this --add.
7:38There we go.
7:40And then we'll do git status.
7:42So we've got this new file to add.
7:44So we'll do git add install.sh, git commit.
7:49And we'll say adding install script.
7:53And then we'll do a git push.
7:56So we've basically created a hook,
7:59a script that will run after the initialization of our GitHub
8:02Codespace environment that's going
8:04to install an extra PowerShell module for us.
8:07But that's only going to happen for us.
8:09It won't happen to any other collaborators,
8:12because their GitHub account will not be configured
8:15to actually use that setting.
8:17So let me just refresh my repository here.
8:20And sure enough, there is our install.sh script.
8:23And it's got that code in there.
8:25It's basically just going to run a bash script, which
8:27is going to call PowerShell.
8:29And now I'm going to come over to my Codespaces settings.
8:33And under the Codespaces section here, I'm
8:37going to go ahead and make sure that this box is checked.
8:39And then I'm going to select the repository that I just created.
8:45So let's search for github codespaces customizations,
8:48that's the repository that I just
8:50created with my personal customizations on it.
8:53And now it has automatically saved that setting.
8:57So in order to test this out, again, we
8:59need to make sure that Codespace is terminated, which we already
9:02did.
9:03And so now we'll go back to our organization.
9:06I'll go back to Organizations go to CBT Trevor,
9:10and then we'll open up this github-codespaces repository
9:14that we created.
9:15And will go ahead and create a new Codespace here,
9:18with two cores.
9:20And just give that a moment to spin up.
9:22So it's going to apply the devcontainer.json
9:25configuration.
9:26It's going to use the Docker file to build
9:29that containerised environment, which includes tmux that we
9:32customized in the last video.
9:34And then it's also going to apply our user specific
9:37customizations that we created as well, which should kick off
9:40that bash script, which then calls PowerShell, and installs
9:44a PowerShell module from the PowerShell gallery
9:47over at powershell.com.
9:48And that's just an example.
9:50You could replace that PowerShell
9:51call with any other command that you
9:53want to or any other series of commands
9:55that you would like to.
9:56But that's just a really simple example
9:58to show that I can trigger a script that basically just run
10:01some additional customizations after the fact.
10:04So once this VS Code environment opens back up,
10:08we should have all of our customizations.
10:11Of course, we get that message saying that, hey, you
10:13are on a custom image that you have
10:15configured with your devcontainer.json file here.
10:19And of course, I should be able to run tmux here.
10:23And yep, sure enough, it looks like tmux is there.
10:25It looks like it's still installing some extensions
10:28here.
10:28It's kind of re-initializing everything from scratch,
10:31since we rebuilt this Codespace from complete scratch.
10:34It has to go through and install all the different extensions
10:37that I have.
10:38But it looks like tmux is working OK.
10:42And I should also have PowerShell installed as well.
10:47So there's PowerShell.
10:48And now, to validate that the install script, the hook
10:52that we just created, is actually working correctly
10:55from our personalized settings that we applied right over here
11:01under the GitHub settings, under Codespaces,
11:04we reference this github-codespaces-customizations
11:07repository that has our install.sh script.
11:10So what we should be able to do is
11:13run git-modlue -listavailable.
11:20And if I hit Enter here, let me just clear the screen really
11:23quick, as you can see, the pode module is actually installed.
11:28So that's basically just confirming
11:29that we have successfully triggered that post setup hook
11:33script.
11:34And it executed it successfully.
11:36Now, I did run into some issues when
11:38I was originally testing this.
11:39You do want to make sure that you are ch
11:42modding that file in the actual Git index
11:45itself, not just on the local file system.
11:47But you want to make sure that you're actually
11:49updating the Git index.
11:50And make sure that the execute bit
11:52is set on that particular file.
11:54Otherwise, it will fail to trigger it correctly.
11:57Also another issue that you could potentially run into
12:00is the type of line endings that are used.
12:03So if you're using Windows based line endings instead of Unix
12:06based line endings, that can also
12:08cause that post-installation hook
12:10to fail to execute as well.
12:14So just be aware of a couple of those potential issues
12:16that you could come across.
12:17But sure enough, it did actually execute.
12:20Now, just to troubleshoot this, if something did go wrong,
12:24we can take a look at the creation log,
12:27as we looked at before, if we hit F1 in the editor here,
12:30and look at the creation log, that's one of the Codespaces
12:33commands that you can run.
12:34Or you can actually just open it up from the file system
12:37if you know where to look.
12:39So by default, you're going to be stuck in this code, GitHub
12:42Codespaces--
12:43this is actually your repository folder.
12:45But if you go up one level and then do an ls-ll, do ls-lga,
12:55and that'll actually reveal the hidden folder here
12:58called dot codespaces.
12:59And this is kind of a meta folder
13:01that the GitHub Codespaces feature uses.
13:03And if we drill into that directory
13:06and do an ls, eventually, let me do ls-lga,
13:12drill into dot persistedshare, cd dot persistedshare.
13:18And then we'll do ls-lga once more.
13:21And as you can see, the creation log actually
13:23exists in that persisted share hidden directory,
13:27which is under the Codespaces hidden directory
13:30under the slash workspaces root directory.
13:33So if you need to look at that creation log,
13:35it does exist under there.
13:36Or you can just use that F1 shortcut to go find it.
13:40Also, if you take a look at this dotfiles directory right here,
13:43you can actually just cd into that.
13:46So we'll do cd dotfiles, do ls-lga.
13:50And look what's there.
13:52That is the install.sh script.
13:54So if I just cat installsh, that is actually the install script
13:59that we created when we created that custom repository right
14:04over here with our customizations in it, just
14:07under my user account.
14:08That's a repository that doesn't exist under my CBT Trevor
14:12Organization.
14:12It's just customizations for me personally
14:15within any of my Codespaces.
14:18So as you can see, that's a really nice hook
14:20to be able to hook in and customize your Codespaces.
14:22You can install software packages,
14:23install modules for your framework of choice.
14:26You can apply configuration files.
14:28You can pretty much do whatever you want to.
14:30I hope this has been informative for you.
14:32And I'd like to thank you for viewing.
Add User-Specific Secrets to GitHub Codespaces
0:11Hey, guys.
0:12And welcome back.
0:13There's one other feature I wanted
0:14to cover in the GitHub codespaces service,
0:17and that is the ability to create encrypted secrets
0:20for your codespaces.
0:22Now, there might be things like API keys
0:25or other types of secrets that are
0:27specific to your user account.
0:30So when you're logged in to GitHub
0:31and you create a GitHub codespace,
0:33you only want those secrets to be available to you
0:36personally not anybody who has access to your shared GitHub
0:41repository.
0:42So that's something we can actually
0:43configure as an environment variable for that GitHub
0:47codespace.
0:47And then any time that you personally spin up a codespace,
0:50you'll be able to see those secrets as environment
0:53variables, whereas other users that
0:55are collaborating on your GitHub repository
0:58will not be able to see them.
1:01So just really quickly here, if we take a look
1:03at our organization, which is CBT Trevor,
1:06then we have this organization repository called
1:09GitHub Codespaces, this is kind of our shared working
1:12environment with the rest of our colleagues,
1:14because this is where our application
1:16code would go as we're building out some kind of application.
1:20So on this organization repository,
1:23if there's any common API secrets
1:26that we need to share with the rest of the team,
1:28we would probably configure those at the repository level.
1:32So on this repository if we drill over to Settings
1:35and then scroll down and go to Secrets,
1:37you can see that we have the ability to set repository level
1:41secrets right here.
1:42And I've actually used this feature
1:44a fair amount in some of my other training on GitHub
1:47actions workflows so that you can
1:49use secret values for things like AWS Cloud secret access
1:54keys that you want to use inside of a GitHub workflow--
1:58GitHub Actions workflow, rather.
1:59You can store those in the repository level secrets
2:01and then reference those inside of the GitHub actions
2:05workflows.
2:06However, if there are API keys, as we talked about,
2:08that are specific to you individually
2:11that are not to be shared with the rest of the team right
2:13here, then you can configure those
2:15on your individual codespaces settings.
2:18And that is another GitHub profile-level, not
2:22a repository- but a profile-level setting,
2:25similar to the dot file setting that we
2:27looked at in the last video.
2:29So if we come up to the top-right corner here,
2:31again, for our user account and then
2:34we drill down under Settings right here,
2:37well these are our personal account settings
2:39for our GitHub account.
2:41And if we scroll back down to Codespaces here,
2:43this is the same screen where we configured
2:46that dot file's beta feature, where we basically said,
2:50here's my personal repository that
2:51has a install script that I want to execute any time that I
2:55deploy a new codespace.
2:58Now, right below that, we have this option
3:00to create codespace secrets.
3:03And as you can see, it describes what those are.
3:06Secrets are environment variables.
3:07So it'll be exposed to the codespace as an environment
3:10variable.
3:10And we can use that from Bash.
3:12We can use it from Python.
3:13We can use it from any process that's
3:15running in that codespace.
3:17They're encrypted by GitHub, and they're only
3:20exposed to codespaces that you personally create for yourself.
3:26So if we create a new secret here--
3:29and I'll call this Trevor Secret Key.
3:32And I'll set the value to whoever
3:35likes to eat bacon and any kind of meats.
3:40And then we'll go ahead and just add that secret here.
3:44Of course, we have to also select the repositories
3:47that we want to expose it to.
3:49So let's do our cbttrevor/github-codespaces.
3:54So let me do a search for codespaces,
3:56so cbttrevor/github-codespaces.
3:58So that will be the repository that we're working on
4:01with other team members.
4:02But we want this secret for just us to be
4:06exposed to that environment.
4:08So we'll say Add Secret.
4:09And now we need to go ahead and either rebuild
4:14our codespace environment, or we need to restart it.
4:19So as the documentation says right here
4:20for codespaces encrypted secrets,
4:23once you have created a secret, it
4:24will only be available when you either create a new codespace
4:27or when you restart the codespace.
4:32So if you have a current codespace,
4:33you'll need to stop the codespace
4:35and then resume it in order to use that environment variable.
4:40So if I was to come over to my codespace environment
4:43right here--
4:43I want to close this old one.
4:45And if I do a, let's say, dollar-- what is it--
4:50Get-ChildItem on the ENV drive--
4:53that's a PowerShell thing.
4:54If I look for that Trevor Secret Key,
4:57I don't see that environment variable here.
4:59So here's term, term program.
5:00I don't see any other T environment variables.
5:03So let's go ahead and restart our codespace.
5:07So we'll say stop codespace.
5:10We'll say codespaces stop current codespace.
5:14And just access that from the command palette.
5:17And then once that has been stopped,
5:19we'll go ahead and just get it restarted.
5:23And then we should have access to that environment variable.
5:25So we'll go ahead and just click on that button to restart it.
5:29Plus, you can always go over to your codespaces right here.
5:32And you can open it in your browser right here.
5:35That'll be under your User Settings up here.
5:37And then just go to Your Codespaces.
5:39That'll list out any codespaces that you've provisioned
5:42across different organizations.
5:44And then you can choose to either open it in the browser,
5:46or you actually have this option here
5:48to open it locally in VS Code as well.
5:52But let's come back over here, and we'll give it
5:54a second to just spin up here.
5:56And this time it's going to be a little bit faster because we're
5:58not actually repositioning it.
6:00All we did is we stopped it and then restarted it.
6:04So it doesn't have to go back and install all the extensions.
6:07All those extensions should still
6:08be installed from the previous execution.
6:10Sure enough, you can see my 52 extensions there.
6:12So that part's fine.
6:14That's not going to take any extra time.
6:15But as we can see right here in the terminal--
6:19let me see, terminal.
6:21Where's my terminal?
6:24Show me my terminal-- debug terminal?
6:26No.
6:27What happened to it?
6:29I think it's still starting up.
6:32So here's my terminal.
6:34And then we'll fire up PowerShell.
6:37And then we'll do Get-ChildItem on the ENV drive, PS drive.
6:42And sure enough, now you can see that we've
6:44got this new environment variable Trevor Secret Key.
6:47And it has my super secure API key right there.
6:50So that's basically how you can set up
6:53API secrets that are specific to just your user account.
6:57You can use those on codespaces, again,
6:59as long as you have allowed them to be
7:02used on those particular repositories.
7:05So if you try to go to a different repository
7:06and use that secret and it doesn't show up,
7:09then you want to come back to your Settings,
7:11go to Your Codespaces, take a look at this secret right
7:15here and make sure that any repositories that you
7:18want to use it on are actually listed right here.
7:22Otherwise that secret simply won't
7:23be available for codespaces for those particular repositories.
7:28I hope this has been informative for you,
7:29and I'd like to thank you for viewing.
Team training path
Turn this skill into assignable team training
This free skill is a preview of the courses your team can assign, track, and report on with CBT Nuggets.
$708
seat / year