Skip to content

Commit

Permalink
Apdate server application
Browse files Browse the repository at this point in the history
  - make the server a stand alone applicaion

Signed-off-by: yzamir <kobi.zamir@gmail.com>
  • Loading branch information
yaacov committed Sep 11, 2023
1 parent 2a91ae0 commit e641ca8
Show file tree
Hide file tree
Showing 25 changed files with 884 additions and 888 deletions.
2 changes: 2 additions & 0 deletions rose/server/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[run]
omit = tests/*
3 changes: 3 additions & 0 deletions rose/server/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 256
extend-ignore = E203
15 changes: 15 additions & 0 deletions rose/server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 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

# Copy the local package files to the container's workspace
COPY . /app

# Install the Python dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Set the command to run the main.py file when the container launches
ENTRYPOINT ["python", "main.py", "--listen", "0.0.0.0"]
CMD [ "--track", "same" ]
47 changes: 47 additions & 0 deletions rose/server/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
.PHONY: lint test lint-fix code-quality run build-image run-image clean

IMAGE_NAME ?= quay.io/rose/rose-server
PORT ?= 8880
WS_PORT ?= 8765

# Default driver when running on localhost
DRIVERS ?= http://127.0.0.1:8081

# By default, run both linting and tests
all: lint test

lint:
@echo "Running 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) --drivers $(DRIVERS)

build-image:
@echo "Building container image ..."
podman build -t $(IMAGE_NAME) .

run-image:
@echo "Running container image ..."
podman run --rm --network host -it $(IMAGE_NAME)

clean:
-rm -rf .coverage
-rm -rf htmlcov
-find . -name '*.pyc' -exec rm {} \;
-find . -name '__pycache__' -exec rmdir {} \;
89 changes: 89 additions & 0 deletions rose/server/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
=======================
ROSE Engine Game Server
=======================

Overview
========
This server provides a simple HTTP endpoint for a driving game.

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 8080
By default, the server will start on port 8080.

Podman Usage
============
1. Build the Podman image:

.. code-block:: bash
podman build -t rose-engine .
2. Run the container:

.. code-block:: bash
podman run -it --rm --network host rose-engine
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
kubectl apply -f rose-engine.yaml
2. Check the status of the deployment:

.. code-block:: bash
kubectl get deployments rose-engine
3. Forward a local port to your pod for accessing the service locally:

.. code-block:: bash
kubectl port-forward deployment/rose-engine-deployment 8880:8880 8765:8765
Now, the service will be accessible locally at http://localhost:8880.

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
Empty file added rose/server/common/__init__.py
Empty file.
10 changes: 10 additions & 0 deletions rose/server/common/actions.py
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)
20 changes: 20 additions & 0 deletions rose/server/common/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# config.py

# Default Configuration
drivers = []
run = "stop"

game_rate = 1.0
game_duration = 60

matrix_height = 9
matrix_width = 6

max_players = 2
cells_per_player = 3

score_move_forward = 10
score_move_backward = -10
score_pickup = 10
score_jump = 5
score_brake = 4
17 changes: 17 additions & 0 deletions rose/server/common/obstacles.py
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)
131 changes: 0 additions & 131 deletions rose/server/game.py

This file was deleted.

Empty file added rose/server/game/__init__.py
Empty file.
Loading

0 comments on commit e641ca8

Please sign in to comment.