Skip to content
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

Merged
merged 40 commits into from
Mar 19, 2017
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
08852d4
createsuperuserauto command creates pw.txt file.
punkyoon Mar 8, 2017
eb3516b
modified .gitignore
punkyoon Mar 8, 2017
247b7a8
create python script for auto deploy
punkyoon Mar 8, 2017
aee790f
added a autodeploy command
punkyoon Mar 8, 2017
95568e5
developing autodeploy command...
punkyoon Mar 8, 2017
aa5ac62
developting autodeploy command ... ; now can set oauth provider
punkyoon Mar 8, 2017
d4bf728
added a script file
punkyoon Mar 8, 2017
cc5afce
developing script ..
punkyoon Mar 8, 2017
f1e9236
developing script...
punkyoon Mar 8, 2017
67a5152
developing script...
punkyoon Mar 8, 2017
2a8403c
developing script.. but there's some error.. I will fix it soon
punkyoon Mar 10, 2017
baa8bfd
fixed a bug
punkyoon Mar 11, 2017
d7f0252
can deploy with auto.py
punkyoon Mar 11, 2017
fa7cdee
modified a .gitignore
punkyoon Mar 11, 2017
7ab9f8d
remove collected_static
punkyoon Mar 11, 2017
ba0d8ad
developed deploy&undeploy helper
punkyoon Mar 11, 2017
c4a6bd9
fixed flake8
punkyoon Mar 11, 2017
90ebf7e
change path
punkyoon Mar 11, 2017
a135e31
[Issue #80] Now autodeploy.py got OAuth Initializer
minhoryang Mar 12, 2017
be68a4c
[WIP] Makefile for deploy/undeploy_helper.py
minhoryang Mar 12, 2017
eb1f4b3
Merge pull request #86 from minhoryang/issue_80
punkyoon Mar 12, 2017
ca1be49
Merge branch 'master' of https://github.com/punkyoon/coding-night-liv…
punkyoon Mar 13, 2017
4b2eaa5
feedback
punkyoon Mar 13, 2017
93f9497
flake8 fix
punkyoon Mar 13, 2017
2642deb
modified travis command
punkyoon Mar 13, 2017
5a3963a
modified travis cmd
punkyoon Mar 13, 2017
9355534
[Issue #80] `python manage.py nginxconfgenerator > nginx/local_nginx.…
minhoryang Mar 13, 2017
9c6cb68
구질구질한 Makefile
AilisObrian Mar 13, 2017
b713d03
Merge remote-tracking branch 'minhoryang/issue_80' into issue_80
AilisObrian Mar 15, 2017
0ae5cf3
Minor Feedbacks Apply
AilisObrian Mar 15, 2017
fa8940e
Merge pull request #87 from minhoryang/issue_80
punkyoon Mar 16, 2017
79ec867
[Issue #84][BugFix] NGINX required sudoer for 80 port
AilisObrian Mar 18, 2017
ae66ab6
[Issue #84][BugFix] Latest Redis from Homebrew Kegs(cached) won't sta…
AilisObrian Mar 18, 2017
5d9632f
[Issue #84] Purge makefile for deps
AilisObrian Mar 18, 2017
48226e1
[Issue #84][BugFix][Related 79ec867] NGINX required sudoer rights for…
AilisObrian Mar 18, 2017
a34f399
[Issue #84][BugFix][Related 48226e1] `sudo brew services` won't worke…
AilisObrian Mar 18, 2017
c173f85
[Issue #84][Readability Improvement] Divided Makefile
AilisObrian Mar 18, 2017
1ca9ed8
Merge pull request #92 from minhoryang/issue_80
minhoryang Mar 18, 2017
c04bcb3
Tiny typo fix at requirements.txt
AilisObrian Mar 18, 2017
7a01754
Daphne-Twisted Bug Resolved, so remove the version requirement statem…
AilisObrian Mar 19, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,9 @@ ENV/
*.rdb
*.swp

collected_static/

# For hide SECRET_KEY
secret.json
pw.txt
Copy link
Member

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 안에 계정 비밀번호를 적어놔도 좋지 않을까 싶어요.

Copy link
Member

@minhoryang minhoryang Mar 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지금 secret.json이 DOMAIN도 가지고있어서 사실 애매모호해요.ㅎㅎ 이번 리뷰과정중에서도 이걸 짚고 넘어갈 수 있구, 아니면 다음에 해도 될 것 같아요.


41 changes: 41 additions & 0 deletions coding_night_live/management/commands/autodeploy.py
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)
Copy link
Member

Choose a reason for hiding this comment

The 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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 함수가 실패했는데도, secret.json을 저장해도 될까요?

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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 함수를 두번 호출하면, id=1인 SocialApp을 두번 생성하려 할겁니다.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 함수를 두번 부를 일이 없을거라고 생각하지만,
undeploy_helper.py의 역할이 무엇이냐에 따라서, 다를 수도 있습니다.

Copy link
Member

@juice500ml juice500ml Mar 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The 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()
5 changes: 5 additions & 0 deletions coding_night_live/management/commands/createsuperuserauto.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ class Command(BaseCommand):

def handle(self, *args, **options):
password = get_random_string()

pwfile = open('pw.txt', 'w')
Copy link
Member

@juice500ml juice500ml Mar 12, 2017

Choose a reason for hiding this comment

The 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',
Expand Down
1 change: 0 additions & 1 deletion coding_night_live/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
with open(secret_file, 'r') as f:
secret = json.loads(f.read())


def get_secret(setting, secret=secret):
try:
return secret[setting]
Expand Down
82 changes: 82 additions & 0 deletions deploy_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import os
import sys
import json


def open_secret():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

함수의 이름이 적절하지 않습니다.
create_secret_json?

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기존에 있는 값을 존중하나요? 무슨 의미의 json.load인가요? input과 어떤 상호작용을 하나요?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그러면 이 함수는 secret_key_gen.py보다 늦게 실행되어야 겠네요.
secret.json이 없으면 에러가 나니까요.
그냥 합치면 안될까요?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

python manage.py migrate가 SECRET_KEY를 필요로 하나요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

migrate 이전에 secret_key가 필요합니다.

  1. python3 secret_key_gen.py 실행 시, secret_key만 명시되어있는 secret.json 생성
  2. input으로 OAuth 관련 설정 입력 받아 secret.json에 추가해줌
  3. python3 manage.py autodeploy에서 secret.json에 있는 내용을 토대로 OAuth 설정

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

migrate 이전에 SECRET_KEY가 필요한지를 현재 코드 상황에서는 알았습니다.
그런데 'migrate 과정에서 SECRET_KEY가 필요한가'라는 물음을 확인하지 못했을 뿐입니다.
django가 SECRET_KEY를 필요로 하다는걸 ImproperlyConfigured로 확인했습니다만,
settings.py에 정의되어 있는 SECRET_KEY를 조금 수정해서, 그 단계를 넘길 수 있다고 생각하고 있습니다.
정말 migrate단계에서 SECRET_KEY가 필요할까요?
secret_key_gen.py와 이 파일을 합칠 수 있지 않을까요?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

autodeploy에서 migrate를 할 수 없나요?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SECRET_KEY=1 로 고정 후 python manage.py migrate를 진행하고 나서도,
python secret_key_gen.py, python manage.py cratesuperuserauto, python manage.py runserver를 통해서 admin페이지에 잘 접근이 가능함을 확인하였습니다.

Copy link
Member

Choose a reason for hiding this comment

The 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':
Copy link
Member

Choose a reason for hiding this comment

The 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error의 경우의 return값은 0이 아니어야 합니다. (공통)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exit(-1)


cmd = 'python3'

# Check Python Version (3 or 2)
if sys.version_info[0] == 2:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

무슨 이유로 이 파일은 python3만 지원하는건가요?

Copy link
Member Author

@punkyoon punkyoon Mar 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@minhoryang django 2.0부터는 python2.7을 아예 지원하지 않습니다. 추후 django 버전 업을 대비하여 2버전에서는 아예 실행하지 못하도록 막아두었습니다.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@punkyoon 오! 장고도 드디어! 알겠습니다 :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@punkyoon Django 2.0으로의 migration(?)이 바람직할려나 모르겠네요! 1.1x를 그대로 갖고 가는게 나을지도 모르고요

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

django 2.0에서의 channels 지원 여부에 따라 좀 갈릴 것 같네요. 일단 py2에서도 하게 하는게 맞는 것 같아요!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@juice500ml django-channels는 py3.5+를 지원한다는데, django 2.0이 channels를 지원할 계획인지 여부 말하시는거죠?
https://github.com/django/channels/blob/13472369ebf18d2925302aa1a407405b67a3e7c5/tox.ini

Copy link
Member

Choose a reason for hiding this comment

The 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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pip를 설치만 하고, import를 진행하지 않습니다. Line 51에서 pip를 찾지 못할 예정입니다.

Copy link
Member

Choose a reason for hiding this comment

The 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])
Copy link
Member

Choose a reason for hiding this comment

The 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아래의 많은 os.system을 makefile로 옮기는건 어떻게 생각하시나요?

Copy link
Member

Choose a reason for hiding this comment

The 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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

os.getcwd()는 현재 이 파일의 위치를 보장하지 않습니다.
os.path.dirname(os.path.abspath(__file__))를 사용하세요.

os.system('sudo rm -rf /etc/nginx/sites-enabled/local_nginx.conf')
Copy link
Member

@minhoryang minhoryang Mar 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 파일의 백업본을 만들어주세요.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기도 rm -f 입니다~

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 &')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아래에 &을 붙은 명령들이 모두 background service로 남길 바라시나요?
모두 sighup을 무시하나요? 다른 서비스 매니저가 필요할 것 같은데요?
(ex. supervisord라던지)

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')
6 changes: 3 additions & 3 deletions local_nginx.conf → nginx/local_nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@

server {
listen 80;
server_name localhost;
server_name coding-night-live.japaneast.cloudapp.azure.com;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 파일을 django template로 뺼 순 없을까요?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The 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;
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ asgi_redis
pyhaikunator
django-redis
raven
Twisted==16.0.0 # Issue #54. Not worked with Twisted==17.0.0
Twisted==16.0.0
# Issue #54. Not worked with Twisted==17.0.0
7 changes: 6 additions & 1 deletion secret_key_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
chars = 'qwertyuiopasdfghjklzxcvbnm0987654321!@#$%^&*(-_=+)'
SECRET_KEY = get_random_string(50, chars)

value = {"SECRET_KEY": SECRET_KEY}
value = {
"SECRET_KEY": SECRET_KEY,
"DOMAIN": 'please write domain',
"CLIENT_ID": 'please write oauth2 client_id',
"SECRET": 'please write oauth2 secret',
}

with open('secret.json', 'w') as result_file:
json.dump(value, result_file, ensure_ascii=False)
Expand Down
28 changes: 28 additions & 0 deletions undeploy_helper.py
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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rm -rf로 기존에 있는 파일을 꼭 지워야 하나요?
open(, 'w')도 마찬가지입니다.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

삭제하려면 pw.txt, secret.json, db.sqlite3의 경우 rm -f 만으로 하는게 바람직할 것 같습니다.
collected_static은 삭제해야하는지 약간은 의문이네요!

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')