Skip to content

Working with Uyuni Project Using DevContainers

Michele Bussolotto edited this page Nov 22, 2024 · 3 revisions

PR: https://github.com/uyuni-project/uyuni/pull/9496

Introduction

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.

Using the DevContainer

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!

1. Clone the Project

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
    

Download the Precompiled Container or Create the DevContainer from Cloned Code

There are two DevContainer environments in the uyuni project:

  1. 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.

  2. 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 the devcontainer.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.


Using VS Code with the DevContainer

Once you have the DevContainer running, follow these steps for a seamless development experience in Visual Studio Code:

1. Open the Project in VS 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.

2. Debugging and Running the Project

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.

3. Rebuilding the Container

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:

  1. Open the Command Palette in VS Code (Ctrl+Shift+P or Cmd+Shift+P).
  2. Type "Remote-Containers: Rebuild Container" and select it.

4. Stopping and Restarting the Container

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.


Using IntelliJ Ultimate with the DevContainer

In addition to VS Code and GitHub Codespaces, you can also use IntelliJ IDEA Ultimate to work with the uyuni project inside a DevContainer.

1. Open the Project in IntelliJ IDEA Ultimate

To open the uyuni project in IntelliJ Ultimate using the DevContainer, follow these steps:

  1. Open IntelliJ IDEA Ultimate.
  2. In the Remote Development section, click on Dev Containers.
  3. Select New Dev Container.
  4. 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.
  5. 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.

2. Debugging and Running the Project

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.


Using GitHub Codespaces with the DevContainer

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.

1. Open the Project in GitHub Codespaces

There are two ways to open the uyuni project in GitHub Codespaces:

Option 1: Open from the GitHub Repository

To open the uyuni project in GitHub Codespaces directly from the repository:

  1. Navigate to the uyuni GitHub repository:
    uyuni GitHub repository.

  2. 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.

Option 2: Open from a Pull Request (PR)

If you're working on a pull request (PR), GitHub makes it easy to launch a Codespace directly from the PR:

  1. 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).

  2. 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.

2. Managing Your Codespace

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.

3. Stopping and Restarting the Codespace

  • 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.
Clone this wiki locally