Skip to content
This repository has been archived by the owner on Sep 12, 2018. It is now read-only.

rearranging code into a proper python package, per #1 #297

Merged
merged 4 commits into from
Apr 22, 2014

Conversation

mhrivnak
Copy link
Contributor

No description provided.



VERSION = '0.6.6'
VERSION = '0.6.7'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm making some assumptions here about your release process. I'm happy to undo this or change it to a different version if that's preferable.

@mhrivnak
Copy link
Contributor Author

Looks like the travis build failed because it couldn't connect to github. Can someone with access restart that build? There should be a button on the build page: http://stackoverflow.com/questions/17606874/trigger-a-travis-ci-rebuild-without-pushing-a-commit

UPDATE: looks like someone did restart it

@samalba
Copy link
Contributor

samalba commented Mar 24, 2014

What about adding a bin/script to start the registry like this:

$ pip install docker-registry
$ docker-registry -c config/config.yml

This would take care of spawning the gunicorn. So we can also remove the run.sh script. What do you think?

@wking
Copy link
Contributor

wking commented Mar 26, 2014

On Sun, Mar 23, 2014 at 01:41:54PM -0700, Michael Hrivnak wrote:

I'd prefer relative imports here. For example, in
docker_registry/init.py:

from .lib import config

to the current (as of 555dbb2):

from docker_registry.lib import config

Importing just the final module (without the associated namespacing)
will also allow for shorter lines. For example, in
test/test_images.py,

images.cfg._config['nginx_x_accel_redirect'] = accel_prefix

instead of the current:

docker_registry.images.cfg._config['nginx_x_accel_redirect']
= accel_prefix

You can also avoid some wrapped lines in your setup.py by storing
os.path.dirname(os.path.abspath(file)) in a local variable:

_this_dir = os.path.dirname(os.path.abspath(file))
desc_path = os.path.join(_this_dir, 'README.md')

req_path = os.path.join(_this_dir, 'requirements.txt')

which reads more easily to me.

I think that this would be a good time to move registry.app.VERSION to
the more conventional docker_registry.version, and also shift the
config import to a less central location (wsgi.py?), although those
can certainly happen in subsequent commits in this PR.

@mhrivnak
Copy link
Contributor Author

I made the changes requested by @wking and am working on replacing the run.sh with a python console-script. The latter is a little more complex than one might expect, but I have something working now that just needs a little polish.

@mhrivnak
Copy link
Contributor Author

mhrivnak commented Apr 3, 2014

I replaced run.sh with a console script, so this is ready for another review.

@samalba
Copy link
Contributor

samalba commented Apr 15, 2014

cc @shin- Could you review?

@shin-
Copy link
Contributor

shin- commented Apr 15, 2014

Sorry that took so long. Works for me, only had to update the boto dependency.

LGTM.

@samalba
Copy link
Contributor

samalba commented Apr 16, 2014

Working on merging this and we do want to merge it, believe me :-)

I am testing locally and I have few more comments.

  1. What's the motivation behind having a directory named "docker_registry", any way to keep all files under "registry" and still have the main package called "docker-registry"? Maybe I am totally wrong there, I don't know setuptools enough but I thought it's possible to map a package_name to a directory...
  2. for the bin/script, I am thinking of a script located in "bin/docker-registry" that spawns gunicorn (it can be a shell script that forward its arguments). Then if you want to spawn gunicorn yourself, you use gunicorn docker_registry:wsgi?

Not sure if your console script addresses the second point, I tried to test it but got conflict in the checkout... Probably need a rebase.

