Repository: readthedocs/readthedocs.org

Issue:
Sample some projects for Docker image 5.0rc1
We just released `4.0` and `5.0rc1`.

So,

* `2.0` got deprecated
* `3.0` became `stable`
* `4.0` became `latest`

Now, we want to start testing `5.0rc1` with some projects. This image have [some changes](https://github.com/rtfd/readthedocs-docker-images/compare/4.0.0..master).

We want to create a Feature flag that "no matter has the user selected for the docker image we want to use `5.0rc` for `container_image`" when building the docs.

Once we have this feature added, we can start with 100, 500, 1500 and 5000 projects for a month and half and after that, release the new image.


Discussion:
Current implementation of the config module allow us to override user's image frmo the db field `container_image`
Yes, but we don't want to do that avoid future miss-understandings. We just released these images and we didn't know why there were projects with `4.0rc1`, it it was because we wanted to test the image or because they needed something specific from that image. Now, we want to avoid that confusion by creating a Feature flag.

This flag, will be useful to test all the `rc` releases, not just this one in particular.

Resolving patch:
diff --git a/readthedocs/doc_builder/environments.py b/readthedocs/doc_builder/environments.py
--- a/readthedocs/doc_builder/environments.py
+++ b/readthedocs/doc_builder/environments.py
@@ -32,6 +32,7 @@
 from readthedocs.builds.models import BuildCommandResultMixin
 from readthedocs.core.utils import slugify
 from readthedocs.projects.constants import LOG_TEMPLATE
+from readthedocs.projects.models import Feature
 from readthedocs.restapi.client import api as api_v2
 
 from .constants import (
@@ -726,10 +727,18 @@ def __init__(self, *args, **kwargs):
                 project_name=self.project.slug,
             )[:DOCKER_HOSTNAME_MAX_LEN],
         )
+
+        # Decide what Docker image to use, based on priorities:
+        # Use the Docker image set by our feature flag: ``testing`` or,
+        if self.project.has_feature(Feature.USE_TESTING_BUILD_IMAGE):
+            self.container_image = 'readthedocs/build:testing'
+        # the image set by user or,
         if self.config and self.config.build.image:
             self.container_image = self.config.build.image
+        # the image overridden by the project (manually set by an admin).
         if self.project.container_image:
             self.container_image = self.project.container_image
+
         if self.project.container_mem_limit:
             self.container_mem_limit = self.project.container_mem_limit
         if self.project.container_time_limit:
diff --git a/readthedocs/projects/models.py b/readthedocs/projects/models.py
--- a/readthedocs/projects/models.py
+++ b/readthedocs/projects/models.py
@@ -1009,6 +1009,7 @@ def add_features(sender, **kwargs):
     ALLOW_V2_CONFIG_FILE = 'allow_v2_config_file'
     MKDOCS_THEME_RTD = 'mkdocs_theme_rtd'
     DONT_SHALLOW_CLONE = 'dont_shallow_clone'
+    USE_TESTING_BUILD_IMAGE = 'use_testing_build_image'
 
     FEATURES = (
         (USE_SPHINX_LATEST, _('Use latest version of Sphinx')),
@@ -1023,6 +1024,8 @@ def add_features(sender, **kwargs):
         (MKDOCS_THEME_RTD, _('Use Read the Docs theme for MkDocs as default theme')),
         (DONT_SHALLOW_CLONE, _(
             'Do not shallow clone when cloning git repos')),
+        (USE_TESTING_BUILD_IMAGE, _(
+            'Use Docker image labelled as `testing` to build the docs')),
     )
 
     projects = models.ManyToManyField(


Test patch: