diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..ffabc800 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +/classroom +/docs +Makefile \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..a9136868 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,42 @@ +# Generate a container that generates requirements.txt +ARG PY_VERSION=3.7 +FROM python:${PY_VERSION} as source + +ARG DEV + +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 . ./ + +# Server port +EXPOSE 8880 + +# Server command +CMD [ "run", "python", "rose-server"] diff --git a/README.md b/README.md index f46c2b44..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 @@ -94,18 +93,30 @@ 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: +(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 + +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 -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: @@ -115,13 +126,16 @@ 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! 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. @@ -138,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). @@ -156,6 +168,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