@mhrivnak
Copy link
Contributor Author

  1. Whatever the directory holding the code is named will be what people import, and it will be on the python path (as our root module), sharing the global python namespace. As this branch currently stands, you can import docker_registry. "registry" would be a very generic name to be in the global namespace. It's a best practice for the python package name to be roughly equivalent to the name used by the root module, and I don't think "registry" would make a good package name. Perhaps the nail in that coffin is that there is already a package called "registry" on pypi, and it's a Windows registry API.

    As for "-" vs. "_", that's a quirk of python package naming. "-" is illegal in a variable name, so we can't use that in the root module name. But PEP8 says of package names: "the use of underscores is discouraged." The generally accepted way to reconcile this discrepancy is to name a package "a-b" and name its root module "a_b". For example, if you go on pypi and search for "django", you'll see a long list of packages named "django-x" whose module is named "django_x".

    It might be more clear to put this is usability terms; you pip install <package-name>, and import <root_module_name>.

    So my strong advice from a pure python packaging perspective is to go with the names that are in this branch, but I will quite happily change the branch to use any variation you prefer. Or if it would be helpful to continue this discussion, I'm happy to answer any additional questions, or elaborate on the above.

  2. The docker-registry console script I created does exactly what run.sh did. The only change is that the new console script adds help/usage text. As for its location, (I apologize if this is old news to you) a benefit of having a standard python package is that you can write a function to be your console script without actually having to make something like bin/docker-registry. When you install the python package, such as with pip, python will auto-generate a skeleton file in the "right place" for your OS that calls the specified function. So in my branch, you won't find a docker-registry executable, but you will find an entry point in setup.py defining where the function is that gets called by the generated executable.

    Given that I ported the run.sh script to fit in with the python package, do you think it would be reasonable to save behavioral changes for another PR?

@wking
Copy link
Contributor

wking commented Apr 16, 2014

On Tue, Apr 15, 2014 at 10:01:25PM -0700, Michael Hrivnak wrote:

  1. … The generally accepted way to reconcile this discrepancy is to
    name a package "a-b" and name its root module "a_b"… So my strong
    advice from a pure python packaging perspective is to go with the
    names that are in this branch…

Outsider vote for package name 'docker-registry' and root module
'docker_registry'. It looks like the current tip of this PR (bf3360a)
is using 'docker_registry' for both.

  1. The docker-registry console script I created…

I'd prefer if docker_registry.run_gunicorn was moved to
docker_registry.gunicorn.run. This would avoid cluttering
docker_registry/init.py, which is complicated enough with it's
existing import-to-trigger-side-effects behaviour. As a side benefit,
DESCRIPTION could be moved to docker_registry.gunicorn.doc.

Another minor quibble is the lack of a summary line 1 for
run_gunicorn.doc.

@mhrivnak
Copy link
Contributor Author

Thanks for catching the package name! I have fixed that, and I improved the doc block for "run_gunicorn".

I don't feel strongly about where the run_gunicorn function lives.

bacongobbler pushed a commit to deis/deis that referenced this pull request Apr 19, 2014
After upgrading the private registry to 0.6.8, there were some
changes to the API that were missed. For example, the docker version
is now mandatory[1].

If you have docker v0.10.0 or higher, there is also a checksum computation
check done on each push, so I hardcoded the user-agent to v0.9.0. This is
a stopgap until

a) we update the API calls to v0.10.0
b) we replace this component with a docker-registry python package[2]

[1]: docker-archive/docker-registry@64f4198
[2]: docker-archive/docker-registry#297

fixes #779
@shin-
Copy link
Contributor

shin- commented Apr 22, 2014

I'm fine with run_gunicorn living there for now. We can open a new PR if it proves to be detrimental at some point.

@shin- shin- merged commit e59fce6 into docker-archive:master Apr 22, 2014
@shin-
Copy link
Contributor

shin- commented Apr 22, 2014

Thanks!

@wking
Copy link
Contributor

wking commented Apr 22, 2014

On Tue, Apr 22, 2014 at 10:34:26AM -0700, Joffrey F wrote:

Merged #297.

This maybe should have been rebased after #247 landed. Do we want a
new PR to shift lib/index?

@shin-
Copy link
Contributor

shin- commented Apr 22, 2014

@wking I've rebased it before merging, see 9baadda . If you spot any inconsistency or see something I missed don't hesitate to let me know / call me out on it, but I think we're good.

