DevContainer
Airulefy supports Visual Studio Code's DevContainer feature, allowing you to easily set up a development environment. This page explains how to configure and use DevContainers with Airulefy.
What is a DevContainer?
A DevContainer is a VS Code feature that allows you to create a complete development environment within a Docker container. This ensures that every developer can work in the same consistent environment with identical settings, tools, and extensions.
Airulefy's Development Environment
The Airulefy project provides a DevContainer configuration with the following features:
- Python 3.11 environment
- Poetry for Python package management
- Automatic test running
- Pre-installed code quality tools (black, isort, mypy)
- Automatic configuration of VS Code Python extensions
devcontainer.json
The .devcontainer/devcontainer.json
file is the main configuration file for the DevContainer. Here's an example configuration used in Airulefy:
{
"name": "Airulefy Development",
"dockerFile": "Dockerfile",
"settings": {
"python.defaultInterpreterPath": "/usr/local/bin/python",
"python.linting.enabled": true,
"python.linting.pylintEnabled": false,
"python.linting.mypyEnabled": true,
"python.formatting.provider": "black",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
},
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"njpwerner.autodocstring"
],
"postCreateCommand": "poetry install && pre-commit install",
"remoteUser": "vscode"
}
Dockerfile
The .devcontainer/Dockerfile
defines the base image and additional setup steps for the DevContainer:
FROM mcr.microsoft.com/devcontainers/python:3.11
# Poetry environment variables
ENV POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
POETRY_VIRTUALENVS_CREATE=1 \
POETRY_CACHE_DIR=/tmp/poetry_cache
# Install Poetry
RUN curl -sSL https://install.python-poetry.org | python3 - && \
poetry --version
# Install necessary system packages
RUN apt-get update && \
apt-get install -y --no-install-recommends \
make \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /workspaces/Airulefy
Automatic Test Running
The Airulefy development environment is configured to automatically run tests in the background. This is set up in .vscode/settings.json
as follows:
{
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.pytestArgs": [
"tests"
],
"python.testing.autoTestDiscoverOnSaveEnabled": true
}
This will automatically run relevant tests whenever you save a file.
Using the Development Container
-
Install Visual Studio Code and the Remote - Containers extension
-
Clone the Airulefy repository:
git clone https://github.com/airulefy/Airulefy.git cd Airulefy
-
Open the folder in VS Code:
code .
-
VS Code will detect the
.devcontainer
folder and show a notification; select "Reopen in Container" -
Wait for the container to build and configure (this may take a few minutes the first time)
-
You're now ready to start developing Airulefy in a fully configured environment!
Troubleshooting
Rebuilding the Container
If dependencies change or you need to rebuild the container for any reason:
- Open the VS Code command palette (
Ctrl+Shift+P
orCmd+Shift+P
) - Select "Remote-Containers: Rebuild Container"
Port Forwarding
To access services running inside the container, use port forwarding. VS Code will automatically detect many ports, but you can add them manually:
- Open the VS Code command palette
- Select "Remote-Containers: Forward Port from Container"
- Enter the port number you want to forward