-
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.
Add configuration and CI files to the server application
Signed-off-by: yzamir <[email protected]>
- Loading branch information
Showing
10 changed files
with
226 additions
and
0 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 = test_*.py |
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,8 @@ | ||
[flake8] | ||
show_source = True | ||
statistics = True | ||
|
||
# E501: line to long. | ||
# E203: whitespace before ':' to accept black code style | ||
# W503: line break before binary operator | ||
ignore = E501,E203,W503 |
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,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" ] |
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,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 {} \; |
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,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 |
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 @@ | ||
# conftest.py | ||
import sys | ||
|
||
sys.path.append(".") |
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 @@ | ||
[pytest] | ||
addopts = -vv -rxs --timeout 10 --cov . |
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,13 @@ | ||
# requirements.txt | ||
|
||
flake8>=3.9.0 | ||
coverage>=7.3.0 | ||
radon>=6.0.0 | ||
black>=23.7.0 | ||
requests>=2.28.0 | ||
websockets>=11.0.0 | ||
aiohttp>=3.8.0 | ||
pytest | ||
pytest-check-links | ||
pytest-coverage | ||
pytest-timeout |
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,5 @@ | ||
# requirements.txt | ||
|
||
requests>=2.28.0 | ||
websockets>=11.0.0 | ||
aiohttp>=3.8.0 |
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,41 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: rose-server-deployment | ||
labels: | ||
app: rose-server | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: rose-server | ||
template: | ||
metadata: | ||
labels: | ||
app: rose-server | ||
spec: | ||
containers: | ||
- name: rose-server-container | ||
image: quay.io/rose/rose-server:latest # Modify with your Docker image name and tag. | ||
ports: | ||
- containerPort: 8880 | ||
|
||
--- | ||
|
||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: rose-server-service | ||
spec: | ||
selector: | ||
app: rose-server | ||
ports: | ||
- name: http | ||
protocol: TCP | ||
port: 8880 | ||
targetPort: 8880 | ||
- name: ws | ||
protocol: TCP | ||
port: 8765 | ||
targetPort: 8765 | ||
type: LoadBalancer # run outside the cluster: kubectl port-forward service/rose-server-service 8880:8880 8765:8765 . |