Skip to content

Commit

Permalink
Merge pull request #247 from domino14/staging
Browse files Browse the repository at this point in the history
Staging - Multiplayer
  • Loading branch information
domino14 authored Aug 30, 2017
2 parents fb20dca + 6cdea98 commit 5615ff9
Show file tree
Hide file tree
Showing 93 changed files with 4,569 additions and 1,436 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ kubernetes/*.crt
kubernetes/deploy-configs/dev-*.yaml
kubernetes/deploy-configs/prod-*.yaml
.coverage
djAerolith/htmlcov
djAerolith/htmlcov
vars.sh
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ WORKDIR /opt/webolith/djAerolith

EXPOSE 8000
# Run command in exec form because /bin/sh does not pass signals to its children.
CMD ["gunicorn", "wsgi:application", "--config", "gunicorn.py"]
CMD ["daphne", "-b", "0.0.0.0", "asgi:channel_layer"]
2 changes: 1 addition & 1 deletion base_pkg.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ MAINTAINER Cesar Del Solar <delsolar@gmail.com>

ENV PYTHONUNBUFFERED 1

RUN apk add --update gettext postgresql-dev postgresql gcc musl-dev libffi-dev
RUN apk add --update gettext postgresql-dev postgresql gcc musl-dev libffi-dev make

COPY djAerolith/prod_requirements.txt /opt/prod_requirements.txt
RUN pip install --upgrade pip
Expand Down
8 changes: 8 additions & 0 deletions build-dockers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
docker build -t domino14/webolith:$CIRCLE_BUILD_NUM -t domino14/webolith:latest .
cd $REPO/kubernetes && docker build -t domino14/webolith-nginx:$CIRCLE_BUILD_NUM -f nginx-Dockerfile --build-arg static_root=./webolith_static/ .
docker login --email $DOCKER_EMAIL --password $DOCKER_PASSWORD --username domino14
docker push domino14/webolith-nginx:$CIRCLE_BUILD_NUM
# Delete the static files.
rm -rf $STATIC_ROOT
docker push domino14/webolith:$CIRCLE_BUILD_NUM
docker push domino14/webolith:latest
32 changes: 14 additions & 18 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ machine:
version: stable
services:
- docker
- redis
python:
version: 2.7.12
environment:
REPO: /home/ubuntu/$CIRCLE_PROJECT_REPONAME
PGSQL_DB_NAME: circle_test
PGSQL_USER: ubuntu
REDIS_HOST: localhost
PGSQL_HOST: 127.0.0.1
PGSQL_PASSWORD:
# Debug for tests is False even if I set this to True.
Expand All @@ -32,17 +34,16 @@ dependencies:
- ~/.yarn-cache
override:
- yarn install
test:
pre:
# XXX: We should build the image first and test it.
- pip install -r djAerolith/test_requirements.txt
- pip install -r djAerolith/prod_requirements.txt
- git clone git@bitbucket.org:cesar_del_solar/webolith-private.git /home/ubuntu/webolith-private
- cp /home/ubuntu/webolith-private/admin.conf /home/ubuntu/admin.conf
- mkdir $WORD_DB_LOCATION
- mv /home/ubuntu/webolith-private/*.db $WORD_DB_LOCATION
- curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
- chmod +x ./kubectl
- sudo mv ./kubectl /usr/local/bin/kubectl
test:
override:
# Build the js bundles.
- yarn full-prod-build
Expand All @@ -51,26 +52,21 @@ test:
# Gather all JS files and compile messages for building into image.
- cd djAerolith && ./manage.py collectstatic --noinput
- cd djAerolith && ./manage.py compilemessages
post:
- docker build -t domino14/webolith:$CIRCLE_BUILD_NUM -t domino14/webolith:latest .
# Should make sure base docker container is always up to date.

deployment:
production:
branch: master
commands:
- >
cd $REPO/kubernetes &&
docker build -t domino14/webolith-nginx:$CIRCLE_BUILD_NUM
-f nginx-Dockerfile --build-arg static_root=./webolith_static/ .
- docker login --email $DOCKER_EMAIL --password $DOCKER_PASSWORD --username domino14
- docker push domino14/webolith-nginx:$CIRCLE_BUILD_NUM
# Delete the static files.
- rm -rf $STATIC_ROOT
- docker push domino14/webolith:$CIRCLE_BUILD_NUM
- docker push domino14/webolith:latest
# We need to create the kubernetes service yaml files, and apply new
# ones from config vars.
- ./build-dockers.sh
- cp /home/ubuntu/webolith-private/admin.conf /home/ubuntu/admin.conf
- fab create_k8s_configs:prod
- fab deploy:prod
# Don't deploy other branches.

staging:
branch: staging
commands:
- ./build-dockers.sh
- cp /home/ubuntu/webolith-private/dev-admin.conf /home/ubuntu/admin.conf
- fab create_k8s_configs:dev
- fab deploy:dev
1 change: 0 additions & 1 deletion config/local_config_skeleton.env
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ USE_GA=off
USE_FB=off

RECAPTCHA_PRIVATE_KEY=abcdef
REDIS_HOST=localhost
SOCKJS_SERVER=http://127.0.0.1:9999/socket

MACONDO_ADDRESS=http://localhost:8088
Expand Down
6 changes: 6 additions & 0 deletions djAerolith/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import os
from channels.asgi import get_channel_layer

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")

channel_layer = get_channel_layer()
26 changes: 26 additions & 0 deletions djAerolith/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,32 @@ def initialize_list(self, questions, lexicon, user, shuffle=False,
self.user = user
self.save()

def make_temporary_copy(self):
"""
Make a temporary copy of this word list. This is useful for
multiplayer mode.
"""
wl = WordList(
lexicon=self.lexicon,
name=uuid.uuid4().hex,
user=self.user,
is_temporary=True,
numAlphagrams=self.numAlphagrams,
numCurAlphagrams=self.numCurAlphagrams,
numFirstMissed=self.numFirstMissed,
numMissed=self.numMissed,
goneThruOnce=self.goneThruOnce,
questionIndex=self.questionIndex,
origQuestions=self.origQuestions,
curQuestions=self.curQuestions,
missed=self.missed,
firstMissed=self.firstMissed,
version=self.version,
category=self.category)
wl.save()
return wl

def restart_list(self, shuffle=False):
""" Restart this list; save it back to the database. """
self.initialize_list(json.loads(self.origQuestions),
Expand Down
2 changes: 1 addition & 1 deletion djAerolith/current_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CURRENT_VERSION = '0.11.4.1'
CURRENT_VERSION = '1.0.0.0-rc5'
7 changes: 0 additions & 7 deletions djAerolith/gunicorn.py

This file was deleted.

18 changes: 0 additions & 18 deletions djAerolith/lib/socket_helper.py

This file was deleted.

8 changes: 5 additions & 3 deletions djAerolith/prod_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# These are the requirements for the prod Docker file.

django>=1.11
django>=1.11,<2.0
six >= 1.7
Markdown
django-registration-redux
gargoyle-yplan
gunicorn
requests
recaptcha-client
wsgiref
Expand All @@ -17,7 +16,10 @@ python-openid
psycopg2
Fabric
PyYAML

channels
asgi_redis
django-channels-presence
gunicorn
# Not strictly a prod requirement. However, the main issue here
# is that we can't run tests in the docker container otherwise.
mock
6 changes: 6 additions & 0 deletions djAerolith/routing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from channels.routing import include
from wordwalls.routing import socket_routing

routing = [
include(socket_routing, path=r'^/wordwalls-socket'),
]
31 changes: 19 additions & 12 deletions djAerolith/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,15 @@ def tobool(val):
'base',
'flashcards',
'tablegame',
'wordwalls',
'wordwalls.apps.WordwallsAppConfig',
'accounts',
'django.contrib.staticfiles',
'gunicorn',
'whitleyCards',
'gargoyle',
'registration',
'social_django',
'channels',
'channels_presence',
#'debug_toolbar',
#'locking'
# Uncomment the next line to enable admin documentation:
Expand Down Expand Up @@ -242,8 +243,18 @@ def tobool(val):
LOGIN_URL = "/accounts/login"

IGNORABLE_404_ENDS = ('.php', '.cgi')
IGNORABLE_404_STARTS = ('/phpmyadmin/', '/forum/', '/favicon.ico', '/robots.txt')
IGNORABLE_404_STARTS = ('/phpmyadmin/', '/forum/', '/favicon.ico',
'/robots.txt')

CHANNEL_LAYERS = {
'default': {
'BACKEND': 'asgi_redis.RedisChannelLayer',
'CONFIG': {
'hosts': [(os.environ.get('REDIS_HOST', 'redis'), 6379)],
},
'ROUTING': 'routing.routing',
}
}
SEND_BROKEN_LINK_EMAILS = False

INTERNAL_IPS = ('127.0.0.1',)
Expand All @@ -258,7 +269,11 @@ def tobool(val):
'()': 'django.utils.log.CallbackFilter',
'callback': skip_suspicious_operations,
},
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},

'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s '
Expand All @@ -278,7 +293,7 @@ def tobool(val):
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler',
'include_html': True,
'filters': ['skip_suspicious_operations']
'filters': ['skip_suspicious_operations', 'require_debug_false']
}
},
'loggers': {
Expand Down Expand Up @@ -319,15 +334,7 @@ def tobool(val):
RECAPTCHA_PUBLIC_KEY = "6LctSMUSAAAAAAe-qMSIt5Y-iTw5hcFRsk2BPYl2"
RECAPTCHA_PRIVATE_KEY = os.environ.get('RECAPTCHA_PRIVATE_KEY')

REDIS_HOST = os.environ.get('REDIS_HOST') # not used.
REDIS_PORT = 6379
REDIS_ALPHAGRAMS_DB = 0 # alphas to pks
REDIS_ALPHAGRAM_SOLUTIONS_DB = 1 # alpha_pks to solutions
REDIS_SOCKET_TOKEN_DB = 2


ALLOWED_HOSTS = ['.aerolith.org', '*']
SOCKJS_SERVER = os.environ.get('SOCKJS_SERVER') # not used.

RECAPTCHA_SSL = os.environ.get('RECAPTCHA_SSL')

Expand Down
7 changes: 0 additions & 7 deletions djAerolith/tablegame/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class GenericTableGameModel(models.Model):
(MULTIPLAYER_GAME, "MultiPlayer"),
)
lexicon = models.ForeignKey(Lexicon)
# XXX: get rid of host and inTable
host = models.ForeignKey(User, related_name="%(app_label)s_%(class)s_host")
inTable = models.ManyToManyField(
User, related_name="%(app_label)s_%(class)s_inTable")
Expand All @@ -54,9 +53,3 @@ def __unicode__(self):

class Meta:
abstract = True

EVENT_CHOICES = (
(1, "has changed the room's description."),
(2, "has joined the room."),
(3, "has left the room."),
)
6 changes: 3 additions & 3 deletions djAerolith/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<li><a href="/wordwalls" class="navbarLink">{% trans "Wordwalls" %}</a></li>
<li><a href="/wordwalls/stats" class="navbarLink">{% trans "Stats" %}</a></li>
<li><a href="/wordwalls/leaderboard" class="navbarLink">{% trans "Hall of Fame" %}</a></li>
{% if user.username == "" %}
{% if user and user.username == "" %}
<li><a href="/accounts/login" class="navbarLink">{% trans "Log in" %}</a></li>
{% else %}
<li><a href="/accounts/profile/{{user}}" class="navbarLink">
Expand All @@ -85,7 +85,7 @@
</div>
<script>

if (location.hostname === 'dev.aerolith.org') {
if (location.hostname === 'staging.aerolith.org') {
document.getElementById('devsite-alert').style.display = '';
}

Expand All @@ -107,7 +107,7 @@
{% endif %}
{% block content %}
<div class="row">
{% if user.username == "" %}
{% if user and user.username == "" %}
<p>{% trans "Welcome to Aerolith 2.0!" %}</p>
<a href="{% url 'social:begin' 'facebook' %}"><img src="/static/img/aerolith/login_with_facebook.png"></a><br><br>
<a href="{% url 'social:begin' 'google-oauth2' %}"><img src="/static/img/aerolith/login_with_google.png"></a><br><br>
Expand Down
4 changes: 2 additions & 2 deletions djAerolith/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from registration.backends.simple.views import RegistrationView

from views import (health, login_error, new_social_user, js_error, test_500,
healthz, socket_token)
healthz, trigger500)
from accounts.views import social, username_change
from base.views import listmanager
gargoyle.autodiscover()
Expand All @@ -50,6 +50,7 @@ def get_success_url(self, user):
url(r'^$', TemplateView.as_view(template_name='base.html')),
url(r'^old/', TemplateView.as_view(template_name='oldsite/index.html')),
url(r'^health/', health),
url(r'^bigfatphony/', trigger500),
url(r'^about/', TemplateView.as_view(template_name='about.html')),
url(r'^admin/', include(admin.site.urls)),
url(r'^accounts/social/$', social),
Expand Down Expand Up @@ -93,7 +94,6 @@ def get_success_url(self, user):
url(r'^wordwalls/', include('wordwalls.urls')),
url(r'^flashcards/', include('whitleyCards.urls')),
url(r'^cards/', include('flashcards.urls')),
url(r'^socket_token/', socket_token),
url(r'^base/', include('base.urls')),
url(r'^js_errors/', js_error),
url(r'^500tester/', test_500),
Expand Down
9 changes: 3 additions & 6 deletions djAerolith/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
import json

from django.shortcuts import render
from django.template import RequestContext
from django.contrib.auth.decorators import login_required
from django.core.mail import send_mail
from django.conf import settings
from django.views.decorators.csrf import csrf_exempt

from lib.socket_helper import get_connection_token
from lib.response import response, StatusCode

logger = logging.getLogger(__name__)
Expand All @@ -39,10 +37,9 @@ def health(request):
return response('OK')


@login_required
def socket_token(request):
conn_token = get_connection_token(request.user)
return response(conn_token)
def trigger500(request):
logger.info('Triggering 500 for request user: %s', request.user)
raise Exception('OH NO')


def login_error(request):
Expand Down
Loading

0 comments on commit 5615ff9

Please sign in to comment.