-
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 18 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,9 @@ ENV/ | |
*.rdb | ||
*.swp | ||
|
||
collected_static/ | ||
|
||
# For hide SECRET_KEY | ||
secret.json | ||
pw.txt | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import sys | ||
import json | ||
|
||
from django.core.management.base import BaseCommand | ||
from django.contrib.sites.models import Site | ||
|
||
from allauth.socialaccount.models import SocialApp | ||
|
||
|
||
class Command(BaseCommand): | ||
def system_check(self): | ||
# win32 / win64 / linux(Ubuntu) | ||
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. TODO인건가요? |
||
print(sys.platform) | ||
|
||
def open_secret(self): | ||
with open('secret.json', 'r') as f: | ||
secret = json.loads(f.read()) | ||
self.social_app_setting(secret['DOMAIN'], secret['CLIENT_ID'], secret['SECRET']) | ||
|
||
def social_app_setting(self, domain, client_id, secret): | ||
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. 이 함수가 실패했는데도, |
||
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.system_check() | ||
self.open_secret() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,11 @@ class Command(BaseCommand): | |
|
||
def handle(self, *args, **options): | ||
password = get_random_string() | ||
|
||
pwfile = open('pw.txt', 'w') | ||
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. with open('pw.txt', 'w') as f:
f.write(password) 가 더 나을 것 같아요! |
||
pwfile.write(password) | ||
pwfile.close() | ||
|
||
print('Generated root password : %s' % (password,)) | ||
admin = User.objects.create_superuser( | ||
email='root@localhost', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import os | ||
import sys | ||
import json | ||
|
||
|
||
def open_secret(): | ||
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. 함수의 이름이 적절하지 않습니다. |
||
with open('secret.json', 'r') as f: | ||
print('* Plesase 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('>') | ||
|
||
result = json.load(f) | ||
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. 기존에 있는 값을 존중하나요? 무슨 의미의 json.load인가요? input과 어떤 상호작용을 하나요? 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. 그러면 이 함수는 secret_key_gen.py보다 늦게 실행되어야 겠네요. 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. migrate 이전에 secret_key가 필요합니다.
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. migrate 이전에 SECRET_KEY가 필요한지를 현재 코드 상황에서는 알았습니다. 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. autodeploy에서 migrate를 할 수 없나요? 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. SECRET_KEY=1 로 고정 후 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. |
||
|
||
result['CLIENT_ID'] = str(client_id) | ||
result['SECRET'] = str(secret) | ||
result['DOMAIN'] = str(domain) | ||
|
||
f.close() | ||
with open('secret.json', 'w') as f: | ||
json.dump(result, f) | ||
f.close() | ||
|
||
|
||
# Check OS | ||
platform = sys.platform | ||
if platform == 'win32' or platform == 'win64': | ||
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. if platform in (
'win32',
'win64',
): 이런 식이 더 나을 것 같습니다. |
||
print('Error: Cannot run in Windows..') | ||
exit(0) | ||
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. Error의 경우의 return값은 0이 아니어야 합니다. (공통) 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.
|
||
|
||
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(0) | ||
|
||
# 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 |
||
with open('requirements.txt', 'r') as packages: | ||
for package in packages: | ||
if package[0] == '#': | ||
break | ||
pip.main(['install', package]) | ||
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.main(['install', '-r', 'requirements.txt']) |
||
|
||
# DB Migration | ||
os.system('%s secret_key_gen.py' % cmd) | ||
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. 아래의 많은 os.system을 makefile로 옮기는건 어떻게 생각하시나요? 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. |
||
os.system('%s manage.py migrate' % cmd) | ||
|
||
# Admin user setting | ||
os.system('%s manage.py createsuperuserauto' % cmd) | ||
|
||
# Install redis-server / nginx | ||
if platform == 'linux': | ||
os.system('sudo apt-get install redis-server') | ||
os.system('sudo apt-get install nginx') | ||
|
||
# Find nginx location | ||
# nginx = subprocess.checkoutput('sudo find / -name nginx.conf', shell=True) | ||
|
||
# Server Deploy | ||
BASE_DIR = os.getcwd() | ||
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.
|
||
os.system('sudo rm -rf /etc/nginx/sites-enabled/local_nginx.conf') | ||
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. 여기도 |
||
os.system('sudo ln -s %s/nginx/local_nginx.conf /etc/nginx/sites-enabled/' % BASE_DIR) | ||
|
||
# OAuth setting | ||
open_secret() | ||
os.system('%s manage.py collectstatic' % cmd) | ||
os.system('%s manage.py autodeploy' % cmd) | ||
|
||
# Server run | ||
os.system('redis-server &') | ||
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. 아래에 |
||
os.system('%s manage.py runworker &' % cmd) | ||
os.system('daphne -b 0.0.0.0 -p 8001 coding_night_live.asgi:channel_layer &') | ||
os.system('sudo service nginx start') |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,21 +6,21 @@ | |
|
||
server { | ||
listen 80; | ||
server_name localhost; | ||
server_name coding-night-live.japaneast.cloudapp.azure.com; | ||
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 template로 뺼 순 없을까요? 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. minhoryang@9355534 |
||
# ex1) server_name localhost; | ||
# ex2) server_name coding-night-live.cloudapp.net; | ||
charset utf-8; | ||
client_max_body_size 20M; | ||
|
||
location /static/ { | ||
alias /opt/coding-night-live/collected_static/; # Please edit this line! | ||
alias /home/punk/coding-night-live/collected_static/; # Please edit this line! | ||
# ex) alias /home/punk/Documents/coding-night-live/collected_static/; | ||
} | ||
|
||
location / { | ||
#localhost deploy -> proxy_pass http:/localhost:8000; | ||
# 80 deploy -> proxy_pass http://0.0.0.0:8000; | ||
proxy_pass http://localhost:8000; | ||
proxy_pass http://0.0.0.0:8001; | ||
|
||
proxy_http_version 1.1; | ||
proxy_set_header Upgrade $http_upgrade; | ||
|
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 == 'win32' or platform == 'win64': | ||
print('Error: Cannot run in Windows..') | ||
exit(0) | ||
|
||
# Check Python Version (3 or 2) | ||
if sys.version_info[0] == 2: | ||
print('Error: Cannot run in Python2.x..') | ||
exit(0) | ||
|
||
# Delete files | ||
os.system('rm -rf pw.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.
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. 삭제하려면 pw.txt, secret.json, db.sqlite3의 경우 rm -f 만으로 하는게 바람직할 것 같습니다. |
||
os.system('rm -rf secret.json') | ||
os.system('rm -rf db.sqlite3') | ||
os.system('rm -rf collected_static') | ||
|
||
# Stop the services | ||
os.system('service redis-server stop') | ||
os.system('service nginx stop') | ||
|
||
# Kill the processes | ||
os.system('sudo killall -9 daphne') | ||
os.system('sudo killall -9 redis-server') | ||
os.system('sudo killall -9 python3') |
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도 가지고있어서 사실 애매모호해요.ㅎㅎ 이번 리뷰과정중에서도 이걸 짚고 넘어갈 수 있구, 아니면 다음에 해도 될 것 같아요.