From b06ab2864af109078f4bcf08f14f6ac52e3fbf8d Mon Sep 17 00:00:00 2001 From: Adam Gleave Date: Thu, 2 Jan 2020 11:48:26 -0800 Subject: [PATCH] Fix Docker build script (#640) * Pass build arguments to Docker * Fix Codacy downloader to work with latest releases * Add automatic Docker push for release * Update changelog * Print pytype version in CI * Fix type error * Fix other type false positive --- .travis.yml | 2 +- Dockerfile | 4 ++-- docs/misc/changelog.rst | 4 ++++ scripts/build_docker.sh | 7 ++++++- stable_baselines/common/vec_env/subproc_vec_env.py | 2 +- stable_baselines/logger.py | 2 ++ 6 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3257911d74..c88d8ad460 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,7 +43,7 @@ jobs: - name: "Type Checking" script: - - 'docker run --rm --mount src=$(pwd),target=/root/code/stable-baselines,type=bind ${DOCKER_IMAGE} bash -c "cd /root/code/stable-baselines/ && pytype"' + - 'docker run --rm --mount src=$(pwd),target=/root/code/stable-baselines,type=bind ${DOCKER_IMAGE} bash -c "cd /root/code/stable-baselines/ && pytype --version && pytype"' - stage: Codacy Trigger if: type != pull_request diff --git a/Dockerfile b/Dockerfile index 254b2bba59..92089c5f5a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,7 +33,7 @@ RUN \ . $VENV/bin/activate && \ cd $CODE_DIR && \ pip install --upgrade pip && \ - if [[ $USE_GPU == "True" ]]; then \ + if [ "$USE_GPU" = "True" ]; then \ TENSORFLOW_PACKAGE="tensorflow-gpu==1.8.0"; \ else \ TENSORFLOW_PACKAGE="tensorflow==1.8.0"; \ @@ -47,6 +47,6 @@ ENV PATH=$VENV/bin:$PATH # Codacy code coverage report: used for partial code coverage reporting RUN cd $CODE_DIR && \ - curl -Ls -o codacy-coverage-reporter.jar "$(curl -Ls https://api.github.com/repos/codacy/codacy-coverage-reporter/releases/latest | jq -r '.assets | map({name, browser_download_url} | select(.name | (contains("codacy-coverage-reporter") and endswith("assembly.jar")))) | .[0].browser_download_url')" + curl -Ls -o codacy-coverage-reporter.jar "$(curl -Ls https://api.github.com/repos/codacy/codacy-coverage-reporter/releases/latest | jq -r '.assets | map({name, browser_download_url} | select(.name | (startswith("codacy-coverage-reporter") and contains("assembly") and endswith(".jar")))) | .[0].browser_download_url')" CMD /bin/bash diff --git a/docs/misc/changelog.rst b/docs/misc/changelog.rst index bd8e0a802f..8d1d369cfb 100644 --- a/docs/misc/changelog.rst +++ b/docs/misc/changelog.rst @@ -15,9 +15,13 @@ Breaking Changes: New Features: ^^^^^^^^^^^^^ +- Docker build script, `scripts/build_docker.sh`, can push images automatically. + Bug Fixes: ^^^^^^^^^^ +- Fixed Docker build script, `scripts/build_docker.sh`, to pass `USE_GPU` build argument. + Deprecations: ^^^^^^^^^^^^^ diff --git a/scripts/build_docker.sh b/scripts/build_docker.sh index 9a4bf73e1d..69bea8b144 100755 --- a/scripts/build_docker.sh +++ b/scripts/build_docker.sh @@ -13,5 +13,10 @@ else TAG="${TAG}-cpu" fi -docker build --build-arg PARENT_IMAGE=${PARENT} -t ${TAG}:${VERSION} . +docker build --build-arg PARENT_IMAGE=${PARENT} --build-arg USE_GPU=${USE_GPU} -t ${TAG}:${VERSION} . +docker tag ${TAG}:${VERSION} ${TAG}:latest +if [[ ${RELEASE} == "True" ]]; then + docker push ${TAG}:${VERSION} + docker push ${TAG}:latest +fi diff --git a/stable_baselines/common/vec_env/subproc_vec_env.py b/stable_baselines/common/vec_env/subproc_vec_env.py index 2cc451a298..e725cd10c8 100644 --- a/stable_baselines/common/vec_env/subproc_vec_env.py +++ b/stable_baselines/common/vec_env/subproc_vec_env.py @@ -87,7 +87,7 @@ def __init__(self, env_fns, start_method=None): for work_remote, remote, env_fn in zip(self.work_remotes, self.remotes, env_fns): args = (work_remote, remote, CloudpickleWrapper(env_fn)) # daemon=True: if the main process crashes, we should not cause things to hang - process = ctx.Process(target=_worker, args=args, daemon=True) + process = ctx.Process(target=_worker, args=args, daemon=True) # pytype:disable=attribute-error process.start() self.processes.append(process) work_remote.close() diff --git a/stable_baselines/logger.py b/stable_baselines/logger.py index fe3c9d2f3f..0cfcde68db 100644 --- a/stable_baselines/logger.py +++ b/stable_baselines/logger.py @@ -233,6 +233,8 @@ def writekvs(self, kvs): summary = tf.Summary(value=[summary_val(k, v) for k, v in kvs.items() if valid_float_value(v)]) event = event_pb2.Event(wall_time=time.time(), summary=summary) event.step = self.step # is there any reason why you'd want to specify the step? + if self.writer is None: + raise ValueError("Attempt to write after close().") self.writer.WriteEvent(event) self.writer.Flush() self.step += 1