Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save Docker image data in JSON file only for DockerBuildEnvironment #3897

Merged
merged 1 commit into from Apr 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 20 additions & 8 deletions readthedocs/doc_builder/python_environments.py
Expand Up @@ -8,13 +8,14 @@
import logging
import os
import shutil
import six
from builtins import object, open

import six
from django.conf import settings

from readthedocs.doc_builder.config import ConfigWrapper
from readthedocs.doc_builder.constants import DOCKER_IMAGE
from readthedocs.doc_builder.environments import DockerBuildEnvironment
from readthedocs.doc_builder.loader import get_builder_class
from readthedocs.projects.constants import LOG_TEMPLATE
from readthedocs.projects.models import Feature
Expand Down Expand Up @@ -147,30 +148,41 @@ def is_obsolete(self):
env_build_image = env_build.get('image', None)
env_build_hash = env_build.get('hash', None)

build_image = self.config.build_image or DOCKER_IMAGE
if isinstance(self.build_env, DockerBuildEnvironment):
build_image = self.config.build_image or DOCKER_IMAGE
image_hash = self.build_env.image_hash
else:
# e.g. LocalBuildEnvironment
build_image = None
image_hash = None

# If the user define the Python version just as a major version
# (e.g. ``2`` or ``3``) we won't know exactly which exact version was
# used to create the venv but we can still compare it against the new
# one coming from the project version config.
return any([
env_python_version != self.config.python_full_version,
env_build_image != build_image,
env_build_hash != self.build_env.image_hash,
env_build_hash != image_hash,
])

def save_environment_json(self):
"""Save on disk Python and build image versions used to create the venv."""
build_image = self.config.build_image or DOCKER_IMAGE
data = {
'python': {
'version': self.config.python_full_version,
},
'build': {
'image': build_image,
'hash': self.build_env.image_hash,
},
}

if isinstance(self.build_env, DockerBuildEnvironment):
build_image = self.config.build_image or DOCKER_IMAGE
data.update({
'build': {
'image': build_image,
'hash': self.build_env.image_hash,
},
})

with open(self.environment_json_path(), 'w') as fpath:
# Compatibility for Py2 and Py3. ``io.TextIOWrapper`` expects
# unicode but ``json.dumps`` returns str in Py2.
Expand Down