@wking
Copy link
Contributor

wking commented Apr 22, 2014

On Tue, Apr 22, 2014 at 10:45:28AM -0700, Joffrey F wrote:

I've rebased it before merging, see
9baadda
. If you spot any inconsistency or see something I missed don't
hesitate to let me know / call me out on it, but I think we're good.

Ah, I'd missed that. 9baadda looks good to me.

wking added a commit to wking/docker-registry that referenced this pull request Jul 18, 2014
This was initially added in 534c6da (run.sh: Add '$GUNICORN_OPTS
"$@"' to gunicorn invocation, 2014-02-13), but didn't survive the
translation to a setuptools entry_points in bf3360a (replacing run.sh
with a "docker-registry" console script, 2014-04-02).  bf3360a was
part of docker-archive#297, which branched off before
534c6da landed with docker-archive#247, and the
entry_points invocation wasn't updated to reflect the change.

The syntax has also changed a bit, since we're invoking Gunicorn from
Python instead of Bash.  Instead of dropping the string verbatim onto
the command-line ($GUNICORN_OPTS), it now goes through the usual
docker_registry.server.env.source YAML parsing (884b418, Type from
environment properly (like Config), 2014-06-23).  So instead of
something like:

  GUNICORN_OPTS='--preload --log-syslog'

you should now be using:

  GUNICORN_OPTS='[--preload, --log-syslog]'
wking added a commit to wking/docker-registry that referenced this pull request Jul 21, 2014
This was initially added in 534c6da (run.sh: Add '$GUNICORN_OPTS
"$@"' to gunicorn invocation, 2014-02-13), but didn't survive the
translation to a setuptools entry_points in bf3360a (replacing run.sh
with a "docker-registry" console script, 2014-04-02).  bf3360a was
part of docker-archive#297, which branched off before
534c6da landed with docker-archive#247, and the
entry_points invocation wasn't updated to reflect the change.

The syntax has also changed a bit, since we're invoking Gunicorn from
Python instead of Bash.  Instead of dropping the string verbatim onto
the command-line ($GUNICORN_OPTS), it now goes through the usual
docker_registry.server.env.source YAML parsing (884b418, Type from
environment properly (like Config), 2014-06-23).  So instead of
something like:

  GUNICORN_OPTS='--preload --log-syslog'

you should now be using:

  GUNICORN_OPTS='[--preload, --log-syslog]'
wking added a commit to wking/docker-registry that referenced this pull request Jul 23, 2014
This was initially added in 534c6da (run.sh: Add '$GUNICORN_OPTS
"$@"' to gunicorn invocation, 2014-02-13), but didn't survive the
translation to a setuptools entry_points in bf3360a (replacing run.sh
with a "docker-registry" console script, 2014-04-02).  bf3360a was
part of docker-archive#297, which branched off before
534c6da landed with docker-archive#247, and the
entry_points invocation wasn't updated to reflect the change.

The syntax has also changed a bit, since we're invoking Gunicorn from
Python instead of Bash.  Instead of dropping the string verbatim onto
the command-line ($GUNICORN_OPTS), it now goes through the usual
docker_registry.server.env.source YAML parsing (884b418, Type from
environment properly (like Config), 2014-06-23).  So instead of
something like:

  GUNICORN_OPTS='--preload --log-syslog'

you should now be using:

  GUNICORN_OPTS='[--preload, --log-syslog]'
Joshua-Anderson pushed a commit to deis/controller-sdk-go that referenced this pull request Jun 16, 2016
After upgrading the private registry to 0.6.8, there were some
changes to the API that were missed. For example, the docker version
is now mandatory[1].

If you have docker v0.10.0 or higher, there is also a checksum computation
check done on each push, so I hardcoded the user-agent to v0.9.0. This is
a stopgap until

a) we update the API calls to v0.10.0
b) we replace this component with a docker-registry python package[2]

[1]: docker-archive/docker-registry@64f4198
[2]: docker-archive/docker-registry#297

fixes #779
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants