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?
This commit is contained in:
James Polley 2018-06-06 12:11:51 +10:00
parent 3d9c8b3032
commit ddae8d91f6
4 changed files with 15 additions and 2 deletions

View file

@ -1,3 +1,8 @@
.git .git
symposion-tools symposion-tools
docker
static/build
*.sh
TODO
dev-env.sh
.gitlab-ci.yml

View file

@ -33,6 +33,9 @@ COPY . /app/symposion_app
WORKDIR /app/symposion_app WORKDIR /app/symposion_app
RUN set -x \ RUN set -x \
&& pip install -r vendored_requirements.txt -c /reqs/constraints.txt && 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 \ RUN set -x \
&& DJANGO_SECRET_KEY=1234 STRIPE_PUBLIC_KEY=1234 STRIPE_SECRET_KEY=1234 \ && DJANGO_SECRET_KEY=1234 STRIPE_PUBLIC_KEY=1234 STRIPE_SECRET_KEY=1234 \
DATABASE_URL="sqlite:////dev/null" \ DATABASE_URL="sqlite:////dev/null" \

View file

@ -13,6 +13,10 @@ docker container stop symposion
docker container rm 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 create --env-file docker/laptop-mode-env -p 28000:8000 -v $(pwd):/app/symposion_app --name symposion ${CONTAINER_NAME}
docker container start symposion 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 migrate
docker exec symposion ./manage.py loaddata ./fixtures/{conference,sites,sitetree,proposal_base,flatpages}.json docker exec symposion ./manage.py loaddata ./fixtures/{conference,sites,sitetree,proposal_base,flatpages}.json
docker exec symposion ./manage.py create_review_permissions docker exec symposion ./manage.py create_review_permissions

View file

@ -1,5 +1,5 @@
Django>=1.11 Django>=1.11
pinax-theme-bootstrap==7.3.0 pinax-theme-bootstrap~=7.10.0
pinax-eventlog==1.1.1 pinax-eventlog==1.1.1
django-formset-js==0.5.0 django-formset-js==0.5.0
dj-static==0.0.6 dj-static==0.0.6
@ -48,3 +48,4 @@ django-waffle>=0.12.0
# SASS Compiler and template tags # SASS Compiler and template tags
libsass==0.14.5 libsass==0.14.5
django-sass-processor==0.7 django-sass-processor==0.7
django-compressor==2.2