forked from astral-sh/uv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GitLab Integration documentation (astral-sh#6857)
<!-- Thank you for contributing to uv! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> ## Summary Documentation for GitLab integration, reliant on the new tags introduced in astral-sh#6053 ## Test Plan <!-- How was it tested? --> --------- Co-authored-by: David Fritzsche <[email protected]> Co-authored-by: Zanie Blue <[email protected]>
- Loading branch information
1 parent
bc459c8
commit 267dda9
Showing
5 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Using uv in GitLab CI/CD | ||
|
||
## Using the uv image | ||
|
||
Astral provides [Docker images](docker.md#available-images) with uv preinstalled. | ||
Select a variant that is suitable for your workflow. | ||
|
||
```yaml title="gitlab-ci.yml | ||
variables: | ||
UV_VERSION: 0.4 | ||
PYTHON_VERSION: 3.12 | ||
BASE_LAYER: bookworm-slim | ||
|
||
stages: | ||
- analysis | ||
|
||
UV: | ||
stage: analysis | ||
image: | ||
name: ghcr.io/astral-sh/uv:$UV_VERSION-python$PYTHON_VERSION-$BASE_LAYER | ||
script: > | ||
cd $CI_PROJECT_DIR | ||
# your `uv` commands | ||
``` | ||
## Caching | ||
Persisting the uv cache between workflow runs can improve performance. | ||
```yaml | ||
UV Install: | ||
variables: | ||
UV_CACHE_DIR: /tmp/.uv-cache | ||
cache: | ||
- key: | ||
files: | ||
- uv.lock | ||
paths: | ||
- $UV_CACHE_DIR | ||
steps: > | ||
# Your uv commands | ||
run: uv cache prune --ci | ||
``` | ||
See the [GitLab caching documentation](https://docs.gitlab.com/ee/ci/caching/) for more details on | ||
configuring caching. | ||
Using `uv cache prune --ci` at the end of the job is recommended to reduce cache size. See the [uv | ||
cache documentation](../../concepts/cache.md#caching-in-continuous-integration) for more details. | ||
|
||
## Using `uv pip` | ||
|
||
If using the `uv pip` interface instead of the uv project interface, uv requires a virtual | ||
environment by default. To allow installing packages into the system environment, use the `--system` | ||
flag on all uv invocations or set the `UV_SYSTEM_PYTHON` variable. | ||
|
||
The `UV_SYSTEM_PYTHON` variable can be defined in at different scopes. You can read more about | ||
how [variables and their precedence works in GitLab here](https://docs.gitlab.com/ee/ci/variables/) | ||
|
||
Opt-in for the entire workflow by defining it at the top level: | ||
|
||
```yaml title="gitlab-ci.yml" | ||
variables: | ||
UV_SYSTEM_PYTHON: 1 | ||
# [...] | ||
``` | ||
|
||
To opt-out again, the `--no-system` flag can be used in any uv invocation. | ||
|
||
When persisting the cache, you may want to use `requirement.txt` or `pyproject.toml` as | ||
your cache key files instead of `uv.lock`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters