Skip to content

Commit

Permalink
Enable usage of S3 as a target for media upload & serving
Browse files Browse the repository at this point in the history
* Add django-storages and settings to use S3 for media

* Split up docker-compose so local customizations are easier
  • Loading branch information
lmorchard committed Oct 8, 2015
1 parent 02ceae7 commit 942330b
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ venv/
idea_town/frontend/static/
idea_town/frontend/static-src/vendor/
idea_town/frontend/static-src/styles/vendor/
docker-compose-s3.yml
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,20 @@ Idea Town is not intended to replace trains for most features, nor is it a test
`docker exec -t -i ideatown_client_build_1 touch gulpfile.js`

* Want to run Python linting and Django tests on file changes? Try this:
```
```bash
sudo gem install kicker
kicker -c -e'docker exec -t -i ideatown_server_1 flake8 ./idea_town && \
docker exec -t -i ideatown_server_1 ./manage.py test -v2' ./idea_town`
kicker -c -e'docker exec -t -i ideatown_server_1 flake8 ./idea_town && docker exec -t -i ideatown_server_1 ./manage.py test -v2' ./idea_town`
```

* You can customize settings for special development cases. For example, to
switch to using S3 for media uploads:
```bash
cp docker-compose-s3.yml-dist docker-compose-s3.yml
# Edit docker-compose-s3.yml to include your AWS credentials
docker-compose -f docker-compose-s3.yml build
docker-compose -f docker-compose-s3.yml up
```


Testing
-------------
Expand Down
30 changes: 30 additions & 0 deletions docker-compose-base.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
client_build:
build: .
dockerfile: Dockerfile-client_build
ports:
- "9988:9988"
volumes:
- .:/app
environment:
- NODE_ENV=development
command:
./bin/run-client-build.sh
server:
build: .
dockerfile: Dockerfile-server
ports:
- "8000:8000"
volumes:
- .:/app
command:
./bin/run-dev.sh
environment:
- PYTHONUNBUFFERED=1
- PYTHONDONTWRITEBYTECODE=1
- DATABASE_URL=postgres://postgres@db/postgres
- DEBUG=True
- ALLOWED_HOSTS=localhost,127.0.0.1,
- SECRET_KEY=59114b6a-2858-4caf-8878-482a24ee9542
- FXA_ACCESS_TOKEN_URL=https://oauth-stable.dev.lcip.org/v1/token
- FXA_AUTHORIZE_URL=https://oauth-stable.dev.lcip.org/v1/authorization
- FXA_PROFILE_URL=https://stable.dev.lcip.org/profile/v1/profile
18 changes: 18 additions & 0 deletions docker-compose-s3.yml-dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
db:
image: postgres:9.3
client_build:
extends:
file: docker-compose-base.yml
service: client_build
server:
extends:
file: docker-compose-base.yml
service: server
links:
- db
environment:
- DEFAULT_FILE_STORAGE=storages.backends.s3boto.S3BotoStorage
- AWS_ACCESS_KEY_ID={your access key id goes here}
- AWS_SECRET_ACCESS_KEY={your secret access key goes here}
- AWS_STORAGE_BUCKET_NAME={your bucket name here}
- MEDIA_URL=http://{your bucket name here}.s3.amazonaws.com/
35 changes: 6 additions & 29 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,13 @@
db:
image: postgres:9.3
client_build:
build: .
dockerfile: Dockerfile-client_build
ports:
- "9988:9988"
volumes:
- .:/app
environment:
- NODE_ENV=development
command:
./bin/run-client-build.sh
extends:
file: docker-compose-base.yml
service: client_build
server:
build: .
dockerfile: Dockerfile-server
ports:
- "8000:8000"
volumes:
- .:/app
extends:
file: docker-compose-base.yml
service: server
links:
- db
- client_build
environment:
- PYTHONUNBUFFERED=1
- PYTHONDONTWRITEBYTECODE=1
- DATABASE_URL=postgres://postgres@db/postgres
- DEBUG=True
- ALLOWED_HOSTS=localhost,127.0.0.1,
- SECRET_KEY=59114b6a-2858-4caf-8878-482a24ee9542
- ADDON_URL=https://github.com/mozilla/idea-town-addon/blob/master/dist/idea-town-addon-0.0.1.xpi?raw=true
- FXA_ACCESS_TOKEN_URL=https://oauth-stable.dev.lcip.org/v1/token
- FXA_AUTHORIZE_URL=https://oauth-stable.dev.lcip.org/v1/authorization
- FXA_PROFILE_URL=https://stable.dev.lcip.org/profile/v1/profile
command:
./bin/run-dev.sh
9 changes: 9 additions & 0 deletions idea_town/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
'django_cleanup',

'rest_framework',
'storages',

# FxA auth handling
'allauth',
Expand Down Expand Up @@ -159,6 +160,14 @@
MEDIA_ROOT = config('MEDIA_ROOT', default=os.path.join(BASE_DIR, 'media'))
MEDIA_URL = config('MEDIA_URL', '/media/')

DEFAULT_FILE_STORAGE = config(
'DEFAULT_FILE_STORAGE',
default='django.core.files.storage.FileSystemStorage')

AWS_ACCESS_KEY_ID = config('AWS_ACCESS_KEY_ID', default=None)
AWS_SECRET_ACCESS_KEY = config('AWS_SECRET_ACCESS_KEY', default=None)
AWS_STORAGE_BUCKET_NAME = config('AWS_STORAGE_BUCKET_NAME', default=None)

SESSION_COOKIE_SECURE = config('SESSION_COOKIE_SECURE', default=not DEBUG, cast=bool)

FIVE_YEARS_IN_SECONDS = 60 * 60 * 24 * 365 * 5
Expand Down
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,9 @@ datadog==0.9.0

# sha256: IX5Hl9o6mkqfvmci4NuYBwuEQ6iCEtes29JBp2aBQdk
simplejson==3.8.0

# sha256: dYSYx38W4muLYa8m-NDbsRm3E_LY0WZoHsiSMR81IMQ
boto==2.38.0

# sha256: 3gT6WE26Z7tSel6olB0v9HEoXLD5d8hjRP8oJ8OZgeI
django-storages-redux==1.3

0 comments on commit 942330b

Please sign in to comment.