-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from dduk-ddak/issue_85
Issue 85 Done!
- Loading branch information
Showing
14 changed files
with
258 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
default: start | ||
|
||
sudo: | ||
sudo -v | ||
|
||
start: prepare sudo | ||
sudo service redis-server start | ||
python3 manage.py runworker & | ||
daphne -b 0.0.0.0 -p 8001 coding_night_live.asgi:channel_layer & | ||
sudo service nginx start # FIXME | ||
|
||
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 | ||
|
||
prepare: deps-install db.sqlite3 pw.txt collected_static/ secret.json | ||
|
||
|
||
OS := $(shell uname) | ||
deps-install: | ||
ifeq ($(OS),Linux) | ||
sudo apt-get install redis-server | ||
sudo apt-get install nginx | ||
else | ||
echo 'ACITON REQUIRED) Need to install redis and nginx before this.' | ||
endif | ||
|
||
stop: sudo | ||
-sudo service nginx stop | ||
-sudo killall -9 daphne # FIXME | ||
-sudo killall -9 python3 # FIXME | ||
-sudo service redis-server stop | ||
|
||
clean: | ||
-rm secret.json db.sqlite3 | ||
-rm -r collected_static | ||
|
||
uninstall: stop clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import json | ||
|
||
from django.core.management.base import BaseCommand | ||
from django.contrib.sites.models import Site | ||
from django.utils.crypto import get_random_string | ||
|
||
from allauth.socialaccount.models import SocialApp | ||
|
||
|
||
class Command(BaseCommand): | ||
|
||
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) | ||
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): | ||
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( | ||
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import os | ||
import sys | ||
|
||
|
||
# Check OS | ||
platform = sys.platform | ||
if platform in ('win32', 'win64'): | ||
print('Error: Cannot run in Windows..') | ||
exit(0) | ||
|
||
cmd = 'python3' | ||
|
||
# Check Python Version (3 or 2) | ||
if sys.version_info[0] == 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') | ||
import pip | ||
pip.main(['install', '-r', 'requirements.txt']) | ||
|
||
# DB Migration | ||
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.path.dirname(os.path.abspath(__file__)) | ||
os.system('sudo rm -rf /etc/nginx/sites-enabled/local_nginx.conf') | ||
os.system('sudo ln -s %s/nginx/local_nginx.conf /etc/nginx/sites-enabled/' % BASE_DIR) | ||
|
||
# OAuth setting | ||
os.system('%s manage.py collectstatic' % cmd) | ||
os.system('%s manage.py autodeploy' % cmd) | ||
|
||
# Server run | ||
os.system('redis-server &') | ||
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>Server Error</title> | ||
|
||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/js/bootstrap.min.js" integrity="sha384-vZ2WRJMwsjRMW/8U7i6PWi6AlO1L79snBrmgiDpgIWJ82z8eA5lenwvxbMV1PAh7" crossorigin="anonymous"></script> | ||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css" integrity="sha384-AysaV+vQoT3kOAXZkl02PThvDr8HYKPZhNT5h/CXfBThSRXQ6jW5DO2ekP5ViFdi" crossorigin="anonymous"> | ||
|
||
<style> | ||
.full{ | ||
background: white no-repeat center center fixed; | ||
-webkit-background-size: cover; | ||
-moz-background-size: cover; | ||
background-size: cover; | ||
-o-background-size: cover; | ||
height:100%; | ||
} | ||
.box { | ||
background: #b4dbfd; | ||
display: block; | ||
margin-left: auto; | ||
margin-right: auto; | ||
width: 70%; | ||
max-width:400px; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body class="container-fluid full"> | ||
<div class="jumbotron box" style="margin-top:30vh"> | ||
<h1>Server Error!</h1> | ||
<small>Error 500</small> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters