Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PBL-32835 Upgrade to Django 1.9 and use django-pipline #279

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
55db94d
Upgrade to Django 1.9.1
Jan 28, 2016
009d320
Updated bootstrap/procfile/post_compile configuration
Jan 28, 2016
b1a0e8c
Renamed 'auth' app to 'site_auth' to fix app name conflict.
Jan 28, 2016
f24a2ef
Use 'celery worker -A cloudpebble' in Procfile
Jan 28, 2016
ee4480f
Fixied some errors and updated some requirements.
Jan 28, 2016
c38c98f
Added django-pipeline support
Feb 2, 2016
4613a5d
Added staticfiles to .gitignore
Feb 3, 2016
b9c6c8f
Merge branch 'master' into feature/django-1.9
Feb 4, 2016
3ac0aaf
Upgrade to Django 1.9.2 & migrate --fake-initial in post_compile
Feb 4, 2016
257f121
Update initial migration with latest changes
Feb 4, 2016
056afe4
Support CSS compression with sourcemaps
Feb 4, 2016
93dc170
Updated DEBUG=False logging to use console.
Feb 4, 2016
a85a7df
Neatened stuff.
Feb 4, 2016
9c02541
Use absolute BASE_DIR and STATIC_ROOT, and uglify-js
Feb 5, 2016
16574fd
Try replacing dj_static with whitenoise
Feb 5, 2016
1724057
Try enabling gzip compression
Feb 5, 2016
ed9bcfe
Set up S3 on first access instead of at module import time.
Feb 9, 2016
c304cf5
Corrected BucketHolder logic.
Feb 9, 2016
e22b6d4
Set BucketHolder self.configured *after* actually configuring
Mar 25, 2016
8fa0765
s3.py Formatting fixes
Mar 25, 2016
ece69cf
Removed staticfiles_storage toggle
Apr 7, 2016
8d43772
Fixed issues with django-pipeline speed in Development mode.
Apr 1, 2016
a15d5e9
Merge branch 'master' into feature/django-1.9
Apr 7, 2016
e7db207
Merge branch 'task/update-python' into feature/django-1.9
Apr 7, 2016
fb4b975
Bumped packages and updated project for compataility
Apr 15, 2016
3be02da
Finders/storages changes
Apr 19, 2016
db1d1c5
Merge branch 'task/update-python' into feature/django-1.9
Apr 28, 2016
09786f5
Merge branch 'task/update-python' into feature/django-1.9
May 3, 2016
1e33def
Merge branch 'feature/s3_bucketholder' into feature/django-1.9
May 10, 2016
6b05f12
Merge branch 'feature/travis' into feature/django-1.9
May 10, 2016
e9191cc
Removed duplicate requirement
May 10, 2016
978d66f
Merge branch 'feature/travis' into feature/django-1.9
May 11, 2016
d5185df
Merge branch 'feature/improved-logging' into feature/django-1.9
May 19, 2016
e93a4be
Merge branch 'master' into feature/django-1.9
Jun 10, 2016
2c06d97
Rebuilt initial migration
Jun 10, 2016
17810ba
Backported improvements from test-bench
Jun 10, 2016
2d6bc84
Merge branch 'master' into feature/django-1.9
Jul 6, 2016
d69ac58
Merge branch 'master' into feature/django-1.9
Aug 3, 2016
df1339e
Update migrations.
Aug 5, 2016
732e0ef
Merge branch 'master' into feature/django-1.9
Sep 7, 2016
b5371a7
Update initial migrations.
Sep 7, 2016
9630157
Merge with origin/master
Dec 16, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ src/
.env/
.idea/
bower_components
staticfiles
12 changes: 9 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM python:2.7.11
MAINTAINER Katharine Berry <[email protected]>

ENV NPM_CONFIG_LOGLEVEL=info NODE_VERSION=4.2.3 DJANGO_VERSION=1.6
ENV NPM_CONFIG_LOGLEVEL=info NODE_VERSION=4.2.3 DJANGO_VERSION=1.9.7

# Node stuff.

Expand Down Expand Up @@ -41,6 +41,11 @@ EXPOSE 8000
# CloudPebble stuff
RUN npm install -g bower && echo '{"allow_root": true}' > ~/.bowerrc

ADD package.json /tmp/package.json
RUN cd /tmp && npm install
RUN mkdir -p /opt/npm && cp -a /tmp/node_modules /opt/npm/
ENV NODE_MODULES_PATH /opt/npm/node_modules

# Grab the toolchain
RUN curl -o /tmp/arm-cs-tools.tar https://cloudpebble-vagrant.s3.amazonaws.com/arm-cs-tools-stripped.tar && \
tar -xf /tmp/arm-cs-tools.tar -C / && rm /tmp/arm-cs-tools.tar
Expand All @@ -55,8 +60,8 @@ RUN mkdir /sdk2 && \
curl -L "https://s3.amazonaws.com/assets.getpebble.com/sdk3/sdk-core/sdk-core-${SDK_TWO_VERSION}.tar.bz2" | \
tar --strip-components=1 -xj -C /sdk2

