-
Notifications
You must be signed in to change notification settings - Fork 25
Add the ability to add a docker config image #33
Conversation
readthedocs_build/config/config.py
Outdated
@@ -30,6 +26,18 @@ | |||
TYPE_REQUIRED = 'type-required' | |||
PYTHON_INVALID = 'python-invalid' | |||
|
|||
DOCKER_BUILD_IMAGES = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this updatable from a setting as it was, so we can define a custome DOCKER_BUILD_IMAGES in our development instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, good call. Hadn't thought of that specific use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 on a setting, we shouldn't change that behavior. This is important for all non-prod instances.
source_file=str(tmpdir.join('readthedocs.yml')), | ||
source_position=0) | ||
build.validate_build() | ||
assert build['build']['image'] == 'latest' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't we check here that 3.6
was the version selected by default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we're opinionated about this yet. We should be eventually though.
+1 on checks for default version though, that seems to be missing from test cases
source_file=str(tmpdir.join('readthedocs.yml')), | ||
source_position=0) | ||
build.validate_build() | ||
assert build['build']['image'] == '2.0' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here but 2.7, I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure we want to specify python magically, based on container image, do we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already do this to a certain degree, but i think the python version tests are testing some of this. For example:
python['version'] = 3
is valid, and exists in the dashboard, we should select the right python 3 version (pretty sure tests exist here)python['version'] = None
should return2.7
for now, until we're opinionated about forcing3.6
default (not work i think we need to make for ourselves just yet, but i'd like to see this soon)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we don't want that, what would it happen if the user doesn't specify the python version? should the test fail? do we have a test for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I think some of the changes here are regressing on configuration ability and our error reporting ability, but it seems we can uphold these with a bit more logic around validation and ordering.
docs/spec.rst
Outdated
Options for setting the docker configuration. | ||
|
||
``image`` | ||
This sets the docker image to use on the build, as defined `here <https://github.com/rtfd/readthedocs-docker-images/blob/master/CONTRIBUTING.rst#releases>`_. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps "docker image" -> "build image" for consistency on nomenclature. It's not a docker image to end users, nor can arbitrary docker images be used.
readthedocs_build/config/config.py
Outdated
@@ -30,6 +26,18 @@ | |||
TYPE_REQUIRED = 'type-required' | |||
PYTHON_INVALID = 'python-invalid' | |||
|
|||
DOCKER_BUILD_IMAGES = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 on a setting, we shouldn't change that behavior. This is important for all non-prod instances.
readthedocs_build/config/config.py
Outdated
except (KeyError, TypeError): | ||
pass | ||
return self.PYTHON_SUPPORTED_VERSIONS | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason to remove this? Seems we want validation on this still.
readthedocs_build/config/config.py
Outdated
|
||
# Set the valid python versions for this container | ||
img = build['image'] | ||
self.PYTHON_SUPPORTED_VERSIONS = DOCKER_BUILD_IMAGES[img]['python']['supported_versions'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PYTHON_SUPPORTED_VERSIONS
is named as a constant and shouldn't be treated as a variable. I think the usage of get_valid_python_versions
was more correct. Also, validation steps probably shouldn't have side effects like altering the state here, so that's probably also another good reason to make this a method that merges sources together.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ordering of the validation is going to continue to matter (because we need to read the docker image, then determine python version), so it will have to set state somewhere, but agreed on making it a bit nicer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we are/were doing ordering of validation one level up anyways:
https://github.com/rtfd/readthedocs-build/blob/master/readthedocs_build/config/config.py#L133-L157
So, dependencies would naturally be filled there, as the validation steps are ordered there
env_config={'python': {'supported_versions': [3.5, 3.6]}} | ||
) | ||
build.validate_python() | ||
assert build['python']['version'] == 3.6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems we should make this error work instead of removing it. We use supported versions for giving intelligent errors to users.
source_file=str(tmpdir.join('readthedocs.yml')), | ||
source_position=0) | ||
build.validate_build() | ||
assert build['build']['image'] == 'latest' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we're opinionated about this yet. We should be eventually though.
+1 on checks for default version though, that seems to be missing from test cases
source_file=str(tmpdir.join('readthedocs.yml')), | ||
source_position=0) | ||
build.validate_build() | ||
assert build['build']['image'] == '2.0' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already do this to a certain degree, but i think the python version tests are testing some of this. For example:
python['version'] = 3
is valid, and exists in the dashboard, we should select the right python 3 version (pretty sure tests exist here)python['version'] = None
should return2.7
for now, until we're opinionated about forcing3.6
default (not work i think we need to make for ourselves just yet, but i'd like to see this soon)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just small suggestions/comments.
# These map to coordisponding settings in the .org, | ||
# so they haven't been renamed. | ||
DOCKER_IMAGE = '{}:{}'.format(DOCKER_DEFAULT_IMAGE, DOCKER_DEFAULT_VERSION) | ||
DOCKER_IMAGE_SETTINGS = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shoulnd't we have the same .update()
we have in .org?
https://github.com/rtfd/readthedocs.org/pull/3339/files#diff-3fbfb50cb375355069e83003f500d2c8R44
or at least, the getattr
since otherwise there is no way to override this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, fixed that below -- I don't want this code to depend on RTD settings, so we pass it in.
str(_build['image']), | ||
self.DOCKER_SUPPORTED_VERSIONS, | ||
) | ||
if ':' not in build['image']: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems that this condition will be always True
, since we are accepting 1.0
, 2.0
and latest
as valid choices (from DOCKER_SUPPORTED_VERSIONS)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the build image is passed from RTD it will be fully qualified already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also the default (not from YAML)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if I follow you. If the image is passed from RTD or not from YAML we won't be inside if 'build' in self.raw_config
since I understood that raw_config
is the YAML. So, maybe this if should be outside this block.
source_position=0) | ||
with raises(InvalidConfig) as excinfo: | ||
build.validate_build() | ||
assert excinfo.value.key == 'build' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, why we don't use something like regular unittest.TestCase
and assertEqual
and those stuffs in this project?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is just how this code was written originally. shrug
This PR closes #24 |
This removes the old way of passing in the docker & python support info, and keeps it inside rtd-build. This is needed so we can verify the values the user has passed in for the docker image and python version are valid together!