-
Notifications
You must be signed in to change notification settings - Fork 11
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
Issue #80 #84
Issue #80 #84
Changes from all commits
08852d4
eb3516b
247b7a8
aee790f
95568e5
aa5ac62
d4bf728
cc5afce
f1e9236
67a5152
2a8403c
baa8bfd
d7f0252
fa7cdee
7ab9f8d
ba0d8ad
c4a6bd9
90ebf7e
a135e31
be68a4c
eb1f4b3
ca1be49
4b2eaa5
93f9497
2642deb
5a3963a
9355534
9c6cb68
b713d03
0ae5cf3
fa8940e
79ec867
ae66ab6
5d9632f
48226e1
a34f399
c173f85
1ca9ed8
c04bcb3
7a01754
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,5 +96,11 @@ ENV/ | |
*.rdb | ||
*.swp | ||
|
||
collected_static/ | ||
|
||
# For hide SECRET_KEY | ||
secret.json | ||
pw.txt | ||
nginx/local_nginx.conf | ||
.prepared | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
OS := $(shell uname) | ||
|
||
default: start | ||
.PHONY: start stop uninstall | ||
|
||
|
||
include Makefile.deps | ||
include Makefile.prepare | ||
|
||
|
||
start: \.prepared deps-start | ||
python3 manage.py runworker & | ||
daphne -b 0.0.0.0 -p 8001 coding_night_live.asgi:channel_layer & | ||
|
||
|
||
stop: deps-stop | ||
-killall -9 daphne | ||
-killall -9 python3 | ||
-killall -9 python # FIXME: daphne at MAC OS | ||
|
||
|
||
uninstall: stop clean deps-uninstall |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
.PHONY: sudo deps-install deps-uninstall deps-start deps-stop prepare-nginx | ||
|
||
|
||
sudo: | ||
sudo -v | ||
|
||
|
||
deps-install: sudo | ||
ifeq ($(OS),Linux) | ||
sudo apt-get install redis-server | ||
sudo apt-get install nginx | ||
else ifeq ($(OS),Darwin) | ||
brew list redis > /dev/null || brew install redis --build-from-source # FIXME: Homebrew/homebrew-core#11134 | ||
brew list nginx > /dev/null || brew install nginx | ||
else | ||
echo 'ACITON REQUIRED) Need to install redis and nginx before this.' | ||
endif | ||
|
||
|
||
deps-uninstall: sudo | ||
ifeq ($(OS),Linux) | ||
# TODO | ||
echo 'ACITON REQUIRED) Need to uninstall redis and nginx after this.' | ||
else ifeq ($(OS),Darwin) | ||
-brew list redis > /dev/null && brew uninstall redis | ||
-brew list nginx > /dev/null && brew uninstall nginx | ||
else | ||
echo 'ACITON REQUIRED) Need to uninstall redis and nginx after this.' | ||
endif | ||
|
||
|
||
deps-start: sudo | ||
ifeq ($(OS),Linux) | ||
sudo service redis-server start | ||
else ifeq ($(OS),Darwin) | ||
brew services run redis | ||
else | ||
sudo redis-server & | ||
endif | ||
ifeq ($(OS),Linux) | ||
sudo service nginx start | ||
else | ||
sudo nginx & | ||
endif | ||
|
||
|
||
deps-stop: sudo | ||
ifeq ($(OS),Linux) | ||
sudo service nginx stop | ||
else ifeq ($(OS),Darwin) | ||
-sudo killall -9 'nginx: master process nginx' | ||
-sudo killall -9 'nginx: worker process' | ||
-sudo killall -9 nginx | ||
else | ||
-sudo killall -9 'nginx: master process nginx' | ||
-sudo killall -9 'nginx: worker process' | ||
-sudo killall -9 nginx | ||
endif | ||
ifeq ($(OS),Linux) | ||
-sudo service redis-server stop | ||
else ifeq ($(OS),Darwin) | ||
-brew services stop redis | ||
else | ||
-sudo killall -9 redis-server | ||
endif | ||
|
||
|
||
prepare-nginx: sudo nginx/local_nginx.conf | ||
ifeq ($(OS),Linux) | ||
sudo rm -f /etc/nginx/sites-enabled/local_nginx.conf | ||
sudo ln -s `pwd`/nginx/local_nginx.conf /etc/nginx/sites-enabled/ | ||
else ifeq ($(OS),Darwin) | ||
rm -f /usr/local/etc/nginx/servers/local_nginx.conf | ||
ln -s `pwd`/nginx/local_nginx.conf /usr/local/etc/nginx/servers/ | ||
else | ||
# FIXME ln -s `pwd`/nginx/local_nginx.conf /usr/local/etc/nginx/servers/ | ||
endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
.PHONY: prepare clean | ||
|
||
db.sqlite3: | ||
python3 manage.py migrate | ||
|
||
pw.txt: db.sqlite3 | ||
python3 manage.py createsuperuserauto | ||
|
||
collected_static/: | ||
yes yes | python3 manage.py collectstatic | ||
|
||
secret.json: db.sqlite3 | ||
python3 manage.py autodeploy | ||
|
||
nginx/local_nginx.conf: secret.json | ||
python3 manage.py nginxconfgenerator > nginx/local_nginx.conf | ||
|
||
prepare \.prepared: \ | ||
deps-install\ | ||
db.sqlite3\ | ||
pw.txt\ | ||
collected_static/\ | ||
secret.json\ | ||
nginx/local_nginx.conf\ | ||
prepare-nginx\ | ||
|
||
touch .prepared | ||
|
||
clean: | ||
-rm \ | ||
secret.json\ | ||
db.sqlite3\ | ||
pw.txt\ | ||
nginx/local_nginx.conf\ | ||
.prepared\ | ||
-rm -r collected_static |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import json | ||
|
||
from django.core.management.base import BaseCommand | ||
from django.contrib.sites.models import Site | ||
from django.db.utils import OperationalError | ||
from django.utils.crypto import get_random_string | ||
|
||
from allauth.socialaccount.models import SocialApp | ||
|
||
|
||
class AutoDeployException(Exception): | ||
pass | ||
|
||
|
||
class AutoDeploySecretNotFound(AutoDeployException): | ||
pass | ||
|
||
|
||
class AutoDeployDatabaseNotPrepared(AutoDeployException): | ||
@staticmethod | ||
def checker(suspiciousFunc): | ||
def _runtime_checker(*args, **kwargs): | ||
try: | ||
return suspiciousFunc(*args, **kwargs) | ||
except OperationalError: | ||
raise AutoDeployDatabaseNotPrepared('ACTION REQUIRED) RUN `python manage.py migrate` FIRST!') | ||
return _runtime_checker | ||
|
||
|
||
def loadSecret(): | ||
secret = {} | ||
try: | ||
with open('secret.json', 'r') as f: # FIXME: PATH | ||
secret.update(json.loads(f.read())) | ||
except FileNotFoundError: | ||
raise AutoDeploySecretNotFound('ACITON REQUIRED) RUN `python manage.py autodeploy` FIRST!') | ||
return secret | ||
|
||
|
||
class Command(BaseCommand): | ||
requires_migrations_checks = True | ||
|
||
def open_secret(self): | ||
print('* Please write your OAuth Client ID') | ||
client_id = input('>') | ||
print('** Please write your OAuth Secret') | ||
secret = input('>') | ||
print('*** Please write your Server Domain (ex. example.com)') | ||
domain = input('>') | ||
|
||
chars = 'qwertyuiopasdfghjklzxcvbnm0987654321!@#$%^&*(-_=+)' | ||
SECRET_KEY = get_random_string(50, chars) | ||
|
||
result = {} | ||
|
||
result['CLIENT_ID'] = str(client_id) | ||
result['SECRET'] = str(secret) | ||
result['DOMAIN'] = str(domain) | ||
result['SECRET_KEY'] = SECRET_KEY | ||
|
||
with open('secret.json', 'w') as f: | ||
json.dump(result, f) | ||
|
||
secret = loadSecret() | ||
self.social_app_setting(secret['DOMAIN'], secret['CLIENT_ID'], secret['SECRET']) | ||
|
||
@AutoDeployDatabaseNotPrepared.checker | ||
def social_app_setting(self, domain, client_id, secret): | ||
default_site_1 = Site.objects.get(id=1) | ||
default_site_1.domain = domain | ||
default_site_1.name = domain | ||
default_site_1.save() | ||
|
||
new_social_app = SocialApp( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 함수를 두번 호출하면, id=1인 SocialApp을 두번 생성하려 할겁니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 함수를 두번 부를 일이 없을거라고 생각하지만, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. id가 autoincrement 될테니 굳이 id=1로 안해도 되지 않나요? Ref. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 그렇게할까요? @punkyoon @juice500ml |
||
id=1, | ||
provider='google', | ||
name=domain, | ||
client_id=client_id, | ||
secret=secret, | ||
key='', | ||
) | ||
|
||
new_social_app.save() | ||
new_social_app.sites.add(default_site_1) | ||
new_social_app.save() | ||
|
||
def handle(self, *args, **options): | ||
self.open_secret() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from django.core.management.base import BaseCommand | ||
from django.conf import settings | ||
from django.template import Template, Context | ||
|
||
from .autodeploy import loadSecret | ||
|
||
|
||
NGINX_CONF_TEMPLATE = Template(''' | ||
# <NOTICE> /etc/nginx/ may not your nginx installation path. please check your installation path before. | ||
# You need to run the script below! | ||
# sudo ln -s coding-night-live/coding-night-live_nginx.conf /etc/nginx/sites-enabled/ | ||
# ex) sudo ln -s /home/punk/coding-night-live/collected_static /etc/nginx/sites-enabled/ | ||
server { | ||
listen 80; | ||
server_name {{ SERVER_NAME }}; | ||
charset utf-8; | ||
client_max_body_size 20M; | ||
location /static/ { | ||
alias {{ BASE_DIR }}/collected_static/; | ||
} | ||
location / { | ||
proxy_pass http://0.0.0.0:8001; | ||
proxy_http_version 1.1; | ||
proxy_set_header Upgrade $http_upgrade; | ||
proxy_set_header Connection "upgrade"; | ||
proxy_redirect off; | ||
proxy_set_header Host $host; | ||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header X-Forwarded-Host $server_name; | ||
} | ||
} | ||
''') | ||
|
||
|
||
def _dontBelieve(conf, key, _defaultValue): | ||
believableValue = conf.get(key, None) | ||
if believableValue: | ||
return believableValue | ||
return _defaultValue | ||
|
||
|
||
class Command(BaseCommand): | ||
def handle(self, *args, **options): | ||
secret = loadSecret() | ||
variables = Context({ | ||
'BASE_DIR': settings.BASE_DIR, | ||
'SERVER_NAME': _dontBelieve(secret, 'DOMAIN', 'localhost'), | ||
'PROXY_PASS': None, | ||
'PORT': None, | ||
}) | ||
self.stdout.write(NGINX_CONF_TEMPLATE.render(variables)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import os | ||
import sys | ||
|
||
|
||
# Check OS | ||
platform = sys.platform | ||
if platform in ('win32', 'win64'): | ||
print('Error: Cannot run in Windows..') | ||
exit(-1) | ||
|
||
cmd = 'python3' | ||
|
||
# Check Python Version (3 or 2) | ||
if sys.version_info[0] == 2: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 무슨 이유로 이 파일은 python3만 지원하는건가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @minhoryang django 2.0부터는 python2.7을 아예 지원하지 않습니다. 추후 django 버전 업을 대비하여 2버전에서는 아예 실행하지 못하도록 막아두었습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @punkyoon 오! 장고도 드디어! 알겠습니다 :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @punkyoon Django 2.0으로의 migration(?)이 바람직할려나 모르겠네요! 1.1x를 그대로 갖고 가는게 나을지도 모르고요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. django 2.0에서의 channels 지원 여부에 따라 좀 갈릴 것 같네요. 일단 py2에서도 하게 하는게 맞는 것 같아요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @juice500ml django-channels는 py3.5+를 지원한다는데, django 2.0이 channels를 지원할 계획인지 여부 말하시는거죠? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @minhoryang 넵넵 그쵸 사실 django-channels가 django 1.10에 들어오기로 했었는데 그게 무산됐거든요! django 2버전에서는 어떻게 될지 아직 미정 상태인거같아요 |
||
print('Error: Cannot run in Python 2.x..') | ||
exit(-1) | ||
|
||
# Install python packages | ||
try: | ||
import pip | ||
except ImportError: | ||
print("Installing pip...") | ||
if platform == 'linux': | ||
os.system('sudo apt-get install python3-pip') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pip를 설치만 하고, import를 진행하지 않습니다. Line 51에서 pip를 찾지 못할 예정입니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. resolved |
||
import pip | ||
pip.main(['install', '-r', 'requirements.txt']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indentation이 이상해요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @juice500ml 음?! 어떤점이 이상할까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 플랫폼이 linux가 아니면 pip package가 import가 안되는데요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @juice500ml ping? |
||
|
||
os.system('make') |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@punkyoon @minhoryang secret.json과 pw.txt가 쪼개져있는게 약간 미묘해요. secret.json 안에 계정 비밀번호를 적어놔도 좋지 않을까 싶어요.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
지금 secret.json이 DOMAIN도 가지고있어서 사실 애매모호해요.ㅎㅎ 이번 리뷰과정중에서도 이걸 짚고 넘어갈 수 있구, 아니면 다음에 해도 될 것 같아요.