Skip to content

Feature/ollama service#59

Merged
jansaldo merged 3 commits intorelease/v2.0.0from
feature/ollama-service
Nov 19, 2025
Merged

Feature/ollama service#59
jansaldo merged 3 commits intorelease/v2.0.0from
feature/ollama-service

Conversation

@jansaldo
Copy link
Copy Markdown
Contributor

@jansaldo jansaldo commented Nov 19, 2025

This pull request adds support for managing an Ollama service as part of the development and deployment workflow. The changes introduce a new Ollama container to the Docker Compose setup, provide Makefile commands for common Ollama operations, and integrate Ollama startup into the VSCode development environment.

Docker and service integration:

  • Added an ollama service to docker-compose.yml with GPU support, persistent storage, and automatic restart, and made API services depend on it to ensure proper startup order. [1] [2] [3]

Developer tooling and automation:

  • Introduced multiple Makefile targets for managing the Ollama service and models (start, stop, restart, pull, run, list, and remove), streamlining development and model management workflows.
  • Added a VSCode task (tasks.json) to start the Ollama service using the new Makefile command, and configured the Python launch configuration to run this task before debugging. [1] [2]

Summary by Sourcery

Integrate an Ollama service into the development workflow by adding it to Docker Compose, providing Makefile commands for model management, and automating its startup in VSCode.

New Features:

  • Add Ollama service to docker-compose.yml with GPU support, persistent storage, and restart policy
  • Introduce Makefile targets for starting, stopping, restarting, and managing Ollama models (pull, run, list, remove)
  • Configure VSCode tasks and pre-launch setup to automatically start the Ollama service before debugging

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Nov 19, 2025

Reviewer's Guide

This PR integrates an Ollama service into the development workflow by adding it to Docker Compose with GPU support and persistent storage, exposing Makefile commands for Ollama operations, and configuring VSCode to start Ollama automatically before debugging.

Flow diagram for Makefile Ollama commands

flowchart TD
  A["Developer runs Makefile command"] --> B{"Which command?"}
  B -->|ollama-up| C["Start Ollama container"]
  B -->|ollama-stop| D["Stop Ollama container"]
  B -->|ollama-restart| E["Restart Ollama container"]
  B -->|ollama-pull| F["Pull model in Ollama container"]
  B -->|ollama-run| G["Run model in Ollama container"]
  B -->|ollama-list| H["List models in Ollama container"]
  B -->|ollama-rm| I["Remove model from Ollama container"]
Loading

File-Level Changes

Change Details Files
Introduce Ollama service in Docker Compose with GPU, volume, and restart policies
  • Added new ollama service block with image, ports, volumes, and restart
  • Configured NVIDIA GPU reservation under deploy.resources
  • Declared persistent volume for Ollama data
  • Updated API services to depend_on ollama for startup ordering
docker-compose.yml
Add Makefile targets to manage Ollama lifecycle and models
  • Defined ollama-up, ollama-stop, and ollama-restart targets
  • Implemented ollama-pull, ollama-run, ollama-list, and ollama-rm with MODEL parameter checks
  • Ensured service is up before executing exec commands
Makefile
Configure VSCode to launch Ollama service before debugging
  • Created tasks.json entry to run ‘make ollama-up’
  • Updated launch.json to include the Ollama startup task as preLaunchTask
.vscode/tasks.json
.vscode/launch.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR integrates Ollama as a containerized service into the development and deployment workflow. The changes add Docker Compose configuration for running Ollama with GPU support, provide developer-friendly Makefile commands for managing the service and models, and configure VSCode to automatically start Ollama before debugging.

  • Added Ollama service to docker-compose.yml with GPU support and persistent storage
  • Created Makefile targets for common Ollama operations (start, stop, pull, list models, etc.)
  • Integrated Ollama startup into VSCode debugging workflow via preLaunchTask

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
docker-compose.yml Adds Ollama service with GPU configuration, persistent volume, and makes API services depend on it
Makefile Introduces 7 new targets for managing Ollama service lifecycle and model operations
.vscode/tasks.json Defines "Start Ollama service" task that executes the Makefile ollama-up command
.vscode/launch.json Configures Python debugger to automatically start Ollama service before launching

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docker-compose.yml
Comment on lines +38 to +44
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

The Ollama service configuration assumes GPU availability via NVIDIA drivers, but there's no fallback configuration for CPU-only environments. This will cause the service to fail in environments without NVIDIA GPUs or proper drivers.

Consider adding a CPU-only profile or making GPU configuration optional:

ollama:
    image: ollama/ollama
    container_name: ollama
    profiles:
        - gpu
    deploy:
        resources:
            reservations:
                devices:
                    - driver: nvidia
                      count: all
                      capabilities: [gpu]
    # ... rest of config

ollama-cpu:
    image: ollama/ollama
    container_name: ollama
    profiles:
        - cpu
    # ... config without GPU requirements

