From 98057eed07f4580fa521febd8741359b15e53e25 Mon Sep 17 00:00:00 2001 From: Micheal Waltz Date: Tue, 2 Oct 2018 11:10:14 -0700 Subject: [PATCH 1/3] ROSE Server in a Docker Container Fixes #173 Uses official CentOS Python 2.7 image. --- .dockerignore | 4 ++++ Dockerfile | 26 ++++++++++++++++++++++++++ README.md | 12 ++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..f1e773d3 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +docs/ +examples/ +Makefile +README* diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..8650ae86 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +# Use official CentOS Python 2.7 image +# https://developer.fedoraproject.org/tools/docker/docker-images.html +FROM centos/python-27-centos7 AS base + +# Project maintainer +LABEL maintainer="frolland@redhat.com" + +# Required env vars +ENV LD_LIBRARY_PATH="/opt/rh/python27/root/usr/lib64/" \ + ENABLE_PIPENV=true + +# Install pipenv +RUN pip install --upgrade pipenv + +# Copy application to default WORKDIR +COPY . ./ + +# Install dependencies from pipfile +RUN pipenv install + +# Server port +EXPOSE 8880 + +# Server command +ENTRYPOINT [ "pipenv" ] +CMD [ "run", "python", "rose-server"] diff --git a/README.md b/README.md index f46c2b44..7019f1b2 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,18 @@ For running the same track for all drivers (instead or random) start the server Open a browser at http://\:8880 to view and control the game. +### Running the server in Docker + +Build the Docker image: + + docker build -t rose:server . + +Run the Docker image on port 8880: + + docker run -it --rm -p 8880 rose:server + +Open a browser at http://\:8880 to view and control the game. + ## Running a driver In a new window, open your virtual environment: From cd4436c4ad0845ec876a47909107c4f95321dd5d Mon Sep 17 00:00:00 2001 From: Anna Dinaburg Vulikh Date: Wed, 28 Apr 2021 18:09:00 +0300 Subject: [PATCH 2/3] updated docker file according to review and added DEV options --- .dockerignore | 7 +++---- Dockerfile | 40 ++++++++++++++++++++++++++++------------ README.md | 23 +++++++++++++++++------ 3 files changed, 48 insertions(+), 22 deletions(-) diff --git a/.dockerignore b/.dockerignore index f1e773d3..ffabc800 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,3 @@ -docs/ -examples/ -Makefile -README* +/classroom +/docs +Makefile \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 8650ae86..a9136868 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,26 +1,42 @@ -# Use official CentOS Python 2.7 image -# https://developer.fedoraproject.org/tools/docker/docker-images.html -FROM centos/python-27-centos7 AS base +# Generate a container that generates requirements.txt +ARG PY_VERSION=3.7 +FROM python:${PY_VERSION} as source -# Project maintainer -LABEL maintainer="frolland@redhat.com" +ARG DEV -# Required env vars -ENV LD_LIBRARY_PATH="/opt/rh/python27/root/usr/lib64/" \ - ENABLE_PIPENV=true +ENV ENABLE_PIPENV=true # Install pipenv RUN pip install --upgrade pipenv +COPY Pipfile ./Pipfile + +# Generate requirements.txt file from Pipfile +RUN if [ -z ${DEV} ]; \ + then \ + pipenv lock -r > requirements.txt; \ + else \ + pipenv lock --dev -r > requirements.txt; \ + fi + +# Generate work image +ARG PY_VERSION +FROM python:${PY_VERSION} + +# Project maintainer +LABEL maintainer="frolland@redhat.com" + +# Copy pipfile to default WORKDIR +COPY --from=source requirements.txt ./requirements.txt + +# Install dependencies +RUN pip install -r requirements.txt + # Copy application to default WORKDIR COPY . ./ -# Install dependencies from pipfile -RUN pipenv install - # Server port EXPOSE 8880 # Server command -ENTRYPOINT [ "pipenv" ] CMD [ "run", "python", "rose-server"] diff --git a/README.md b/README.md index 7019f1b2..12c88bed 100644 --- a/README.md +++ b/README.md @@ -98,11 +98,13 @@ Open a browser at http://\:8880 to view and control the game. Build the Docker image: - docker build -t rose:server . + docker build -t rose_server . Run the Docker image on port 8880: +(If you don't want to see the log of the run in the current window, replace `-it` with `-d`) + + docker run -it --rm --name=rose_server -p 8880:8880 rose_server python ./rose-server - docker run -it --rm -p 8880 rose:server Open a browser at http://\:8880 to view and control the game. @@ -112,12 +114,12 @@ In a new window, open your virtual environment: pipenv shell -Create your driver file: - +Create your driver file: + cp examples/none.py mydriver.py -Edit the file mydriver.py and change the driver_name variable to your name. - +Edit the file mydriver.py and change the driver_name variable to your name. + Start up the client, using your driver file: @@ -127,6 +129,11 @@ The server address can be specified that way (Replace '10.20.30.44' with your se ./rose-client -s 10.20.30.44 mydriver.py +For running the driver on the Docker container use: + + docker exec -it rose_server python ./rose-client examples/random-driver.py + + For driver modules, see the [examples](examples) directory. You can run the game with just 1 driver! @@ -168,6 +175,10 @@ To open a shell for development, use: pipenv --python /usr/local/bin/python3.7 shell +For development in docker, use: + + docker build --build-arg DEV=True -t rose_dev . + Before submitting patches, please run the tests: flake8 From 1f1ec7be1bca716650da237884dceff7a0881e89 Mon Sep 17 00:00:00 2001 From: Anna Dinaburg Vulikh Date: Mon, 3 May 2021 13:31:33 +0300 Subject: [PATCH 3/3] Removed extra spaces --- README.md | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 12c88bed..537fc8db 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,6 @@ Refer to our GitHub pages for the course materials and additional resources: - [Read](https://opensource.com/education/15/9/open-source-education-israel) an article by Laura Novich on [opensource.com](https://opensource.com) - ## Requirements Once we're in the ROSE directory, we need to verify we have pipenv installed. @@ -61,7 +60,7 @@ your user: ## Getting started -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. +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 pipenv to create a virtual environment and to install the rest of the dependencies: @@ -70,7 +69,7 @@ Use pipenv to create a virtual environment and to install the rest of the depend You can also install packages from your distribution, but they may be too old. -After creating the environment, we want to activate and enter our environment: +After creating the environment, we want to activate and enter our environment: pipenv shell @@ -105,12 +104,11 @@ Run the Docker image on port 8880: docker run -it --rm --name=rose_server -p 8880:8880 rose_server python ./rose-server - Open a browser at http://\:8880 to view and control the game. ## Running a driver -In a new window, open your virtual environment: +In a new window, open your virtual environment: pipenv shell @@ -120,7 +118,6 @@ Create your driver file: Edit the file mydriver.py and change the driver_name variable to your name. - Start up the client, using your driver file: ./rose-client mydriver.py @@ -133,14 +130,12 @@ For running the driver on the Docker container use: docker exec -it rose_server python ./rose-client examples/random-driver.py - For driver modules, see the [examples](examples) directory. You can run the game with just 1 driver! To let 2 drivers compete, repeat these commands in 2 terminals. -Command line interface ----------------------- +## Command line interface You can control the game from the command line using the rose-admin tool. @@ -157,12 +152,10 @@ would change game rate to 10 frames per second: ./rose-admin set-rate 10 - ## Creating a tarball python setup.py sdist - ## Developing Should you want to contribute to the project, please read the [Code of Conduct](docs/code-of-conduct.md).