-
Notifications
You must be signed in to change notification settings - Fork 185
Working with Uyuni Project Using DevContainers
PR: https://github.com/uyuni-project/uyuni/pull/9496
A DevContainer provides a consistent, containerized development environment for the uyuni project. This guide explains how to use a DevContainer for uyuni, including options for downloading a precompiled container or creating the container from the cloned code. It also highlights the tools that support DevContainers to streamline development workflows.
The DevContainer for uyuni includes everything you need to start working with the code, such as Java, linters, Python, and more, ensuring that your development environment is fully configured and ready to go.
DevContainers provide a standardized and reproducible environment for development. They are used in different ways depending on the tools and workflows you prefer. In this section, we will show you some examples of how to use the DevContainer with popular development environments such as Visual Studio Code (VS Code), IntelliJ IDEA Ultimate, and GitHub Codespaces.
While we provide examples for these tools, we welcome contributions for other tools or workflows that can integrate with the DevContainer. Feel free to experiment with different environments and share your improvements with the community!
You can clone the uyuni project using any method you prefer (e.g., through GitHub's web interface, using GitHub Desktop, or via the command line). Here's an example using the command line:
-
Example: Clone the Project Using CLI
Clone the uyuni repository from GitHub:git clone https://github.com/uyuni-project/uyuni.git cd uyuni
There are two DevContainer environments in the uyuni project:
-
Main DevContainer: The environment located in
.devcontainer/dev
contains all the necessary dependencies for compiling and working with the uyuni codebase. This container includes dependencies for Java, Python, Bash, linters, and all other tools required for development. -
Docker Compose DevContainer: The environment located in
.devcontainer
includes a docker-compose.yml file that uses the main DevContainer and starts an additional container running a database. This database container is used for unit tests, allowing you to run and test the project with a simulated database environment.
You have two options to get started with the DevContainer:
-
Option 1: Download Precompiled Container
If you prefer a preconfigured environment, you can download the precompiled DevContainer image from GitHub Container Registry (GHCR). This image includes all necessary dependencies and tools for the uyuni project.docker pull ghcr.io/uyuni-project/uyuni/devcontainer:latest
-
Option 2: Create the DevContainer from Cloned Code
Alternatively, you can create the DevContainer directly from the cloned uyuni project. This involves opening the project directory and using a tool that supports DevContainers (e.g., Visual Studio Code, DevContainer CLI, IntelliJ Ultimate) to build and start the container. The container configuration is provided in thedevcontainer.json
file and the Dockerfile, which automatically sets up the environment with all necessary dependencies. Once the DevContainer is created, it will be ready to use for development.
Once you have the DevContainer running, follow these steps for a seamless development experience in Visual Studio Code:
After cloning or pulling the container, open the project directory in Visual Studio Code. If you have the Remote - Containers extension installed, VS Code will detect the devcontainer.json
configuration and prompt you to reopen the project inside the container. Click Reopen in Container.
Once inside the container, you can use the VS Code debugger to run and debug the project as you normally would. Since you're working inside the container, your environment will closely match the production setup, making it easier to reproduce issues and test in an isolated space.
If changes are made to the DevContainer configuration (e.g., the Dockerfile or devcontainer.json
), you may need to rebuild the container to apply them:
- Open the Command Palette in VS Code (
Ctrl+Shift+P
orCmd+Shift+P
). - Type "Remote-Containers: Rebuild Container" and select it.
To stop the container, close VS Code or select "Remote-Containers: Reopen Locally" from the Command Palette. To restart it, select "Reopen in Container" again.
In addition to VS Code and GitHub Codespaces, you can also use IntelliJ IDEA Ultimate to work with the uyuni project inside a DevContainer.
To open the uyuni project in IntelliJ Ultimate using the DevContainer, follow these steps:
- Open IntelliJ IDEA Ultimate.
- In the Remote Development section, click on Dev Containers.
- Select New Dev Container.
- IntelliJ will prompt you to select the devcontainer.json file. Navigate to the uyuni project and select the devcontainer.json file located in the
.devcontainer
directory. - IntelliJ will automatically detect the DevContainer configuration and set up the environment inside the container.
Once the container is set up, IntelliJ IDEA will launch the project with all the necessary dependencies configured, and you can begin working on the project within the containerized environment.
Once inside the container, you can use IntelliJ's built-in debugging tools to run and debug the uyuni project as usual. The containerized environment ensures that the dependencies and configuration closely match the production setup, making it easier to reproduce issues and test the code.
GitHub Codespaces offers a cloud-based development environment that can automatically launch a containerized workspace configured using the DevContainer. This is a great option if you want to quickly spin up an environment without worrying about local setup or dependencies.
There are two ways to open the uyuni project in GitHub Codespaces:
To open the uyuni project in GitHub Codespaces directly from the repository:
-
Navigate to the uyuni GitHub repository:
uyuni GitHub repository. -
Click the "Code" button, then under the "Codespaces" tab, click "New codespace".
GitHub will automatically create a new Codespace for you, launching the uyuni project inside a container configured by the
devcontainer.json
file.
If you're working on a pull request (PR), GitHub makes it easy to launch a Codespace directly from the PR:
-
When you create or view a PR, a "Create Codespace" button will be available within the PR description (this is typically added automatically in the PR template).
-
Clicking this button will automatically create a Codespace for you, pre-configured with the PR's code changes. This is an efficient way for reviewers and collaborators to instantly access the environment with the latest changes, without needing to manually check out branches or configure the environment themselves.
This integration makes it incredibly easy to work on pull requests, review code, and test changes within an isolated, cloud-based environment.
Once your Codespace is running, GitHub provides several helpful buttons and information:
- Workspace Information: You can view details about the current workspace, including its configuration, status, and other relevant metadata.
- Limits and Costs: A button will display important details about the workspace limits (e.g., CPU, memory) and associated costs (if applicable). This is useful for understanding resource usage and optimizing your cloud environment.
- Stopping the Codespace: You can stop the Codespace at any time to free up resources or save costs. Simply click the "Stop" button from the GitHub interface.
- To stop your Codespace, click the "Stop" button from the GitHub interface.
- To restart it, simply click "Reopen in Codespace", and GitHub will restore your environment and continue where you left off.