Skip to content

Commit

Permalink
feat: Create Makefile for build.yml (#7)
Browse files Browse the repository at this point in the history
* feat: Create Makefile for build.yml

* fix: bash error on Windows

* fix: bash error with Windows Action

* fix: update Makefile for Windows build

* fix: incorrect quote escaping on windows e2e test

* fix: incorrect quote escaping on windows e2e test v2

* fix: No logs from Windows run

* fix: No logs from Windows run v2

* fix: No logs from Windows run v3

* fix: No logs from Windows run v4

* fix: No logs from Windows run v5

* fix: empty server.log
  • Loading branch information
CameronNg authored May 14, 2024
1 parent 50eaa35 commit 071d602
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 72 deletions.
1 change: 1 addition & 0 deletions .github/scripts/e2e-test-server-linux-and-mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ if [[ "$error_occurred" -eq 1 ]]; then
echo "Server Error Logs:"
cat /tmp/server.log
kill $pid
echo "An error occurred while running the server."
exit 1
fi

Expand Down
34 changes: 22 additions & 12 deletions .github/scripts/e2e-test-server-windows.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@echo off

setlocal enabledelayedexpansion

set "TEMP=C:\Users\%UserName%\AppData\Local\Temp"

rem Check for required arguments
Expand All @@ -15,7 +17,7 @@ for %%i in ("%BINARY_PATH%") do set "BINARY_NAME=%%~nxi"

echo BINARY_NAME=%BINARY_NAME%

del %TEMP%\python-file-execution-res.log 2>nul
del %TEMP%\response1.log 2>nul
del %TEMP%\server.log 2>nul

set /a min=9999
Expand All @@ -24,9 +26,9 @@ set /a range=max-min+1
set /a PORT=%min% + %RANDOM% %% %range%

rem Start the binary file
start /B "" "%BINARY_PATH%" "127.0.0.1" %PORT% > %TEMP%\server.log 2>&1
start "" /B "%BINARY_PATH%" "127.0.0.1" %PORT% > "%TEMP%\server.log" 2>&1

ping -n 6 127.0.0.1 %PORT% > nul
ping -n 3 127.0.0.1 > nul

rem Capture the PID of the started process with "server" in its name
for /f "tokens=2" %%a in ('tasklist /fi "imagename eq %BINARY_NAME%" /fo list ^| findstr /B "PID:"') do (
Expand All @@ -38,6 +40,7 @@ echo pid=%pid%
if not defined pid (
echo server failed to start. Logs:
type %TEMP%\server.log
echo.
exit /b 1
)

Expand All @@ -53,32 +56,39 @@ echo curl_data1=%curl_data1%
rem Run the curl commands and capture the status code
curl.exe --connect-timeout 60 -o "%TEMP%\response1.log" -s -w "%%{http_code}" --location "http://127.0.0.1:%PORT%/execute" --header "Content-Type: application/json" --data "%curl_data1%" > %TEMP%\response1.log 2>&1


set "error_occurred=0"

rem Read the status codes from the log files
rem Read the status code directly from the response file
set "response1="
for /f %%a in (%TEMP%\response1.log) do set "response1=%%a"

if "%response1%" neq "200" (
echo The first curl command failed with status code: %response1%
type %TEMP%\response1.log
echo.
set "error_occurred=1"
)

echo ----------------------
echo Log python file execution:
type %TEMP%\response1.log
echo.

echo ----------------------
echo Server logs:
type %TEMP%\server.log
echo.

if "%error_occurred%"=="1" (
echo Server test run failed!!!!!!!!!!!!!!!!!!!!!!
echo Server Error Logs:
type %TEMP%\server.log
taskkill /f /pid %pid%
echo An error occurred while running the server.
exit /b 1
)

echo ----------------------
echo Server logs:
type %TEMP%\server.log

echo Server test run successfully!

rem Kill the server process
@REM taskkill /f /pid %pid%
taskkill /f /im server.exe 2>nul || exit /B 0

endlocal
51 changes: 10 additions & 41 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,69 +13,38 @@ jobs:
matrix:
include:
- os: "linux"
name: "ubuntu-1"
name: "ubuntu-18-04"
runs-on: "ubuntu-18-04"
# run-e2e: true
- os: "mac"
name: "arm64-1"
name: "arm64"
runs-on: "mac-silicon"
- os: "windows"
name: "amd64-avx2-cuda-12-0"
name: "amd64"
runs-on: "windows-cuda-12-0"

steps:
- name: Clone
id: checkout
uses: actions/checkout@v3

- name: Install dependencies on Windows
- name: Install make on Windows
if: runner.os == 'windows'
run: |
choco install make -y
.\install_deps.bat
- name: Install dependencies on Unix
if: runner.os != 'windows'
- name: Install dependencies
run: |
bash ./install_deps.sh
make install-dependencies
- name: Build engine
run: |
mkdir -p build
cd build
cmake ..
cmake --build . --config Release -j12
make build-engine
- name: Build example server
run: |
mkdir -p examples/server/build
cd examples/server/build
cmake ..
cmake --build . --config Release -j12
make build-example-server
- name: Run e2e test on Windows
if: runner.os == 'windows'
run: |
mkdir -p examples\server\build\Release\engines\cortex.python-runtime
cd examples\server\build\Release
cp ..\..\..\..\build\Release\engine.dll engines\cortex.python-runtime
..\..\..\..\.github\scripts\e2e-test-server-windows.bat server.exe ../../../.github/scripts/python-file-to-test.py
- name: Run e2e test on Linux
if: runner.os == 'linux'
- name: Run e2e test
run: |
mkdir -p examples/server/build/engines/cortex.python-runtime
cd examples/server/build/
cp ../../../build/libengine.so engines/cortex.python-runtime/
chmod +x ../../../.github/scripts/e2e-test-server-linux-and-mac.sh
../../../.github/scripts/e2e-test-server-linux-and-mac.sh ./server ../../../.github/scripts/python-file-to-test.py
- name: Run e2e test on MacOS
if: runner.os == 'mac'
run: |
mkdir -p examples/server/build/engines/cortex.python-runtime
cd examples/server/build/
cp ../../../build/libengine.dylib engines/cortex.python-runtime/
chmod +x ../../../.github/scripts/e2e-test-server-linux-and-mac.sh
../../../.github/scripts/e2e-test-server-linux-and-mac.sh ./server ../../../.github/scripts/python-file-to-test.py
make run-e2e-test
45 changes: 26 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
# Makefile for Cortex python-runtime engine - Build, Lint, Test, and Clean

CMAKE_EXTRA_FLAGS ?= ""
RUN_TESTS ?= false
PYTHON_FILE_EXECUTION_PATH ?= ".github/scripts/python-file-to-test.py"
RUN_TESTS ?= true
PYTHON_FILE_EXECUTION_PATH ?= .github/scripts/python-file-to-test.py

# Default target, does nothing
all:
@echo "Specify a target to run"

# Build the Cortex python-runtime engine
build-lib:
install-dependencies:
ifeq ($(OS),Windows_NT) # Windows
@powershell -Command "cmake -S ./third-party -B ./build_deps/third-party;"
@powershell -Command "cmake --build ./build_deps/third-party --config Release -j8;"
@powershell -Command "mkdir -p build && cd build && cmake .. $(CMAKE_EXTRA_FLAGS) && cmake --build . --config Release;"
cmd /C install_deps.bat
else # Unix-like systems (Linux and MacOS)
@cmake -S ./third-party -B ./build_deps/third-party
@make -C ./build_deps/third-party -j8
# The following mkdir command will now work properly by changing to the directory only once.
@mkdir -p build && cd build && \
cmake .. $(CMAKE_EXTRA_FLAGS) && \
make -j8
bash ./install_deps.sh
endif

build-example-server: build-lib
build-engine:
ifeq ($(OS),Windows_NT)
@powershell -Command "mkdir -p .\examples\server\build && cd .\examples\server\build && cmake .. $(CMAKE_EXTRA_FLAGS) && cmake --build . --config Release -j8;"
cmd /C "mkdir build && cd build && cmake .. && cmake --build . --config Release -j12"
else
@mkdir -p examples/server/build && cd examples/server/build && \
cmake .. $(CMAKE_EXTRA_FLAGS) && \
cmake --build . --config Release -j8
mkdir -p build
cd build && cmake .. && cmake --build . --config Release -j12
endif

build-example-server:
ifeq ($(OS),Windows_NT)
cmd /C "mkdir examples\\server\\build && cd examples\\server\\build && cmake .. && cmake --build . --config Release -j12"
else
mkdir -p examples/server/build
cd examples/server/build && cmake .. && cmake --build . --config Release -j12
endif

package:
ifeq ($(OS),Windows_NT)
@powershell -Command "mkdir -p cortex.python-runtime && cp build\Release\engine.dll cortex.python-runtime\ && 7z a -ttar temp.tar cortex.python-runtime\* && 7z a -tgzip cortex.python-runtime.tar.gz temp.tar;"
@powershell -Command "New-Item -ItemType Directory -Path cortex.python-runtime -Force; cp build\Release\engine.dll cortex.python-runtime\; Compress-Archive -Path cortex.python-runtime\* -DestinationPath cortex.python-runtime.zip;"
else
@mkdir -p cortex.python-runtime && \
cp build/libengine.$(shell uname | tr '[:upper:]' '[:lower:]' | sed 's/darwin/dylib/;s/linux/so/') cortex.python-runtime/ && \
Expand All @@ -46,7 +46,8 @@ ifeq ($(RUN_TESTS),false)
@echo "Skipping tests"
else
ifeq ($(OS),Windows_NT)
@powershell -Command "mkdir -p examples\server\build\Release\engines\cortex.python-runtime && cd examples\server\build\Release && cp ..\..\..\..\build\Release\engine.dll engines\cortex.python-runtime && ..\..\..\..\.github\scripts\e2e-test-server-windows.bat server.exe ..\..\..\$(PYTHON_FILE_EXECUTION_PATH);"
@mkdir examples\server\build\Release\engines\cortex.python-runtime && \
cmd /C "cd examples\server\build\Release && copy ..\..\..\..\build\Release\engine.dll engines\cortex.python-runtime && ..\..\..\..\.github\scripts\e2e-test-server-windows.bat server.exe ..\..\..\..\\$(PYTHON_FILE_EXECUTION_PATH)"
else
@mkdir -p examples/server/build/engines/cortex.python-runtime && \
cd examples/server/build && \
Expand All @@ -55,3 +56,9 @@ else
endif
endif

clean:
ifeq ($(OS),Windows_NT)
cmd /C "rmdir /S /Q build examples\\server\\build cortex.python-runtime cortex.python-runtime.tar.gz cortex.python-runtime.zip"
else
rm -rf build examples/server/build cortex.python-runtime cortex.python-runtime.tar.gz cortex.python-runtime.zip
endif
1 change: 1 addition & 0 deletions src/python_runtime_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ void PythonRuntimeEngine::HandlePythonFileExecutionRequestImpl(
json_resp["message"] = "Failed to execute the Python file";
} else {
LOG_INFO << "Created child process for Python embedding";
WaitForSingleObject(pi.hProcess, INFINITE);
}
#else
std::string child_process_exe_path = PythonRuntimeUtils::getCurrentExecutablePath();
Expand Down

0 comments on commit 071d602

Please sign in to comment.