Skip to content

Commit 7c70150

Browse files
authored
feat: SDK relay launch script options (#74)
* feat: robustify launch script and other preps to run on a GH runner
1 parent 5e5a736 commit 7c70150

File tree

3 files changed

+52
-6
lines changed

3 files changed

+52
-6
lines changed

package-testing/sdk-test-runner/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ FROM node:18-alpine
33
WORKDIR /app
44

55
COPY package.json ./
6+
COPY yarn.lock ./
67

78
RUN yarn install
89

package-testing/sdk-test-runner/README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ The following components are required to use the the package test runner with a
9393

9494
1. An **SDK relay server**. This is a REST server running at `localhost:4000` resonding to the [Asssignment and Bandit Request API](#sdk-relay-server)
9595
1. OR, an **SDK relay client**. This is a client application that connects to the SDK test runner via `socket.io` and responses to [Assignment requests](#sdk-relay-client)
96-
2. A `build-and-run.sh` file which, given a properly configured environment, [builds the SDK Relay Server application](#build-and-runsh) **using the specified version of the SDK package**.
96+
2. Launch Script:
97+
1. A `build-and-run-<platform>.sh` file which fully configures the environment then initiates a [build and run of the relay server application](#build-and-runsh) **using the specified version of the SDK package**. <platform> is one of `linux`, `macos`, or `windows`.
98+
2. OR, a `build-and-run.sh` file which can configure the environment based on the env variable, `PLATFORM` and then initiate a [build and run of the relay server application](#build-and-runsh) **using the specified version of the SDK package**.
99+
3. OR, a `docker-run.sh` file which builds and runs a docker container running the SDK relay app
97100

98101
The following are key components derived from above which allow for convenient and consistent dev-ops.
99102

@@ -278,6 +281,25 @@ Example `build-and-run.sh` script
278281

279282
#!/usr/bin/env bash
280283

284+
# Configure environment per platform
285+
case "${PLATFORM}" in
286+
"windows")
287+
choco install php -v ${PHP_VERSION}
288+
;;
289+
"macos")
290+
brew install php@${PHP_VERSION}
291+
;;
292+
"ubuntu")
293+
sudo apt update
294+
sudo apt install php-${PHP_VERSION}
295+
;;
296+
*)
297+
echo "Unsupported platform: ${PLATFORM}"
298+
exit 1
299+
;;
300+
esac
301+
302+
281303
composer install
282304

283305
# Set default values for vars

package-testing/sdk-test-runner/test-sdk.sh

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/bin/bash
2+
trap "exit 1" TERM
3+
export TOP_PID=$$
24

35
# Usage:
46
#
@@ -36,6 +38,7 @@ function wait_for_url() {
3638

3739
while [[ $attempt -le $max_attempts ]]; do
3840
curl --silent --output /dev/null --fail "$url" && { return 1; }
41+
echo "Waiting attempt number ${attempt}"
3942
sleep 1
4043
((attempt++))
4144
done
@@ -45,7 +48,7 @@ function wait_for_url() {
4548

4649
function exit_with_message() {
4750
echo_red "$1"
48-
exit 1
51+
kill -s TERM $TOP_PID
4952
}
5053

5154
# Parse command-line arguments
@@ -67,12 +70,17 @@ export SDK_RELAY_PORT="${SDK_RELAY_PORT:-4000}"
6770
export EPPO_SCENARIO_FILE="${EPPO_SCENARIO_FILE:-scenarios.json}"
6871
export EPPO_TEST_DATA_PATH="${EPPO_TEST_DATA_PATH:-./test-data}"
6972

70-
7173
# Validate SDK name
7274
if [[ -z "$SDK_NAME" ]]; then
7375
exit_with_message "Missing required argument: sdkName"
7476
fi
7577

78+
# Ensure platform is set
79+
if [[ -z "$PLATFORM" ]]; then
80+
exit_with_message "PLATFORM environment variable must be set"
81+
fi
82+
export PLATFORM
83+
7684
# Extrapolate the SDK directory name
7785
if [[ -z "$SDK_DIR" ]]; then
7886
SDK_DIR=${SDK_NAME}-relay
@@ -121,10 +129,22 @@ case "$command" in
121129

122130
echo " ... Starting Test Cluster node [${SDK_DIR}]"
123131

124-
# change directory to the SDK relay then build-and-run
132+
# change directory to the SDK relay then run the SDK relay server
125133
RUNNER_DIR=$(pwd)
134+
mkdir -p ${RUNNER_DIR}/logs
126135
pushd ../$SDK_DIR
127-
./build-and-run.sh >> ${RUNNER_DIR}/logs/sdk.log 2>&1 &
136+
137+
BUILD_AND_RUN_PLATFORM=build-and-run-${PLATFORM}.sh
138+
if [ -f docker-run.sh ]; then
139+
echo " ... Starting SDK Relay via docker launch script"
140+
./docker-run.sh >> ${RUNNER_DIR}/logs/sdk.log 2>&1 &
141+
elif [ -f ${BUILD_AND_RUN_PLATFORM} ]; then
142+
echo " ... Starting SDK Relay via platform build-and-run script"
143+
./${BUILD_AND_RUN_PLATFORM} >> ${RUNNER_DIR}/logs/sdk.log 2>&1 &
144+
else
145+
exit_with_message "SDK Relay does not have a launch script in $SDK_DIR"
146+
fi
147+
128148
SDK_RELAY_PID=$!
129149
popd
130150

@@ -139,6 +159,7 @@ case "$command" in
139159
echo " ... Starting Test Cluster node [Eppo-exp/sdk-test-runner]"
140160

141161
docker run \
162+
--add-host host.docker.internal:host-gateway \
142163
-e SDK_NAME \
143164
-e EPPO_API_HOST=host.docker.internal \
144165
-e SDK_RELAY_HOST=host.docker.internal \
@@ -148,6 +169,7 @@ case "$command" in
148169
--name eppo-sdk-test-runner \
149170
-t Eppo-exp/sdk-test-runner:latest "--junit=logs/results.xml"
150171

172+
EXIT_CODE=$?
151173

152174
echo " ... Downing the docker containers"
153175
docker logs eppo-api >& logs/api.log
@@ -158,7 +180,8 @@ case "$command" in
158180
docker container remove eppo-sdk-test-runner #already stopped at this point
159181

160182
pkill -P $SDK_RELAY_PID
161-
183+
184+
exit $EXIT_CODE
162185
;;
163186
client)
164187
echo_red "Client mode not yet implemented"

0 commit comments

Comments
 (0)