From ddae8d91f6824ee60bd8764f9d9aca0311b0b017 2018-06-06 02:20:06 From: James Polley Date: 2018-06-06 02:20:06 Subject: [PATCH] Improved handling of static/build and css generation When the container is mounted, the local contents of . obscure /app/symposion_app in the image. Generally speaking, this is handy for development, as it means that local changes are detected and used immediately without needing to restart the container. However, it breaks in the specific case of the sass->css generation. Prior to this change, the css is generated only after the first time a page is hit. The generated file is placed in static/build; however, due to the obscuration, this generated file isn't visible to the running process. The next time the container is built, the pre-existing static/build directory is copied into the container as it's being built; then, later, that version is what gets served. This change adds the needed libraries to pre-generate the css as part of the image build, and runs compilescss to do this, prior to the collectstatic step. It also adds a second collectstatic into the make_dev_container script, so that the visible static/build directory should ahve the same contents as the obscured static/build directory. It also expands the .dockerignore file to make sure these files aren't copied into the image in future. I'm not sure if this is the right thing to do, as changes to this directory will be ignored, which could be confusing. Perhaps never being able to see these generated files is better? --- diff --git a/.dockerignore b/.dockerignore index abe0c15368c79f306fc7e06c920299c49fb2e09e..3c3152a5ae7877e6ada955a6cf9e94e91bc90a45 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,8 @@ .git symposion-tools - +docker +static/build +*.sh +TODO +dev-env.sh +.gitlab-ci.yml diff --git a/docker/Dockerfile b/docker/Dockerfile index efb4df2061e2a911867f99885e6670658efa8d0f..09e816d719f5f110e55da6af9402771ec830a975 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -33,6 +33,9 @@ COPY . /app/symposion_app WORKDIR /app/symposion_app RUN set -x \ && pip install -r vendored_requirements.txt -c /reqs/constraints.txt +RUN set -x \ + && DJANGO_SECRET_KEY=1234 STRIPE_PUBLIC_KEY=1234 STRIPE_SECRET_KEY=1234 \ + DATABASE_URL="sqlite:////dev/null" python manage.py compilescss RUN set -x \ && DJANGO_SECRET_KEY=1234 STRIPE_PUBLIC_KEY=1234 STRIPE_SECRET_KEY=1234 \ DATABASE_URL="sqlite:////dev/null" \ diff --git a/make_dev_container.sh b/make_dev_container.sh index 8d51ddba4bab6d4c4e6baef4231ef64d244a6379..3410c24bdb974d7e0c336c4ee3f387d6d8bdb18a 100755 --- a/make_dev_container.sh +++ b/make_dev_container.sh @@ -13,6 +13,10 @@ docker container stop symposion docker container rm symposion docker container create --env-file docker/laptop-mode-env -p 28000:8000 -v $(pwd):/app/symposion_app --name symposion ${CONTAINER_NAME} docker container start symposion +## When we started the container and mounted . into /app/symposion_app, it hides the static/build directory +## As a kludge, re-run collectstatic to recreate it +## Possible alternative here: don't mount all of ., just mount the bits that we'd live to have update live +docker exec symposion ./manage.py collectstatic --noinput -v 0 docker exec symposion ./manage.py migrate docker exec symposion ./manage.py loaddata ./fixtures/{conference,sites,sitetree,proposal_base,flatpages}.json docker exec symposion ./manage.py create_review_permissions diff --git a/requirements.txt b/requirements.txt index 03b27009c1005720ffac61bffff71d540aa58c81..8c26eee4f2bc1a296c67af806c592d45720cd735 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ Django>=1.11 -pinax-theme-bootstrap==7.3.0 +pinax-theme-bootstrap~=7.10.0 pinax-eventlog==1.1.1 django-formset-js==0.5.0 dj-static==0.0.6 @@ -48,3 +48,4 @@ django-waffle>=0.12.0 # SASS Compiler and template tags libsass==0.14.5 django-sass-processor==0.7 +django-compressor==2.2