0

I'm trying to install private python-based git repos from a requirements.txt into a docker container such that they are easily editable during development.

For example, I have a Django project which contains a Dockerfile that allows building that project inside of a docker container. (It might look something like this https://github.com/JoeJasinski/docker-django-demo/blob/master/Dockerfile).

Now, say that project has a requirements.txt file that pulls in code from a private repos as follows.

django=1.11.2
-e git+git@github.com:myorg/my-private-project.git#egg=my_private_project
-e git+ssh://git@git.example.com/second-private-project@mytag#egg=second_private_project
-e git+https://github.com/myorg/third-private-project#egg=third_private_project

Ideally, I'd make it so I can edit both my main project, and the dependent repos without having to re-build the docker container each time. The Dockerfile "ADD . dest/" command makes it possible for the main project to be edited in place, but I'm having difficulty finding a good solution for installing these private repositories.

Normally (outside of Docker), the pip -e flag makes repos editable in place, which is great since I can edit and commit to them like any other repo.

However, inside of Docker, the container doesn't have access to the ssh private key needed to download the private repos (and this is probably a good thing, so we don't build the key into the docker images).

One thought I had is to download the private repos outside of the container, prior to building. Then somehow those repos would be "ADD"ed to the Docker container at build time and then individually added to the PYTHONPATH (maybe during runtime?). However, I feel like I'm over-complicating the situation.

Any suggestions as to a good, simple (Pythonic) way to install private python-based git repositories into a container so that it's easy to develop on both the main project and dependent repositories?

Joe J
  • 9,985
  • 16
  • 68
  • 100
  • 1
    Have you looked at mounting the development files from your host into the container? – Matt Oct 07 '17 at 02:08
  • @matt, Thanks for your reply. Yes, I think mounting (ADDing) is a good option. The only issue is that the packages need to be pip installed inside of the container (which installs python deps from setup.py and adds the pacakge to the python path). And since the ADD usually happens after the container is built, I haven't found a good process to do that yet. – Joe J Oct 07 '17 at 16:58
  • I don't mean ADDing to the container build but mounting the local development files as a volume onto your container - https://stackoverflow.com/a/40921548/1318694 – Matt Oct 09 '17 at 01:01
  • If you are using a code repository that support access tokens (like github) and pip version > 10 you can write something similar to git+https://${ACCESS_TOKEN}:x-oauth-basic@github.com/yourgitrepo#egg=yourpackagename in your requirements file. After that you can just add your access token as a build-arg either from the command line or in your docker compose. – BjornArnelid Aug 31 '18 at 07:08

0 Answers0