Skip to main content
Integrate uv into your GitLab CI/CD pipelines for efficient Python dependency management.

Using uv Docker Images

1

Select a base image

Use one of the official uv Docker images. You can choose from distroless, Alpine, or Debian-based images:
2

For distroless images

When using distroless images, specify the entrypoint:

Pipeline Configuration

Here’s a complete example pipeline:

Caching Dependencies

Persist the uv cache between pipeline runs to improve performance:
Use uv cache prune --ci to reduce cache size. See the cache documentation for more details.

Advanced Caching

Cache based on both lockfile and Python version:

Matrix Testing

Test across multiple Python versions:

Using uv pip

For workflows using the uv pip interface, enable system Python:
When using uv pip, consider using requirements.txt or pyproject.toml instead of uv.lock in your cache key.

Installing uv in Custom Images

If you need to use a custom base image:

Complete Example with Multiple Stages

Best Practices

  • Pin versions: Always specify exact versions for UV_VERSION and PYTHON_VERSION
  • Use cache: Enable caching to speed up pipeline runs
  • Set UV_LINK_MODE: Use copy mode since GitLab creates separate mountpoints
  • Prune cache: Run uv cache prune --ci in after_script to optimize cache size
  • Cache key: Use uv.lock as the cache key for projects, requirements.txt for pip workflows