GrahamDumpleton / mod_wsgi-docker

Docker images for Apache/mod_wsgi.
Apache License 2.0
72 stars 36 forks source link

Improve Docker Build Time #7

Closed collinjackson93 closed 8 years ago

collinjackson93 commented 8 years ago

I know this image isn't exactly designed for development, but I find it a little cumbersome that the build process installs pip, wheel, mod_wsgi-express, and project dependencies every time there is a code change. Would it be possible to change the COPY . /app line to COPY ./requirements.txt ./app and then run COPY . /app after running mod_wsgi-docker-build? This would only invalidate the cache if the requirements list has changed. (See Dockerfile best practices here for an example)

GrahamDumpleton commented 8 years ago

Your suggestion unfortunately will not work in general case as the requirements.txt file may need to reference a local package that was copied in as part of your source code. So it gets complicated.

That mod_wsgi gets reinstalled is an issue I know of. It is actually installed as part of system wide Python as well and virtual environment chains off that and it is found, but when run out of system Python mod_wsgi wasn't picking up virtual environment correctly. I need to revisit it to work out how to fix that and then I can drop second installation of mod_wsgi. It only came up that that broke things in last week and I had to revert to doing the second installation.

Anyway, I haven't got a lot of time to explain in detail right now, or check my recipe works, as at training day, but presuming running Docker locally and how your Docker system is setup allows local file system mounting, the images are specifically set up to allow you to do.

docker build myapp .
docker run -v `pwd`:/app -p 8000:80 myapp --reload-on-changes

So you build it once to get an image with required dependencies, but then you actually mount the current directory into the container, overlaying and hiding what was copied in. You then ensure that --reload-on-changes option is also supplied to mod_wsgi-express and you can then make changes to the local file system to code files and your application will auto reload changes. This will allow you to do development.

See if you can get that going and if not tell me what OS you are using and how Docker was installed.

collinjackson93 commented 8 years ago

I kind of figured it wouldn't be that simple, but I figured I would suggest it on the off chance that it would work.

Thanks for the work around; I'll give it a shot.

GrahamDumpleton commented 8 years ago

The additional reinstall of pip and mod_wsgi shouldn't occur now. This is because the Python virtual environment has been done away with as it causes various problems. If you have stuff in 'requirements.txt', they will still be installed though.

The changes made are quite significant, but everything should still run okay. If you see any problems, especially with access permissions at run time, let me know ASAP.