Skip to content

Commit 2db1113

Browse files
committed
chore(common): add build script to the pipeline
1 parent 8b92e9f commit 2db1113

4 files changed

Lines changed: 124 additions & 31 deletions

File tree

.github/workflows/pipeline.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
run: go install github.com/cloudfoundry/libbuildpack/packager/buildpack-packager@latest
6161

6262
- name: Package buildpack
63-
run: buildpack-packager build -cached -any-stack
63+
run: make build
6464

6565
release-buildpack:
6666
name: Release Buildpack

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
__pycache__
2-
.venv
2+
.venv
3+
python-uv_buildpack-*

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,8 @@ smoke-test:
4848

4949
# Run all lightweight script-level unit tests together.
5050
unit-test:
51-
@./scripts/unit-test.sh
51+
@./scripts/unit-test.sh
52+
53+
# Build a cached buildpack artifact for testing with `pack` and `pack build`.
54+
build:
55+
@buildpack-packager build -cached -any-stack

README.md

Lines changed: 116 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
# Cloud Foundry UV Python Buildpack
22

3-
The current cloud foundry [python-buildpack](https://github.com/cloudfoundry/python-buildpack) doesn't support modern python tools, such as [uv](https://docs.astral.sh/uv/), so I created this custom buildpack to bridge the gap.
3+
The standard Cloud Foundry [python-buildpack](https://github.com/cloudfoundry/python-buildpack) does not focus on modern Python workflows built around [uv](https://docs.astral.sh/uv/). This custom buildpack fills that gap by detecting uv-managed applications, installing a managed Python runtime, and staging locked dependencies for Cloud Foundry.
44

5-
## Installation
5+
## What this buildpack expects
66

7-
## How to use
7+
For an app to be detected by this buildpack, it must include:
88

9+
- `pyproject.toml`
10+
- `uv.lock`
911

10-
### Defining the initialization script
12+
If the app includes a `.python-version` file, the buildpack uses that version when installing Python.
1113

12-
This buildpack detects uv-managed apps when both `pyproject.toml` and `uv.lock` are present.
14+
## How startup is chosen
1315

14-
At staging time, `bin/compile` exports the locked dependencies from `uv.lock`, installs them into `.python_packages`, and writes a `.profile.d/python.sh` file so the app can import those staged packages at runtime. If the app uses a `src/` layout, that `src/` directory is also added to `PYTHONPATH`.
16+
At release time, the buildpack chooses the web command in this order:
1517

16-
At release time, `bin/release` chooses the web command in this order:
17-
18-
1. If the app has a `Procfile`, the buildpack does not generate a default process type and Cloud Foundry uses the `Procfile`.
19-
2. If `pyproject.toml` exists and `[project.scripts]` contains a script named exactly the same as `[project].name`, that script is used.
20-
3. Otherwise, if `[project.scripts]` contains a `start` script, that script is used.
18+
1. If the app has a `Procfile`, Cloud Foundry uses it directly.
19+
2. Otherwise, if `pyproject.toml` defines a console script whose name matches `[project].name`, that script is used.
20+
3. Otherwise, if `[project.scripts]` defines `start`, that script is used.
2121
4. Otherwise, if `main.py` exists, the buildpack uses `python3 main.py`.
2222
5. Otherwise, if `app.py` exists, the buildpack uses `python3 app.py`.
23-
6. If none of the above are present, the buildpack emits an empty `web` process and you must provide your own entrypoint.
2423

25-
For `pyproject.toml` scripts, the buildpack converts a console-script target such as:
24+
For example, this `pyproject.toml`:
2625

2726
```toml
2827
[project]
@@ -33,15 +32,90 @@ my-app = "server.main:run"
3332
start = "server.main:start"
3433
```
3534

36-
into a process command like:
35+
becomes:
3736

3837
```sh
3938
python3 -c "from server.main import run; run()"
4039
```
4140

42-
In the example above, `my-app` wins over `start` because it matches `[project].name`.
41+
## Installing the buildpack
42+
43+
### Option 1: Use a packaged buildpack zip directly
44+
45+
Package the buildpack from the repository root:
46+
47+
```sh
48+
make build
49+
```
50+
51+
Then deploy an app with the generated zip:
4352

44-
## Testing Locally
53+
```sh
54+
cf push my-app -p path/to/app -b /full/path/to/python-uv_buildpack-cached-vX.Y.Z.zip
55+
```
56+
57+
If you use a manifest, you can also pass the buildpack zip on the command line:
58+
59+
```sh
60+
cf push -f manifest.yml -b /full/path/to/python-uv_buildpack-cached-vX.Y.Z.zip
61+
```
62+
63+
### Option 2: Upload the buildpack to Cloud Foundry once
64+
65+
Create a reusable named buildpack in your foundation:
66+
67+
```sh
68+
cf create-buildpack python-uv-buildpack python-uv_buildpack-cached-v1.0.10.zip 1 --enable
69+
```
70+
71+
Then deploy apps with:
72+
73+
```sh
74+
cf push my-app -b python-uv-buildpack
75+
```
76+
77+
Or in `manifest.yml`:
78+
79+
```yaml
80+
---
81+
applications:
82+
- name: my-app
83+
path: .
84+
buildpacks:
85+
- python-uv-buildpack
86+
```
87+
88+
### Option 3: Use a published GitHub Release artifact
89+
90+
If you publish packaged buildpack zips in GitHub Releases, you can deploy with a release URL:
91+
92+
```sh
93+
cf push my-app -b https://github.com/NickChecan/uv-python-buildpack/releases/download/vX.Y.Z/python-uv_buildpack-cached-vX.Y.Z.zip
94+
```
95+
96+
## Example app manifests
97+
98+
If you pass the buildpack with `cf push -b ...`, you do not need a `buildpacks:` entry in the app manifest.
99+
100+
Example:
101+
102+
```yaml
103+
---
104+
applications:
105+
- name: my-app
106+
path: .
107+
memory: 256M
108+
disk_quota: 512M
109+
instances: 1
110+
```
111+
112+
Then:
113+
114+
```sh
115+
cf push -f manifest.yml -b ../../python-uv_buildpack-cached-vX.Y.Z.zip
116+
```
117+
118+
## Testing locally
45119

46120
Run the buildpack test flow from the repository root:
47121

@@ -51,42 +125,56 @@ make test-buildpack
51125

52126
This command:
53127

54-
- stages `test/my-app-*` into a temporary build directory
128+
- stages the sample app into a temporary build directory
55129
- runs `bin/detect`
56130
- runs `bin/compile`
57-
- verifies the staged dependencies can be imported
131+
- verifies the staged dependencies are importable
58132
- prints the `bin/release` output
59133

60-
You can also run other smoke test projects by specifying its directory. For example:
134+
You can run a different smoke fixture by passing its directory:
61135

62136
```sh
63137
make test-buildpack APP_DIR=test/smoke/my-app-2
64138
```
65139

66-
If you want to remove the temporary staging directories before or after a run:
140+
To clean the temporary staging directories:
67141

68142
```sh
69143
make clean-test-buildpack
70144
```
71145

72-
If you want to start the staged sample app locally after `make test-buildpack` succeeds:
146+
To start the staged sample app locally after a successful test build:
73147

74148
```sh
75149
make start-local
76150
```
77151

78152
Then open `http://127.0.0.1:8000/`.
79153

80-
## How to Contribute
154+
To run the full unit test suite:
155+
156+
```sh
157+
make unit-test
158+
```
159+
160+
To run all smoke fixtures:
161+
162+
```sh
163+
make smoke-test
164+
```
165+
166+
See the project [Makefile](./Makefile) for the supported local commands.
167+
168+
## Contributing
81169

82-
Contributions are welcome! Here's how you can get involved:
170+
Contributions are welcome.
83171

84-
1. **Report Issues:** Found a bug or have a feature request? [Open an issue](https://github.com/NickChecan/uv-python-buildpack/issues). <br />
85-
2. **Submit Pull Requests:** Fork the repository, create a new branch, make your changes, and submit a PR. <br />
86-
3. **Improve Documentation:** Help improve the README or add examples to make setup easier. <br />
87-
4. **Test & Feedback:** Try Model Mux and provide feedback.
172+
1. Report bugs or request features by opening an [issue](https://github.com/NickChecan/uv-python-buildpack/issues).
173+
2. Fork the repository, create a branch, make your changes, and open a pull request.
174+
3. Improve the documentation or examples to make the buildpack easier to adopt.
175+
4. Run the local tests before submitting changes when possible.
88176

89177
## License
90178

91179
Copyright (c) 2026 Nicholas Coutinho Checan.
92-
Licensed under the MIT License. See [LICENSE](./LICENSE).
180+
Licensed under the MIT License. See [LICENSE](./LICENSE).

0 commit comments

Comments
 (0)