From the course: OpenAI API and MCP Development
Creating a dev container and configuration file
From the course: OpenAI API and MCP Development
Creating a dev container and configuration file
You may have noticed that when you start to work in Codespaces, that you have to go through the same steps of setting up your Python projects with the creation and activation of your virtual machine, but also to install the packages. But actually, step two is redundant, because whenever you work in Codespaces, you already work in a virtual machine, some sort of virtual machine that we call DevContainer. So I'm going to introduce you to the dev container configuration file in this video. What we want to do is to set up a Python project in Codespaces. So we have already Codespaces up and running. Now we want to see how to set it up so we can execute some commands automatically instead of doing it manually. And I want to show you the steps to create a custom container configuration. So let me So let me introduce you to the DevContainers. So this is development containers, DevContainers for short. So they are Docker containers that are specifically configured to provide a fully featured development environment with all the packages, everything that you need in your projects. And you want them to be already pre-installed. So you don't need to go through the steps of installing and setting up everything on your own manually. It's going to be done automatically you start your Cutspace. So I'm going to take you to the steps to create one. And this guide is actually for VS Code, but that's going to be the same steps to do it in Cutspaces. So here you just need to add a dev container JSON file. And you're going to have first a predefined configuration file, and then you can customize it to include your own operation that you want to be running whenever you start and run your cut spaces. Okay so let's do that. I'm going to show you the steps. So you're going to press simultaneously on the keys shift command and p in cut spaces and first you're going to see this in the list. If it doesn't come up you can start typing devcontainer and then select devcontainer configuration file, then select Create a new configuration. Here we go. So you have a few options coming up, but what we want to do is to set up a Python project. So I'm going to type Python and select the version that I need. 3.11 is going to be enough. Then we can go ahead and press OK to create this development container with our configuration file. So when you press OK on the left, you're going to see coming up this DevContainer directory with a DevContainer JSON file. And now you see that you're going to be prompted to rebuild. So let's press Rebuild now, because we have a new configuration available now. So let's press Rebuild, meaning that it's going to take into account this new configuration for your Cutspaces, and that's going to be the starting point for every time that you start and run your Cutspaces. So let's run it. And while this is being rebuilt, I'm going to take you to our actual exercise files, because you're going to find in the exercise files available with this course a custom DevContainer configuration file, because we're going to use this one. So you just need to copy all these lines, and I'm going to walk you through it. Let's go back to our Codespaces when it's finished rebuilding. So we're going to then, again, update this one, because this one is very basic and just predefined with the configuration of the Python version. Instead, I want to have here more options. And here, again, we're going to be prompted to rebuild. I'm going to walk you through it first. So what you have here is the configuration for this Python. All right, so I'm just gonna paste again, so I'm gonna be prompted to rebuilding and afterwards. Okay, we're gonna try that again. All right, so then you also have some extensions. So the same that you'd find in VS Code. And these are extensions that we can use for linting to verify the formatting and the writing of our code, just to make sure that the code is written properly and in a clean way. And then we have line 12, important, this PostCreate command. And this is to run automatically the command to install all the packages that we need for the project without having to do it manually. So let's do that again, because what I want is to be prompted to rebuild again. Let's just make sure that, OK, you know what? I'm just going to delete again, because I just want to make sure that this is allowing us to use this configuration. So I'm going to show you the steps again. I'm going to press on the keys shift command and then P. Select add dev container configuration file. All right, I'm going to start typing Python. To have a basic predefined configuration file. All right, so let's skip and then change again this one. And I hope that we're going to be prompted to rebuild because this is what I want. you need to rebuild every time that you add and create a DevContainer JSON. Okay, so what you can do is you can actually press again, and we're gonna actually manually request here to rebuild the container. If you don't have the dialog box coming up at the bottom of the screen, you can here again request to rebuild the container, and then here you're gonna press rebuild. So that is an important step to make sure that your new configuration is now taken into account. And whenever you start your Cutspaces, you want these configurations to be applied to your project. So now let's try to run our project. OK, so now we're going to be welcomed with this message. And now we want to run the project. That's going to be PythonMain.py. All right, and here we go. So it's going to be started right away. So the program started right away. So we can ask, as usual, our questions to the AI. So we didn't need to go through the steps of here. So we don't need that, actually. I should remove it. Here we go. And this as well, you don't need to install the packages. No need, all right? But you need still to add a secret key, and you need to add it in the settings of your repository. And after that, you just need to go straight to this part which is to start your app. You just need to do that. So this is the advantage with Codespaces is that you have a fully configured Python project which is ready to go and ready to get started and to work with.