Copilot uses AI. Check for mistakes.
Comment thread .vscode/launch.json
"subProcess": false,
"envFile": "${workspaceFolder}/.env",
"python": "${workspaceFolder}/.venv/bin/python"
"python": "${workspaceFolder}/.venv/bin/python",
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

[nitpick] The preLaunchTask "Start Ollama service" will run every time you start debugging in VSCode, but the task doesn't check if Ollama is already running. The --no-recreate flag in the Makefile will prevent recreating existing containers, but the task will still execute and potentially cause delays or confusion if it fails.

Consider adding task properties to handle this better:

{
    "label": "Start Ollama service",
    "type": "shell",
    "command": "make",
    "args": ["ollama-up"],
    "options": {
        "cwd": "${workspaceFolder}"
    },
    "problemMatcher": [],
    "isBackground": false,
    "presentation": {
        "reveal": "silent",
        "panel": "shared"
    }
}

This makes the task output less intrusive when Ollama is already running.

Suggested change
"python": "${workspaceFolder}/.venv/bin/python",
"python": "${workspaceFolder}/.venv/bin/python",
// NOTE: To avoid intrusive output and redundant execution, ensure the "Start Ollama service" task in .vscode/tasks.json uses:
// "presentation": { "reveal": "silent", "panel": "shared" }

Copilot uses AI. Check for mistakes.
Comment thread docker-compose.yml
Comment on lines +35 to +52
ollama:
image: ollama/ollama
container_name: ollama
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
ports:
- "11434:11434"
volumes:
- ollama:/root/.ollama
restart: always

volumes:
ollama:
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

The Ollama integration is missing documentation. The README should be updated to explain:

  1. That Ollama is now a dependency and what it's used for
  2. How to set up Ollama for development (including GPU requirements)
  3. Available Makefile commands for Ollama management
  4. How to configure which models to use
  5. How to run the API without Ollama (if applicable)

This is especially important since the Quick Start section shows docker run commands that won't include the Ollama service, potentially causing confusion for users.

Copilot uses AI. Check for mistakes.
Comment thread docker-compose.yml
Comment on lines +6 to +7
depends_on:
- ollama
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

The depends_on directive only ensures startup order, not readiness. The API services will start as soon as the Ollama container starts, but Ollama may not be ready to accept requests yet. Consider using a health check or wait-for script to ensure Ollama is actually ready before the API services attempt to connect to it.

Example with healthcheck:

ollama:
    image: ollama/ollama
    healthcheck:
        test: ["CMD", "ollama", "list"]
        interval: 10s
        timeout: 5s
        retries: 5
    # ... rest of config

aymurai-api:
    depends_on:
        ollama:
            condition: service_healthy

Copilot uses AI. Check for mistakes.
Comment thread Makefile
ifndef MODEL
$(error MODEL variable is required, e.g. make ollama-run MODEL=llama3)
endif
docker compose up -d --no-recreate ollama
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

The -it flag in docker compose exec -it requires an interactive terminal, which will cause this Makefile target to fail when run in non-interactive environments (CI/CD pipelines, automated scripts, VSCode tasks, etc.). Consider removing the -it flag or providing separate targets for interactive and non-interactive use.

Recommended change:

ollama-run:
ifndef MODEL
	$(error MODEL variable is required, e.g. make ollama-run MODEL=llama3)
endif
	docker compose up -d --no-recreate ollama
	docker compose exec ollama ollama run $(MODEL)

Or add a separate interactive target:

ollama-run-interactive:
ifndef MODEL
	$(error MODEL variable is required, e.g. make ollama-run-interactive MODEL=llama3)
endif
	docker compose up -d --no-recreate ollama
	docker compose exec -it ollama ollama run $(MODEL)
Suggested change
docker compose up -d --no-recreate ollama
docker compose up -d --no-recreate ollama
docker compose exec ollama ollama run $(MODEL)
ollama-run-interactive:
ifndef MODEL
$(error MODEL variable is required, e.g. make ollama-run-interactive MODEL=llama3)
endif
docker compose up -d --no-recreate ollama

Copilot uses AI. Check for mistakes.
Comment thread docker-compose.yml
Comment on lines +6 to +7
depends_on:
- ollama
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

The API services have a hard dependency on Ollama being available, but there's no evidence in the codebase that the API actually uses Ollama (no imports found, no Ollama-related configuration). This creates an unnecessary runtime dependency that will prevent the API from starting if Ollama fails.

If Ollama is optional or only used for specific features, consider:

  1. Making the depends_on conditional or removing it
  2. Implementing graceful degradation in the API code when Ollama is unavailable
  3. Adding connection retry logic with appropriate timeouts

If Ollama is truly required, ensure the API code properly handles connection failures and documents this dependency.

Copilot uses AI. Check for mistakes.
@jansaldo jansaldo merged commit 401a08b into release/v2.0.0 Nov 19, 2025
6 of 7 checks passed
@jansaldo jansaldo deleted the feature/ollama-service branch November 19, 2025 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants