NationalCentreTruthReconciliation / Secure-Record-Transfer

A transfer portal incorporating CAAIS and BagIt Specifications
https://secure-record-transfer.readthedocs.io/en/latest/
4 stars 2 forks source link

Move containerfile to root #192

Closed yenaing-oo closed 2 months ago

yenaing-oo commented 2 months ago

Regarding https://github.com/NationalCentreTruthReconciliation/Secure-Record-Transfer/issues/190

yenaing-oo commented 2 months ago

The app ran fine in development since static assets were being served directly from their original location without being minified. In production, however, Django couldn't seem to location manage.py:

image

I looked through the container's files and discovered that the contents of ./bagitobjecttransfer were copied into /app rather than the directory iteself: image

I think the Docker's COPY instruction copies the contents of a directory instead of the directory. Here's a similar question on Stackoverflow, but for the ADD instruction.

I changed the part in Containerfile copying sources files to copy files and directory separately, and this seemed to fix issue of manage.py not being found.

The next issue I ran into is that Django keeps trying to serve static assets from app/static rather than app/bagitobjecttransfer/static. (I don't know how to recreate the error logs for this, I got another error instead when going back to this point).

I tried changing every possible setting in base.py to make it serve static files from app/bagitobjecttransfer/static, but nothing seemed to work. The only thing that does work is changing STATIC_ROOT to the app/static.

danloveg commented 2 months ago

Thanks for looking into this, I'll pull your branch and test on my end. I wasn't expecting that the static files would need to be served from elsewhere, so I'll take a look at that too and see if there's any issue using app/static/instead.

yenaing-oo commented 2 months ago

You're absolutely right that the static files need to be at /app/static, that was a good catch. I even built that behaviour into the prod compose file, I must have just forgotten that I had made that decision.

We only need that change in the production configuration, hence why I've asked you to move that change to the base settings file to docker_prod.py.

Ah I think I found the other culprit for this behaviour in ngix.conf. It looks like this is telling the Ngix web server to serve static assets from app/static, whereas the line you mentioned in compose.prod.yml is defining a shared volume between Django and Ngix.