-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- make client and server separate applications - use vanilla HTTP comunication between client and server - use asyncio instead of twisted - use websockets instead of autobahn Signed-off-by: yzamir <kobi.zamir@gmail.com>
- Loading branch information
Showing
49 changed files
with
1,453 additions
and
1,169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[run] | ||
omit = tests/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[flake8] | ||
max-line-length = 256 | ||
extend-ignore = E203 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Use Red Hat Universal Base Image (UBI) with Python | ||
FROM registry.access.redhat.com/ubi8/python-38 | ||
|
||
# Set the working directory in the Docker container | ||
WORKDIR /app/rose/client | ||
|
||
# Copy the local package files to the container's workspace | ||
COPY ./__init__.py /app/rose/__init__.py | ||
COPY . /app/rose/client | ||
|
||
# Install the Python dependencies | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
# Add the rose client package to the python path | ||
ENV PYTHONPATH "${PYTHONPATH}:/app" | ||
|
||
# Set the command to run the main.py file when the container launches | ||
ENTRYPOINT ["python", "main.py", "--listen", "0.0.0.0"] | ||
CMD ["--driver", "./mydriver.py", "--port", "8081"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
.PHONY: lint test lint-fix code-quality test-coverage run clean | ||
|
||
IMAGE_NAME ?= quay.io/rose/rose-client | ||
DRIVER_PATH ?= ./mydriver.py | ||
PORT ?= 8081 | ||
|
||
# By default, run both linting and tests | ||
all: lint test | ||
|
||
lint: | ||
@echo "Running flake8 linting..." | ||
flake8 --show-source --statistics . | ||
black --check --diff . | ||
|
||
lint-fix: | ||
@echo "Running lint fixing..." | ||
@black --verbose --color . | ||
|
||
code-quality: | ||
@echo "Running static code quality checks..." | ||
radon cc . | ||
radon mi . | ||
|
||
test: | ||
@echo "Running unittests..." | ||
pytest | ||
|
||
run: | ||
@echo "Running driver logic server ..." | ||
python main.py --port $(PORT) --driver $(DRIVER_PATH) | ||
|
||
build-image: | ||
@echo "Building container image ..." | ||
podman build -t $(IMAGE_NAME) . | ||
|
||
run-image: | ||
@echo "Running container image ..." | ||
podman run --rm \ | ||
--network host \ | ||
-v ../../examples:/app/examples:z \ | ||
-it $(IMAGE_NAME) \ | ||
--port $(PORT) \ | ||
--driver $(DRIVER_PATH) | ||
|
||
clean: | ||
-rm -rf .coverage | ||
-rm -rf htmlcov | ||
-find . -name '*.pyc' -exec rm {} \; | ||
-find . -name '__pycache__' -exec rmdir {} \; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
======================= | ||
ROSE Driver Game Server | ||
======================= | ||
|
||
Overview | ||
======== | ||
This server provides a simple HTTP endpoint for a driving game. The game receives JSON payloads containing information about car metadata and a game track filled with obstacles. | ||
The server, using a driver's logic, returns the best action for the car to take next. | ||
|
||
Requirements | ||
============ | ||
* Python 3.8+ | ||
* Podman (optional, for containerization) | ||
|
||
Installation | ||
============ | ||
1. Clone the repository: | ||
|
||
.. code-block:: bash | ||
git clone <repository_url> | ||
cd <repository_directory> | ||
2. Install the required Python packages: | ||
|
||
.. code-block:: bash | ||
pip install -r requirements.txt | ||
pip install -r requirements-dev.txt | ||
Running the Server | ||
================== | ||
Run the server using: | ||
|
||
.. code-block:: bash | ||
python main.py --port 8081 --driver <path to driver python file> | ||
By default, the server will start on port 8081, default driver is ./mydriver.py . | ||
|
||
Driver Logic | ||
============ | ||
This server uses a default driver logic which chooses the next action randomly. For a custom driver logic, modify the `driver.py` file. | ||
|
||
Podman Usage | ||
============ | ||
1. Build the Podman image: | ||
|
||
.. code-block:: bash | ||
# Edit mydriver.py file. | ||
podman build -t rose-driver . | ||
2. Run the container: | ||
|
||
.. code-block:: bash | ||
# Edit mydriver.py file, and create the best driver code, | ||
# once mydriver.py is ready build and run the container. | ||
podman build -t rose-driver . | ||
podman run -it --rm --network host rose-driver --port 8081 | ||
3. Run the container using local driver python file: | ||
|
||
.. code-block:: bash | ||
podman run -it --rm --network host -v <path to driver python file>:/mydriver.py:z rose-driver --driver /mydriver.py --port 8081 | ||
Kubernetes Deployment | ||
===================== | ||
|
||
You can deploy the application on a Kubernetes cluster using the provided configuration. | ||
|
||
Instructions: | ||
------------- | ||
1. Apply both the Deployment and Service: | ||
|
||
.. code-block:: bash | ||
# Edit rose-driver.yaml and change the image to use your publically published image, image must be available from the registry, | ||
# you can't use local images when running inside a cluster, image must be pushed to a registry reachable from the cluster. | ||
# | ||
# Note: By modifying the deployment and service names, you can run more then one driver. | ||
kubectl apply -f rose-driver.yaml | ||
2. Check the status of the deployment: | ||
|
||
.. code-block:: bash | ||
kubectl get deployments rose-driver | ||
3. Forward a local port to your pod for accessing the service locally: | ||
|
||
.. code-block:: bash | ||
kubectl port-forward deployment/rose-driver-deployment 8081:8081 | ||
Now, the service will be accessible locally at http://localhost:8081. | ||
|
||
Note: For production deployments, consider exposing the service using an Ingress controller or cloud provider specific solutions. | ||
|
||
Contributing | ||
============ | ||
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. | ||
|
||
License | ||
======= | ||
GPL-v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__author__ = 'gickowic' | ||
__author__ = "gickowic" |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
""" Driving actions """ | ||
|
||
NONE = "none" # NOQA | ||
RIGHT = "right" # NOQA | ||
LEFT = "left" # NOQA | ||
PICKUP = "pickup" # NOQA | ||
JUMP = "jump" # NOQA | ||
BRAKE = "brake" # NOQA | ||
|
||
ALL = (NONE, RIGHT, LEFT, PICKUP, JUMP, BRAKE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class Car: | ||
def __init__(self, info): | ||
self.x = info["x"] | ||
self.y = info["y"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
""" Game obstacles """ | ||
|
||
import random | ||
|
||
NONE = "" # NOQA | ||
CRACK = "crack" # NOQA | ||
TRASH = "trash" # NOQA | ||
PENGUIN = "penguin" # NOQA | ||
BIKE = "bike" # NOQA | ||
WATER = "water" # NOQA | ||
BARRIER = "barrier" # NOQA | ||
|
||
ALL = (NONE, CRACK, TRASH, PENGUIN, BIKE, WATER, BARRIER) | ||
|
||
|
||
def get_random_obstacle(): | ||
return random.choice(ALL) |
Oops, something went wrong.