|
| 1 | +# AGENT GUIDELINES FOR OFFLINE PYTHON DEVCONTAINER PROJECT |
| 2 | + |
| 3 | +## Overview |
| 4 | +This document provides essential guidelines for agents operating within the `offline-python-vscode-devcontainer` repository. This project focuses on providing an offline and air-gapped development environment for Python applications using Docker/Podman devcontainers. The emphasis is on container management and environment setup, rather than specific Python application code style. |
| 5 | + |
| 6 | +## 1. Build, Lint, and Test Commands |
| 7 | + |
| 8 | +### 1.1. Build Commands |
| 9 | + |
| 10 | +To build the primary Docker/Podman image locally: |
| 11 | +```bash |
| 12 | +podman build . -t offline-python-vscode-devcontainer:dev-latest-local |
| 13 | +``` |
| 14 | +This command should be executed from the root of the repository where the `Dockerfile` is located. |
| 15 | + |
| 16 | +### 1.2. Linting/Static Analysis |
| 17 | + |
| 18 | +Currently, there are no explicit linting commands configured for the Dockerfiles or `devcontainer.json` files. Agents should adhere to best practices for Dockerfile and JSON formatting to maintain readability. |
| 19 | + |
| 20 | +### 1.3. Test Commands |
| 21 | + |
| 22 | +Tests for Python applications *within* the devcontainer are run using `pytest`. |
| 23 | + |
| 24 | +* **Run all tests (inside the container):** |
| 25 | + ```bash |
| 26 | + pytest -v /home/vscode/py-apps/tests/ |
| 27 | + ``` |
| 28 | + This command is executed as part of the Dockerfile build process (`RUN su vscode -c "pytest -v /home/vscode/py-apps/tests/"`) but can also be run manually inside a running container instance. |
| 29 | + |
| 30 | +* **Run a single test file (inside the container):** |
| 31 | + ```bash |
| 32 | + pytest -v /home/vscode/py-apps/tests/<test_file.py> |
| 33 | + ``` |
| 34 | + Replace `<test_file.py>` with the actual path to the test file (e.g., `/home/vscode/py-apps/tests/test_imports.py`). |
| 35 | + |
| 36 | +* **Run a single test function within a file (inside the container):** |
| 37 | + ```bash |
| 38 | + pytest -v /home/vscode/py-apps/tests/<test_file.py>::<test_function_name> |
| 39 | + ``` |
| 40 | + Replace `<test_file.py>` and `<test_function_name>` accordingly. |
| 41 | + |
| 42 | +## 2. Code Style Guidelines |
| 43 | + |
| 44 | +Given that this is a container project, these guidelines focus on Dockerfile and `devcontainer.json` conventions. Python-specific code style is left to the individual Python projects that will utilize these devcontainers. |
| 45 | + |
| 46 | +### 2.1. Dockerfile Best Practices |
| 47 | + |
| 48 | +* **Multi-stage Builds**: Use multi-stage builds (as seen in the project's `Dockerfile`) to keep final images small and clean. |
| 49 | +* **Layer Caching**: Order instructions to leverage Docker's layer caching effectively. Place frequently changing instructions (like `COPY` application code) later in the Dockerfile. |
| 50 | +* **Minimize Layers**: Combine `RUN` commands using `&&` to reduce the number of layers. |
| 51 | +* **Clean Up**: Always clean up temporary files and caches (`apt-get clean`, `rm -rf /var/lib/apt/lists/*`, etc.) at the end of `RUN` commands to reduce image size. |
| 52 | +* **Security**: Follow security best practices, such as running processes with a non-root user (`remoteUser: "vscode"`, `su vscode -c "..."`). |
| 53 | +* **Clarity**: Use comments where necessary to explain complex steps. |
| 54 | + |
| 55 | +### 2.2. `devcontainer.json` Guidelines |
| 56 | + |
| 57 | +* **Image Specification**: Clearly define the base image (`"image"`). |
| 58 | +* **Run Arguments**: Include necessary `runArgs` for container security and user namespace management (`--userns=keep-id`, `--security-opt label=disable`). |
| 59 | +* **Remote User**: Specify `"remoteUser"` to ensure development is done with appropriate user permissions (e.g., `"vscode"`). |
| 60 | +* **VS Code Settings**: |
| 61 | + * Configure `python.defaultInterpreterPath` to point to the correct Python interpreter within the container. |
| 62 | + * Set `python.languageServer` (e.g., `"Pylance"`). |
| 63 | + * Manage extension behavior: set `"extensions.ignoreRecommendations": true`, `"extensions.autoUpdate": false`, and `"extensions.autoCheckUpdates": false` for controlled offline environments. |
| 64 | + * Control extension syncing with `remote.extensionKind`. |
| 65 | +* **`updateRemoteUserUID`**: Set to `true` to ensure user IDs are correctly synchronized. |
| 66 | + |
| 67 | +### 2.3. Git Flow Conventions |
| 68 | + |
| 69 | +The project adheres to the `git-flow` branching model: |
| 70 | + |
| 71 | +* **`develop` Branch**: Main development branch for new features. |
| 72 | +* **`feature` Branches**: For new features, branched from `develop` and merged back into `develop`. Use `git flow feature start <feature-name>`. |
| 73 | +* **`release` Branch**: Contains official release history. Created from `develop` for release preparation and merged into `release` and `develop`. Use `git flow release start <version>`. |
| 74 | +* **`hotfix` Branches**: For urgent bug fixes on `release`. Branched from `release` and merged into both `release` and `develop`. Use `git flow hotfix start <hotfix-name>`. |
| 75 | +* **`bugfix` Branches**: For new bug fixes. Branched from `develop` and merged back into `develop`. Use `git flow bugfix start <bugfix-name>`. |
| 76 | + |
| 77 | +### 2.4. General Project Conventions |
| 78 | + |
| 79 | +* **Documentation**: Ensure `README.md` and `CONTRIBUTORS.md` are kept up-to-date. |
| 80 | +* **Dependency Management**: Python dependencies are managed via `requirements.txt`. Any additions should be made there and trigger a Docker image rebuild. |
| 81 | +* **Offline Focus**: All configurations and scripts should prioritize and support the offline/air-gapped nature of the development environment. |
0 commit comments