Skip to content

Commit

Permalink
Switch to Docker for tests (openai#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
gdb authored Aug 10, 2016
1 parent be1eeec commit fabb897
Show file tree
Hide file tree
Showing 8 changed files with 2,076 additions and 59 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.tox
51 changes: 8 additions & 43 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,15 @@
language: python
python:
- "2.7"
- "3.4"
dist: trusty
sudo: required
cache:
apt: true
pip: true
addons:
apt:
sources:
- george-edison55-precise-backports # cmake 3.2.3
- deadsnakes
packages:
- cmake
- cmake-data
- python-dev
- python3.4-dev
- swig
- libav-tools
- python-numpy
- libboost-all-dev
- libsdl2-dev
- libjpeg-dev
- zlib1g-dev
- libblas-dev
- liblapack-dev
- gfortran
- python-opengl
language: python
services:
- docker
before_install:
# Start an X server so rendering works.
- Xvfb :12 -screen 0 800x600x24 +extension RANDR &

# Prime the cache. We currently manually keep this synced.
- docker pull quay.io/openai/gym:test
- docker build -f test.dockerfile -t quay.io/openai/gym:test .
script:
# In a pull request, there are no secrets, and hence no MuJoCo:
# https://docs.travis-ci.com/user/pull-requests#Security-Restrictions-when-testing-Pull-Requests.
- '[ -z ${MUJOCO_KEY_BUNDLE+x} ] || ( mkdir -p ~/.mujoco && curl https://openai-public.s3-us-west-2.amazonaws.com/mujoco/$MUJOCO_KEY_BUNDLE.tar.gz | tar xz -C ~/.mujoco )'

# Without this line, Travis has fork()s fail with an out of memory
# error. (These fork()s are for spawning the subprocess for video
# recording.) We should debug the memory usage at some stage, but
# simply setting overcommit is a good starting point.
- sudo sysctl -w vm.overcommit_memory=1
env:
- DISPLAY=:12
install: travis_wait pip install -r requirements_dev.txt
script: nose2
- docker run -e MUJOCO_KEY_BUNDLE="${MUJOCO_KEY_BUNDLE:-}" quay.io/openai/gym:test tox

notifications:
slack:
Expand Down
24 changes: 13 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@
FROM ubuntu:14.04

RUN apt-get update \
&& apt-get install -y xorg-dev \
libgl1-mesa-dev \
xvfb \
libxinerama1 \
libxcursor1 \
libglu1-mesa \
libav-tools \
&& apt-get install -y libav-tools \
python-numpy \
python-scipy \
python-pyglet \
Expand All @@ -17,16 +11,24 @@ RUN apt-get update \
libjpeg-dev \
curl \
cmake \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& easy_install pip
swig \
python-opengl \
libboost-all-dev \
libsdl2-dev \
wget \
unzip \
git \
xpra \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& easy_install pip

WORKDIR /usr/local/gym
RUN mkdir gym && touch gym/__init__.py
COPY ./gym/version.py ./gym
COPY ./requirements.txt .
COPY ./setup.py .
RUN pip install -r requirements.txt
RUN pip install -e .[all]

# Finally, upload our actual code!
COPY . /usr/local/gym
Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ install:
pip install -r requirements.txt

test:
nose2
docker build -f test.dockerfile -t quay.io/openai/gym:test .

upload:
rm -rf dist
python setup.py sdist
twine upload dist/*

docker-build:
docker build -t quay.io/openai/gym .

docker-run:
docker run -ti quay.io/openai/gym bash
24 changes: 22 additions & 2 deletions bin/docker_entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,29 @@

set -e

# Set up display; otherwise rendering will cause segfaults
path=$(cd $(dirname "$0") && pwd)

[ -z ${MUJOCO_KEY_BUNDLE+x} ] || ( mkdir -p ~/.mujoco && curl https://openai-public.s3-us-west-2.amazonaws.com/mujoco/$MUJOCO_KEY_BUNDLE.tar.gz | tar xz -C ~/.mujoco )

# Set up display; otherwise rendering will fail
rm -f /tmp/.X12-lock
Xvfb :12 -screen 0 800x600x24 +extension RANDR 2>/dev/null &
"$path/../vendor/Xdummy" :12 &
export DISPLAY=:12

# Wait for the file to come up
display=12
file="/tmp/.X11-unix/X$display"
for i in $(seq 1 10); do
if [ -e "$file" ]; then
break
fi

echo "Waiting for $file to be created (try $i/10)"
sleep "$i"
done
if ! [ -e "$file" ]; then
echo "Timing out: $file was not created"
exit 1
fi

exec "$@"
42 changes: 42 additions & 0 deletions test.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# A Dockerfile that sets up a full Gym install
FROM ubuntu:14.04

RUN apt-get update \
&& apt-get install -y libav-tools \
python-numpy \
python-scipy \
python-pyglet \
python-setuptools \
libpq-dev \
libjpeg-dev \
curl \
cmake \
swig \
python-opengl \
libboost-all-dev \
libsdl2-dev \
wget \
unzip \
git \
xpra \
python3-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& easy_install pip

WORKDIR /usr/local/gym
RUN mkdir gym && touch gym/__init__.py
COPY ./gym/version.py ./gym
COPY ./requirements.txt .
COPY ./setup.py .
COPY ./tox.ini .

RUN pip install tox
# Install the relevant dependencies. Keep printing so Travis knows we're alive.
RUN ["bash", "-c", "( while true; do echo '.'; sleep 60; done ) & tox --notest"]

# Finally, upload our actual code!
COPY . /usr/local/gym

ENTRYPOINT ["/usr/local/gym/bin/docker_entrypoint"]
CMD ["tox"]
30 changes: 28 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,21 @@ passenv=DISPLAY TRAVIS*
deps =
nose2
mock
atari_py>=0.0.17
Pillow
PyOpenGL
pachi-py>=0.0.19
box2d-py
PyOpenGL
doom_py>=0.0.11
mujoco_py>=0.4.3
keras
theano
numpy>=1.10.4
requests>=2.0
six
pyglet>=1.2.0
commands =
pip install -e .[all]
nose2 {posargs}

[testenv:py27]
Expand All @@ -22,6 +35,19 @@ passenv=DISPLAY TRAVIS*
deps =
nose2
mock
atari_py>=0.0.17
Pillow
PyOpenGL
pachi-py>=0.0.19
box2d-py
PyOpenGL
doom_py>=0.0.11
mujoco_py>=0.4.3
keras
theano
numpy>=1.10.4
requests>=2.0
six
pyglet>=1.2.0
commands =
pip install -e .[all]
nose2 {posargs}
Loading

0 comments on commit fabb897

Please sign in to comment.