Skip to content

Commit

Permalink
PHP SDK Relay Server (#62)
Browse files Browse the repository at this point in the history
* PHP testing app
* script to build and launch using a ref of the SDK
* Dockeration
* release script
* healthcheck
* readme
  • Loading branch information
typotter authored Oct 23, 2024
1 parent 6a8c052 commit 073afbb
Show file tree
Hide file tree
Showing 15 changed files with 3,264 additions and 0 deletions.
7 changes: 7 additions & 0 deletions package-testing/php-sdk-relay/.env.EXAMPLE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Set your appropriate values and save as `.env`
EPPO_API_HOST=localhost
EPPO_API_PORT=5000
EPPO_API_KEY=A123456780

SDK_RELAY_HOST=localhost
SDK_RELAY_PORT=4000
2 changes: 2 additions & 0 deletions package-testing/php-sdk-relay/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
vendor
32 changes: 32 additions & 0 deletions package-testing/php-sdk-relay/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM php:8.1

# dependencies needed for composer (and for build-and-run.sh).
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip


COPY --from=composer /usr/bin/composer /usr/bin/composer

WORKDIR /relayapp

COPY . .

COPY --chmod=755 build-and-run.sh /

RUN composer install

ENV SDK_RELAY_HOST=0.0.0.0
ENV EPPO_API_HOST=host.docker.internal

EXPOSE $SDK_RELAY_PORT

HEALTHCHECK CMD curl --fail http://localhost:${SDK_RELAY_PORT} || exit 1


CMD ["/build-and-run.sh"]
45 changes: 45 additions & 0 deletions package-testing/php-sdk-relay/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# PHP Testing Server

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

## Setup
Open `.env.EXAMPLE`, set appropriate config values and then save it as `.env`

## Running

### Locally

```shell
BASH_ENV=.env SDK_REF=<your branch/tag/SHA> ./build-and-run.sh
```

### With Docker
#### Build Docker Image
```shell
docker build -t Eppo-exp/php-sdk-relay .
```

#### Run the docker container
```shell
./docker-run.sh
```

## Development

### Running locally

```shell
php -S localhost:4000 src/index.php
```

### Testing the relay server

Use this [Postman collection](https://www.postman.com/material-meteorologist-42730907/typotter-eppo/collection/5bjhdzy/relay-server-testing)

### Build and Tag a new Docker image
_nb: not really needed as this target will need to be built on every run of the test cluster against this SDK, but
useful for development along the way nonetheless_

```shell
./release.sh <version>
```
28 changes: 28 additions & 0 deletions package-testing/php-sdk-relay/build-and-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

composer install

# Set default values for vars

: "${SDK_REF:=main}"
: "${SDK_RELAY_HOST:=localhost}"
: "${SDK_RELAY_PORT:=4000}"
SDK="https://github.com/Eppo-exp/php-sdk.git"


# checkout the specified ref of the SDK repo, build it, and then insert it into vendors here.
mkdir -p tmp

echo "Cloning ${SDK}@${SDK_REF}"
git clone -b ${SDK_REF} --depth 1 --single-branch ${SDK} tmp || ( echo "Cloning repo failed"; exit 1 )

# overwrite vendor files
cp -Rf tmp/. ./vendor/eppo/php-sdk/
rm -Rf tmp

# Run the poller
php src/eppo_poller.php &

echo "Listening on port ${SDK_RELAY_PORT}"

php -S "0.0.0.0:${SDK_RELAY_PORT}" -t src
35 changes: 35 additions & 0 deletions package-testing/php-sdk-relay/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "eppo/php-sdk-test",
"description": "Test server using the PHP SDK",
"type": "project",
"license": "MIT",
"homepage": "https://github.com/Eppo-exp/sdk-test-data",
"minimum-stability": "stable",
"autoload": {
"psr-4": {
"Eppo\\SDKTest\\": "src/"
}
},
"authors": [
{
"name": "Ty Potter",
"email": "[email protected]"
}
],
"require": {
"php": "^8.1",
"eppo/php-sdk": "^3.2",
"vlucas/phpdotenv": "^5.6",
"php-http/curl-client": "^2.3",
"nyholm/psr7": "^1.8",
"slim/slim": "^4.14",
"slim/psr7": "^1.7",
"php-di/php-di": "^7.0",
"slim/http": "^1.4"
},
"config": {
"allow-plugins": {
"php-http/discovery": true
}
}
}
Loading

0 comments on commit 073afbb

Please sign in to comment.