Skip to content

Commit 9f27fd1

Browse files
author
Dennis Schwartz
authored
[F] New paginated components route (#48)
* Added Docker setup for local development. * Re-add port to localhost CORS settings * Update settings and docker-compose command. * Clean up updatecomponents.py * Re-wrote update_visualizations function. * Mark components that don't need browserify * Update deps for security vulnerabilities and remove Django warning. * Prevent duplicate Snippets. * Update visualizations template to work for built components * Provide all components with pagination. * Fix requirements that breaks builds. * Add pagination. * Remove offending package. * Store docker settings outside of git. * Turn debug off. * Remove unused logger * Update readme with updatecomponents command. * Add dev.biojs.net to CORS whitelist. * Add docs for github credentials. * Add debug docs. * Setup automated deployments. * Use newly encrypted env vars. * limit deployments to relevant branches * Add GITHUB creds to deployment. * Import github creds from ansible config * Log GH ID when it fails. * One more try with settings.
1 parent 1dbab59 commit 9f27fd1

File tree

11 files changed

+110
-20
lines changed

11 files changed

+110
-20
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*.pyc
22
*.sqlite3
33
media/
4-
config.py
4+
config.py
5+
creds.txt

.travis.yml

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,51 @@
11
language: python
2-
32
python:
4-
- 2.7
5-
6-
install:
7-
- pip install -r requirements.txt
8-
9-
script:
10-
- python manage.py makemigrations
11-
- python manage.py migrate
3+
- 2.7
4+
services:
5+
- docker
6+
jobs:
7+
include:
8+
- stage: test
9+
install:
10+
- pip install -r requirements.txt
11+
script:
12+
- python manage.py makemigrations
13+
- python manage.py migrate
14+
- stage: deploy-dev
15+
if: branch = master
16+
before_script:
17+
- docker pull philm/ansible_playbook
18+
- git clone https://github.com/biojs/biojs-backend-ansible.git
19+
- openssl aes-256-cbc -K $encrypted_cf08b333dbdc_key -iv $encrypted_cf08b333dbdc_iv
20+
-in deployment-key.enc -out ~/.ssh/id_rsa -d
21+
script:
22+
- docker run -it -v ~/.ssh/id_rsa:/root/.ssh/id_rsa -v "$(pwd)/biojs-backend-ansible":/ansible/playbooks
23+
-e DB_USER=$DB_USER
24+
-e DB_PASSWORD=$DB_PASSWORD
25+
-e GITHUB_CLIENT_SECRET=$GITHUB_CLIENT_SECRET
26+
-e GITHUB_CLIENT_ID=$GITHUB_CLIENT_ID
27+
philm/ansible_playbook dev-deploy.yml
28+
--private-key=~/.ssh/id_rsa -u ubuntu -i dev_hosts
29+
- stage: deploy-production
30+
if: branch = production
31+
before_script:
32+
- docker pull philm/ansible_playbook
33+
- git clone https://github.com/biojs/biojs-backend-ansible.git
34+
- openssl aes-256-cbc -K $encrypted_cf08b333dbdc_key -iv $encrypted_cf08b333dbdc_iv
35+
-in deployment-key.enc -out ~/.ssh/id_rsa -d
36+
script:
37+
- docker run -it -v ~/.ssh/id_rsa:/root/.ssh/id_rsa -v "$(pwd)/biojs-backend-ansible":/ansible/playbooks
38+
-e DB_USER=$DB_USER
39+
-e DB_PASSWORD=$DB_PASSWORD
40+
-e GITHUB_CLIENT_SECRET=$GITHUB_CLIENT_SECRET
41+
-e GITHUB_CLIENT_ID=$GITHUB_CLIENT_ID
42+
philm/ansible_playbook dev-production.yml
43+
--private-key=~/.ssh/id_rsa -u ubuntu -i production_hosts
44+
notifications:
45+
email: true
46+
env:
47+
global:
48+
- secure: FipxVvaQcL1ZG5eT7AgLil7ofDw7M1q6rxbwha6qO3hx1LiySZuaGK7fJW0iz9aPcF+SjtNCtE2o5zxANXgTAncSrqI/yTYhoPTW6WHfb/m/vustkkoGjtOMZDNRL+UJ2eYB3kKIXFdXnVkWKi8RuKjS38yioLxJs2aJdH/49yuMeY/+wIqGiVBYqG8b5VGl56gcbw9BgntTg9+OVDdz1Yflm8CdLtu2aqS7MIU66OU4H5GNgks+XuBGNfRiPAeyxR/jLkpQXWE0q67n3SKXQEzJEJlYuJNmRl14tcD3wigrm5BLpQwBVuKfS+XYTGYvb4FDh/oyTydGOvm/wFLN439en89YFtpHYVJZnon1G6BMNHbW07X8gnRLHw8jhosEwDHRDYyfCHaxvAz9v4tS00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ea3oY1rLZjNAwWO3Lx6uJYh6VZYYIJ5ggeR3Is+EqoH2cM/GqzY78Z263Qp+epDpOrXWbRftQoJZSi2Twn5ge+XC04BBXEYr3EbO8ePCBrRnS0dmhCRaEZ35kQ5STAqDZfKJjeRYMmuWy1cWPhuDSEG5qaMTCWDpm/hhkPaaT81Cegnf/ditrLyJ5A=

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,21 @@ $ pip install -r requirements.txt
2929
# migrate the database
3030
$ python manage.py migrate
3131

32+
# Create a personal Github access token in settings and use github username for CLIENT_ID
33+
# export Github credentials to bypass rate limit
34+
$ export GITHUB_CLIENT_ID=<username> && export GITHUB_CLIENT_SECRET=<token>
35+
3236
# start the server
3337
$ python manage.py runserver
38+
39+
# Collect components
40+
$ python manage.py updatecomponents
3441
```
3542

3643
Navigate to [127.0.0.1:8000](http://127.0.0.1:8000/).
44+
45+
## Settings
46+
47+
### Debugging
48+
49+
Enable debug logs by editing the DEBUG=False setting in `biojs/settings.py`

biojs/settings.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,19 @@
2222
# SECURITY WARNING: keep the secret key used in production secret!
2323
SECRET_KEY = '$&&+$xz)50khd6q+aq&95r1$2urmmdv37=-*lu3v-wwh46829t'
2424

25-
GITHUB_CLIENT_ID = os.environ.get('GITHUB_CLIENT_ID') or ''
26-
GITHUB_CLIENT_SECRET = os.environ.get('GITHUB_CLIENT_SECRET') or ''
25+
try:
26+
from config import *
27+
GITHUB_CLIENT_ID = GITHUB_CLIENT_ID
28+
GITHUB_CLIENT_SECRET = GITHUB_CLIENT_SECRET
29+
except:
30+
GITHUB_CLIENT_ID = ''
31+
GITHUB_CLIENT_SECRET = ''
2732

2833
# SECURITY WARNING: don't run with debug turned on in production!
2934
try:
30-
from config import *
31-
DEBUG = DEBUG
35+
from config import DEBUG
3236
except:
33-
DEGUB = True
37+
DEBUG = False
3438

3539
ALLOWED_HOSTS = ['*']
3640

@@ -161,8 +165,25 @@
161165
# CORS settings
162166

163167
CORS_ORIGIN_WHITELIST = (
168+
'dev.biojs.net',
164169
'biojs.net',
165170
'biojs.io',
166171
'localhost:8080',
167172
'127.0.0.1:9000'
168173
)
174+
175+
LOGGING = {
176+
'version': 1,
177+
'disable_existing_loggers': False,
178+
'handlers': {
179+
'console': {
180+
'class': 'logging.StreamHandler',
181+
},
182+
},
183+
'loggers': {
184+
'django': {
185+
'handlers': ['console'],
186+
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
187+
},
188+
},
189+
}

biojs/urls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
urlpatterns += staticfiles_urlpatterns()
1414

1515
if settings.DEBUG:
16-
urlpatterns += static(settings.STATIC_URL, serve, document_root=settings.STATIC_ROOT)
17-
urlpatterns += static(settings.MEDIA_URL, serve, document_root=settings.MEDIA_ROOT)
16+
urlpatterns += static(settings.STATIC_URL, serve, document_root=settings.STATIC_ROOT)
17+
urlpatterns += static(settings.MEDIA_URL, serve, document_root=settings.MEDIA_ROOT)

deployment-key.enc

1.81 KB
Binary file not shown.

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ services:
55
image: biojs-backend-base
66
working_dir: /opt
77
environment:
8-
GITHUB_CLIENT_SECRET: 289807644cc6b4afe50b4bb2c5afcd7056047de0
9-
GITHUB_CLIENT_ID: DennisSchwartz
8+
GITHUB_CLIENT_SECRET: <token>
9+
GITHUB_CLIENT_ID: <user>
1010
volumes:
1111
- .:/opt
1212
ports:

main/management/commands/updatecomponents.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ def handle(self, *args, **options):
176176
except urllib2.HTTPError as e:
177177
print('Error getting github data!')
178178
print(e)
179+
print GITHUB_CLIENT_ID
179180
continue
180181
except Exception as e:
181182
print('Unexpected error accessing Github!')

main/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
urlpatterns = [
77
url(r'^$', views.index, name="index"),
8+
url(r'^components/?$', views.components, name="components"),
89
url(r'^updatedata/$', views.update_data, name="update_data"),
910
url(r'^all/$', views.all_components, name="all_components"),
1011
url(r'^top/$', views.top_components, name="top_components"),

main/views.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from django.core.management import call_command
1010
from django.core.serializers import serialize
1111
from django.views.decorators.clickjacking import xframe_options_exempt
12+
from django.core.paginator import Paginator, EmptyPage
1213
import numpy as np
1314

1415
def index(request):
@@ -37,6 +38,19 @@ def top_components(request):
3738
'top_components':top_components.data,
3839
})
3940

41+
def components(request):
42+
size = request.GET.get('size', 20)
43+
page = request.GET.get('page', 1)
44+
components_list = Component.objects.all().order_by('-modified_time')
45+
paginator = Paginator(components_list, size)
46+
try:
47+
currentPage = paginator.page(page)
48+
serialised = TopComponentSerializer(currentPage, many=True)
49+
components = serialised.data
50+
except EmptyPage:
51+
components = []
52+
return JsonResponse({ 'components': components })
53+
4054
def component_details(request, url_name):
4155
component = Component.objects.get(url_name=url_name)
4256
details = DetailComponentSerializer(component, context={'request':request})

0 commit comments

Comments
 (0)