Skip to content

Commit dd2bcfe

Browse files
committed
chore(common): add makefile for test scripts
1 parent f3c9f0c commit dd2bcfe

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

Makefile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
APP_DIR := test/my-app
2+
BUILD_DIR := /tmp/uv-bp-build
3+
CACHE_DIR := /tmp/uv-bp-cache
4+
ENV_DIR := /tmp/uv-bp-env
5+
ROOT_DIR := $(CURDIR)
6+
BUILDPACK_DIR := $(ROOT_DIR)
7+
PYTHON_BIN ?= python3
8+
9+
.PHONY: test-buildpack clean-test-buildpack start-local
10+
11+
# Reset the temporary staging directories used for local buildpack testing.
12+
clean-test-buildpack:
13+
rm -rf $(BUILD_DIR) $(CACHE_DIR) $(ENV_DIR)
14+
15+
# Run the sample app through detect, compile, and release using the same
16+
# temporary directories each time so local testing is repeatable.
17+
test-buildpack: clean-test-buildpack
18+
mkdir -p $(BUILD_DIR) $(CACHE_DIR) $(ENV_DIR)
19+
cp -R $(APP_DIR)/. $(BUILD_DIR)
20+
cd $(APP_DIR) && ../../bin/detect
21+
$(BUILDPACK_DIR)/bin/compile $(BUILD_DIR) $(CACHE_DIR) $(ENV_DIR)
22+
cd $(BUILD_DIR) && /bin/bash -lc 'source .profile.d/python.sh && $(PYTHON_BIN) -c "import fastapi; print(fastapi.__version__)"'
23+
cd $(BUILD_DIR) && $(BUILDPACK_DIR)/bin/release
24+
25+
# Start the staged sample app locally using the dependencies prepared by `test-buildpack`.
26+
start-local:
27+
cd $(BUILD_DIR) && /bin/bash -lc 'source .profile.d/python.sh && $(PYTHON_BIN) main.py'

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,32 @@
22

33
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.
44

5+
## Testing Locally
6+
7+
Run the buildpack test flow from the repository root:
8+
9+
```sh
10+
make test-buildpack
11+
```
12+
13+
This command:
14+
15+
- stages `test/my-app` into a temporary build directory
16+
- runs `bin/detect`
17+
- runs `bin/compile`
18+
- verifies the staged dependencies can be imported
19+
- prints the `bin/release` output
20+
21+
If you want to remove the temporary staging directories before or after a run:
22+
23+
```sh
24+
make clean-test-buildpack
25+
```
26+
27+
If you want to start the staged sample app locally after `make test-buildpack` succeeds:
28+
29+
```sh
30+
make start-local
31+
```
32+
33+
Then open `http://127.0.0.1:8000/`.

0 commit comments

Comments
 (0)