Skip to content

Commit 5c2b812

Browse files
add build-and-run.sh to python relay server (#98)
* add build-and-run.sh to python relay server * refactor dockerfile to build wheel * requirements * SDK_RELAY_HOST * hardcode to 0.0.0.0 * python fixes and run in venv * do not hardcore url * only works with 0.0.0.0
1 parent 1fa74e4 commit 5c2b812

File tree

8 files changed

+64
-53
lines changed

8 files changed

+64
-53
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SDK_REF=main
2+
SDK_RELAY_HOST=localhost
3+
SDK_RELAY_PORT=4000
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
bin
22
lib
3-
venv
3+
.venv
4+
tmp

package-testing/python-sdk-relay/Dockerfile

Lines changed: 0 additions & 11 deletions
This file was deleted.

package-testing/python-sdk-relay/README.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,8 @@
22

33
Post test case files to this server and check the results against what's expected.
44

5-
## Running locally with Docker
6-
7-
Build the docker image:
8-
9-
```shell
10-
docker build -t Eppo-exp/python-sdk-relay .
11-
```
12-
13-
Run the docker container:
5+
## Build and run
146

157
```shell
16-
./docker-run.sh
8+
./build-and-run.sh
179
```
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env bash
2+
3+
# Set default values for vars
4+
5+
: "${SDK_REF:=main}"
6+
: "${SDK_RELAY_HOST:=localhost}"
7+
: "${SDK_RELAY_PORT:=4000}"
8+
SDK="https://github.com/Eppo-exp/eppo-multiplatform.git"
9+
10+
# Create a persistent virtual environment.
11+
if [ ! -d ".venv" ]; then
12+
python3 -m venv .venv
13+
fi
14+
source .venv/bin/activate
15+
16+
# checkout the specified ref of the SDK repo, build it, and then insert it into vendors here.
17+
rm -rf tmp
18+
mkdir -p tmp
19+
20+
echo "Cloning ${SDK}@${SDK_REF}"
21+
git clone -b ${SDK_REF} --depth 1 --single-branch ${SDK} tmp || ( echo "Cloning repo failed"; exit 1 )
22+
23+
# TODO: Refactor this into a `build.sh` script that resides in the SDK repo.
24+
25+
# install dependencies
26+
27+
pip install maturin
28+
pip install -r requirements.txt
29+
30+
# Build the wheel file in tmp directory
31+
maturin build --release --out tmp/dist --find-interpreter --manifest-path ./tmp/python-sdk/Cargo.toml
32+
33+
# Get Python version and find matching wheel
34+
PYTHON_VERSION=$(python3 -c 'import sys; print(f"cp{sys.version_info.major}{sys.version_info.minor}")')
35+
echo "Looking for wheel for Python version: ${PYTHON_VERSION}"
36+
37+
WHEEL_FILE=$(find tmp/dist -name "eppo_server_sdk-*-${PYTHON_VERSION}-*.whl" | head -n 1)
38+
echo "Found wheel file: ${WHEEL_FILE}"
39+
40+
if [ -z "$WHEEL_FILE" ]; then
41+
echo "Error: Wheel file not found for Python version ${PYTHON_VERSION}"
42+
echo "Available wheels:"
43+
ls tmp/dist
44+
exit 1
45+
fi
46+
47+
pip install "${WHEEL_FILE}"
48+
49+
# cleanup
50+
rm -rf tmp
51+
52+
# start the relay server
53+
echo "Listening on port ${SDK_RELAY_HOST}:${SDK_RELAY_PORT}"
54+
python3 src/server.py

package-testing/python-sdk-relay/docker-run.sh

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
flask
2-
eppo-server-sdk==4.1.0
2+
# eppo-server-sdk installed from local wheel

package-testing/python-sdk-relay/src/server.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ def initialize_client_and_wait():
160160
initialize_client_and_wait()
161161

162162
port = int(environ.get('SDK_RELAY_PORT', 7001))
163-
host = environ.get('SDK_RELAY_HOST', '0.0.0.0')
163+
# host = environ.get('SDK_RELAY_HOST', '0.0.0.0')
164+
host = '0.0.0.0'
164165
print(f"Starting server on {host}:{port}")
165166
app.run(
166167
host=host,

0 commit comments

Comments
 (0)