Skip to content

Conversation

@lars20070
Copy link
Contributor

@lars20070 lars20070 commented Nov 25, 2025

The pull request adds a new dev container for pydantic-ai. It is built using a hybrid approach: the Dockerfile provides low-level customization, while devcontainer.json is used for fine-tuning and IDE integration. Minor changes to devcontainer.json do not require a full rebuild of the entire image, which speeds up the development workflow.

  1. The Dockerfile is based on Microsoft's Debian-style Trixie image for Python 3.12. It uses a non-root user named vscode and installs system dependencies, uv, and the Ollama client. Note that the Ollama instance runs on the host machine for performance reasons.

  2. The devcontainer.json is based on Microsoft's dev container template for Python 3. It installs additional development tools via features, sets important environment variables, and runs uv sync. The container does not enforce any specific IDE configuration; developers are encouraged to mount their own .vscode/ or .cursor/ folders externally.

Added

  • dev container with Dockerfile and devcontainer.json
  • CI integration

@lars20070
Copy link
Contributor Author

@dsfaccini In the beginning, I had thought accessing the Ollama host instance with ollama list and ollama run from inside the container would be convenient. But I have now removed the Ollama CLI entirely. I agree that this is cleaner.

  1. .env.example is a very good point. I have added it to the root directory.

  2. Apologies for the flaky test comments. During early stages of the dev container setup I had seen these tests failing. But I have not been able to reproduce the failing tests since.

  3. I have copied further configs from your branch to devcontainer.json. Most likely there are more missing, and I would appreciate your input.

  4. I have configured MCP servers in .vscode and .cursor which are mounted externally. Works fine in my tests with Context7 and GitHub. In the IDE and MCP setup, I would leave as much as possible to the user.

Thanks for your good comments so far. Hope together we can find a stable and minimal dev container setup. Would be helpful for new contributers to get started.

@@ -0,0 +1,27 @@
ARG PYTHON_VERSION=3.11
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use 3.12 as in .python-version

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Changed to 3.12.

# Enable Docker BuildKit for cache mounts
ENV DOCKER_BUILDKIT=1

# Install system dependencies with cache mount for faster rebuilds (pinned versions)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pinning means we'll probably never update these; could we not pin even if that means the cache would be invalidated more often?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Unrelated to cache. This was for sake of reproducibility and avoid "works on my machine" issues.

I have changed the pinned to latest versions. Less maintenance. I do not expect problems here.

@@ -0,0 +1,36 @@
## Requirements

Please ensure that both [Docker](https://docs.docker.com/desktop/) and optionally [Ollama](https://ollama.com/download) are installed and running on the host machine. To configure your IDE, mount your own `.vscode/` or `.cursor/` folders by uncommenting the `mounts` section in `devcontainer.json`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"ensure that both X and optionally Y" is a bit contradictory :) I'd rather have hard requirements, and then some section on optional things

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Fixed.


The dev container is built using a hybrid approach: the `Dockerfile` provides low-level customization, while `devcontainer.json` is used for fine-tuning and IDE integration. Minor changes to `devcontainer.json` do not require a full rebuild of the entire image, which speeds up the development workflow.

1. The `Dockerfile` is based on Microsoft's Debian-style [Bookworm image for Python 3.11](https://hub.docker.com/r/microsoft/devcontainers-python). It uses a non-root user named `vscode` and installs system dependencies and `uv`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3.12 please!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/python
{
"name": "Python 3",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pydantic AI?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

# ============================================================================

# OpenAI (Required for: OpenAI models, OpenAI-compatible providers)
# Get your key at: https://platform.openai.com/api-keys
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will get outdated, I'd rather just link to the docs for the provider in question


# Brave Search (Optional - for web search tools)
# Get your key at: https://brave.com/search/api/
# BRAVE_API_KEY=
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have anything Brave related in Pydantic AI

# GitHub Personal Access Token (Optional - for MCP GitHub server)
# Create at: https://github.com/settings/tokens
# Needs: repo, read:org scopes
# GITHUB_PERSONAL_ACCESS_TOKEN=
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't auto install this so we shouldn't have this


# PostgreSQL with pgvector (Optional - for RAG examples)
# Default when using docker-compose pgvector service:
# PGVECTOR_DATABASE_URL=postgresql://postgres:postgres@localhost:54321/postgres
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather this file stick to the point, so we don't have to struggle to keep it up to date when we add examples etc. If the example docs states to set a given env var, the user can figure out how to do that in the devcontainer.

For maintenance burden reasons, let's limit this file to the most popular providers; the user can figure out how to set the rest.

# - For testing, use test models or Ollama to avoid API costs
# - Never commit this file with real API keys
# - Add .env to .gitignore (already done in this project)
# - See README.md for detailed setup instructions per provider
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should direct them to the docs shouldn't it?

@DouweM DouweM self-assigned this Nov 28, 2025
@DouweM DouweM changed the title dev container Add devcontainer Nov 28, 2025
make lint
make typecheck
make test
echo "Dev container built and run successfully"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it stands, this CI step will always succeed, even if any of the steps above failed.

For example, on this PR the output currently shows this error, even though the step shows as green:

Coverage failure: total of 99.99 is less than fail-under=100.00
  • Can we please fix this job to fail when any of the steps fail?
  • Can we get coverage to 100%? (or mark the uncovered lines as pragma: lax no cover if we can't)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CI job can now fail, see set -o errexit. Coverage is now 100%.

@lars20070
Copy link
Contributor Author

lars20070 commented Dec 1, 2025

@DouweM Thanks for the helpful comments. They resulted in some major changes. The biggest is the switch from a bookworm to a trixie base image. This upgrade provides SQLite 3.46.1 which is required by DBOS 2.0.0.

For .env.example I would still require your help, since I do not have a valid .env myself. See comments above.

@lars20070 lars20070 requested a review from DouweM December 1, 2025 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants