Skip to content

Commit

Permalink
Make ROSE containers more freindly
Browse files Browse the repository at this point in the history
Signed-off-by: yzamir <kobi.zamir@gmail.com>
  • Loading branch information
yaacov committed Sep 11, 2023
1 parent 5b86d4e commit ee55c43
Show file tree
Hide file tree
Showing 104 changed files with 2,507 additions and 1,380 deletions.
2 changes: 0 additions & 2 deletions .coveragerc

This file was deleted.

3 changes: 0 additions & 3 deletions .dockerignore

This file was deleted.

18 changes: 11 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: "3.7"
python-version: |
3.7
3.9
- name: Install dependencies
run: |
pip install --upgrade pip
pip install -r requirements-dev.txt
run: make dev-init

- name: Lint
run: flake8 --show-source --statistics
run: make lint

- name: Run tests
run: pytest
run: make test
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Python
__pycache__
*.pyc

# Editors
Expand All @@ -9,7 +10,8 @@
.coverage
htmlcov/

Pipfile.lock
rose_project.egg-info
dist

# Classroom setup
classroom/credentials.json
Expand Down
12 changes: 0 additions & 12 deletions .travis.yml

This file was deleted.

42 changes: 0 additions & 42 deletions Dockerfile

This file was deleted.

37 changes: 20 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
init: Pipfile
python -m pip install pipenv --user
pipenv install
init:
pip install -r rose/client/requirements.txt
pip install -r rose/server/requirements.txt

dev-init: Pipfile
python -m pip install pipenv --user
pipenv install --dev
dev-init:
pip install -r rose/client/requirements-dev.txt
pip install -r rose/server/requirements-dev.txt

test: pytest.ini
pipenv run pytest
lint:
make -C rose/client lint
make -C rose/server lint

admin: rose-admin
pipenv run ./rose-admin
lint-fix:
make -C rose/client lint-fix
make -C rose/server lint-fix

server: rose-server
pipenv run ./rose-server
test:
make -C rose/client test-coverage
make -C rose/server test-coverage

client: rose-client
pipenv run ./rose-client

container-image:
podman build --build-arg DEV=True -t rose_dev .
clean:
-find . -name '.coverage' -exec rm {} \;
-find . -name 'htmlcov' -exec rmdir {} \;
-find . -name '*.pyc' -exec rm {} \;
-find . -name '__pycache__' -exec rmdir {} \;
118 changes: 63 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,52 +58,46 @@ The following commands should be performed only once; after creating the
environment you will be connecting to the same environment each time you
open a new session.

Use venv to create a virtual environment and to install the rest of
the dependencies:
Clone the code to your local machine:

python3 -m venv ~/.venv/rose
# Clone the code into your current working directory:
git clone https://github.com/RedHat-Israel/ROSE.git

After creating the environment, we want to activate and enter our
environment (make sure you're in the ROSE directory):
# Change directory into the code folder:
cd ROSE

source ~/.venv/rose/bin/activate
Install the project dependencies:

After entering the virtual enviornment we need to install the project dependencies:

pip install -r requirements.txt

Indication that you are inside the environment, the prompt line will
look like this:

(rose) [username@hostname ROSE]$
pip install -r rose/client/requirements.txt
pip install -r rose/server/requirements.txt

## Running the server

If you are not in your virtual environment, please activate it:

source ~/.venv/rose/bin/activate

Start the server on some machine:
Start the server and listen to all machines (default is only this host):

./rose-server
./rose-server --listen 0.0.0.0

For running the same track for all drivers (instead or random) start the
server using:

./rose-server -t same
./rose-server --track same --listen 0.0.0.0

Open a browser at http://{server-address}:8880 to view and control the
game.

### Running the server in Podman

Change directory into the server code directory:

cd rose/server

Build the Docker image:

podman build -t rose_server .

Run the Docker image on port 8880:

podman run -it --rm --name=rose_server -p 8880:8880 rose_server python ./rose-server
podman run -it --rm --name=rose_server --network host rose_server

If you don't want to see the log of the run in the current window,
replace `-it` with `-d`.
Expand All @@ -116,26 +110,27 @@ game.
You can use SSH tunneling when running the server on your remote VM, so
you can view the game in you local browser:

ssh -L 8880:127.0.0.1:8880 {user}@{server-address}
ssh -L 8880:127.0.0.1:8880 -L 8765:127.0.0.1:8765 {user}@{server-address}

After starting the server (as mentioned above), open a browser at
http://127.0.0.1:8880/ to view and control the game.

### Opening firewall ports

You can also open ports 8880 and 8888 on the remote VM running the
server, and browse from a local machine in case port 8880 or 8888 are
You can also open ports 8880 and 8765 on the remote VM running the
server, and browse from a local machine in case port 8880 or 8765 are
blocked by [firewalld](https://firewalld.org/):

sudo firewall-cmd --add-port=8880/tcp --permanent
sudo firewall-cmd --add-port=8888/tcp --permanent
sudo firewall-cmd --add-port=8765/tcp --permanent
sudo firewall-cmd --reload

## Running a driver
If you are serving none local machines, remember to run the server with --listen 0.0.0.0
to allow incoming connections from remove machines.

In a new window, open your virtual environment:
./rose-server -t same --listen 0.0.0.0

source ~/.venv/rose/bin/activate
## Running a driver

Create your driver file:

Expand All @@ -146,22 +141,28 @@ name.

Start up the client, using your driver file:

./rose-client mydriver.py
./rose-client --driver mydriver.py

### Running the driver in Podman

The server address can be specified that way (Replace '10.20.30.44' with
your server address):
Change directory into the server code directory:

./rose-client -s 10.20.30.44 mydriver.py
cd rose/client

For running the driver on the Docker container use:
Edit mydriver.py driver file

docker exec -it rose_server python ./rose-client examples/random-driver.py
Build the Docker image:

podman build -t rose_driver .

Run the Docker image on port 8081:

For driver modules, see the [examples](examples) directory.
podman run -it --rm --name=rose_driver --network host rose_driver

You can run the game with just 1 driver!
If you don't want to see the log of the run in the current window,
replace `-it` with `-d`.

To let 2 drivers compete, repeat these commands in 2 terminals.
The driver will be available at http://{server-address}:8081 .

## Command line interface

Expand All @@ -176,14 +177,23 @@ To stop a race, use the rose-admin tool on any machine:

./rose-admin {server-address} stop

To reset a race, use the rose-admin tool on any machine:

./rose-admin {server-address} reset

To modify the game rate, you can use the "set-rate" command. The
following command would change game rate to 10 frames per second:

./rose-admin {server-address} set-rate 10

To set the game drivers. The following command would update
the game drivers:

./rose-admin {server-address} set-drivers http://127.0.0.1:8081 http://127.0.0.1:8082

## Using tmux / screen

`./rose-server` and `./rose-client {driver name}` do not return, but
`./rose-server` and `./rose-client --driver {driver name}` do not return, but
continue running, in order to run both server and drivers a user need to
run them in separate shells, using the same virtual environment.
shell. `tmux` may be useful in this case.
Expand All @@ -208,28 +218,26 @@ Example `tmux` commands:
Should you want to contribute to the project, please read the
[Code of Conduct](docs/code-of-conduct.md).

To create venv use:

python3 -m venv ~/.venv/rose

To enter the venv:
Install make utility:

source ~/.venv/rose/bin/activate
sudo dnf install make

To install development requirements:
Install development python modules:

pip install -r requirements-dev.txt
pip install -r rose/client/requirements-dev.txt
pip install -r rose/server/requirements-dev.txt

For development in docker, use:
Run lint and test before submitting a pull request:

docker build --build-arg DEV=True -t rose_dev .
make lint
make test

Before submitting patches, please run the tests:
When developint the client or server code, change directory into the the server or client direcotry:

flake8
pytest
cd rose/client # or cd rose/server

Creating coverage report in html format:
Use the make utility to build and run the applicaion

pytest --cov-report html
xdg-open htmlcov/index.html
# for example:
make build-image # will build a docker image
make run-image # will run the image locally
File renamed without changes.
Binary file removed examples/best_driver.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/none.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
This driver does not do any action.
"""
from rose.common import obstacles, actions # NOQA
from rose.client.game import obstacles, actions # NOQA

driver_name = "No Driver"

Expand Down
2 changes: 1 addition & 1 deletion examples/random-driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
very good driver but the implementation is very elegant.
"""
import random
from rose.common import obstacles, actions # NOQA
from rose.client.game import obstacles, actions # NOQA

driver_name = "Random Driver"

Expand Down
Binary file removed examples/score.pyc
Binary file not shown.
Binary file removed examples/zigzag.pyc
Binary file not shown.
Loading

0 comments on commit ee55c43

Please sign in to comment.