ENV SDK_THREE_CHANNEL=beta
ENV SDK_THREE_VERSION=4.0-beta16
ENV SDK_THREE_CHANNEL=release
ENV SDK_THREE_VERSION=4.0.1

# Install SDK 3
RUN mkdir /sdk3 && \
Expand All @@ -70,5 +75,6 @@ WORKDIR /code
RUN rm -rf bower_components && cd /tmp && python /code/manage.py bower install && mv bower_components /code/

RUN python manage.py compilemessages
RUN python manage.py collectstatic --noinput

CMD ["sh", "docker_start.sh"]
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
web: newrelic-admin run-program gunicorn -c gunicorn.py cloudpebble.wsgi
celery: newrelic-admin run-program python manage.py celeryd -E -l info
celery: newrelic-admin run-program celery worker -A cloudpebble -E -l info
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ appropriate values there. Setting environment variables also works.
Note that you won't be able to set up integration with certain Pebble systems (e.g. Pebble SSO). This shouldn't usually
matter; whenever these are used, an alternative route is provided and should be invoked in its absence.

In order to run locally with `DEBUG=False` set, add the setting `STATICFILES_STORAGE = 'pipeline.storage.PipelineStorage'`
to `cloudpebble/settings_local.py`.

Contributing
------------

Expand Down
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"required": true
},
"BROKER_POOL_LIMIT": "1",
"BUILDPACK_URL": "https://github.com/pebble/cloudpebble-buildpack",
"BUILDPACK_URL": "https://github.com/pebble/cloudpebble-buildpack.git#pipeline",
"COMPLETION_CERTS": "/app/completion-certs.crt",
"ENABLE_KEEN": "yes",
"FROM_EMAIL": "[email protected]",
Expand Down
3 changes: 1 addition & 2 deletions bin/post_compile
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ rm /tmp/*.tar.*

# Make sure the database is up to date.
echo "Performing database migration."
python manage.py syncdb --noinput
python manage.py migrate
python manage.py migrate --fake-initial

echo "Compiling gettext files"
python manage.py compilemessages
Expand Down
4 changes: 2 additions & 2 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ easy_install requests==2.7.0

# Make sure we have a useful database and our JS dependencies.
pushd /vagrant
sudo -u vagrant python manage.py syncdb --noinput
sudo -u vagrant python manage.py migrate
sudo -u vagrant python manage.py bower install
popd
Expand Down Expand Up @@ -169,7 +168,8 @@ console log
script
export PATH="$PATH:/home/vagrant/arm-cs-tools/bin:/home/vagrant/sdk2/bin"
export DEBUG=yes
exec /usr/bin/python manage.py celery worker --autoreload --loglevel=info --no-color
# The following line is untested after move to Django 1.9
exec celery worker --autoreload --loglevel=info --no-color
end script

EOF
Expand Down
5 changes: 5 additions & 0 deletions cloudpebble/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from __future__ import absolute_import

# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app
22 changes: 22 additions & 0 deletions cloudpebble/celery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from __future__ import absolute_import

import os

from celery import Celery

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'cloudpebble.settings')

from django.conf import settings # noqa

app = Celery('cloudpebble')

# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)


@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
53 changes: 53 additions & 0 deletions cloudpebble/compressors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from __future__ import unicode_literals

import codecs
import tempfile

from django.contrib.staticfiles.storage import staticfiles_storage

from pipeline.conf import settings
from pipeline.compressors import SubProcessCompressor
from pipeline.utils import source_map_re, path_depth


class ConcatenatingUglifyJSCompressor(SubProcessCompressor):
def compress_js(self, js):
command = [settings.UGLIFYJS_BINARY, settings.UGLIFYJS_ARGUMENTS]
if self.verbose:
command.append(' --verbose')
return self.execute_command(command, js)

def concatenate_files(self, paths, out_path):
args = [settings.CONCATENATOR_BINARY]
args += [staticfiles_storage.path(p) for p in paths]
args += ['-o', out_path]
args += ['-d', staticfiles_storage.base_location]
self.execute_command(args)

def compress_js_with_source_map(self, paths):
concatenated_js_file = tempfile.NamedTemporaryFile()
source_map_file = tempfile.NamedTemporaryFile()
try:
self.concatenate_files(paths, concatenated_js_file.name)
args = [settings.UGLIFYJS_BINARY]
args += [concatenated_js_file.name]
args += ["--in-source-map", concatenated_js_file.name + ".map"]
args += ["--source-map", source_map_file.name]
args += ["--source-map-root", staticfiles_storage.base_url]
args += ["--prefix", "%s" % path_depth(staticfiles_storage.base_location)]
args += settings.UGLIFYJS_ARGUMENTS
if self.verbose:
args.append('--verbose')

js = self.execute_command(args)

with codecs.open(source_map_file.name, encoding='utf-8') as f:
source_map = f.read()

# Strip out existing source map comment (it will be re-added with packaging)
js = source_map_re.sub('', js)

return js, source_map
finally:
concatenated_js_file.close()
source_map_file.close()
Loading