Skip to content

Commit 18dd76c

Browse files
committed
initial commit
0 parents  commit 18dd76c

40 files changed

+1080
-0
lines changed

.gitignore

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# common files
2+
.DS_Store
3+
4+
5+
.idea/
6+
*.pyc
7+
*.log
8+
*.py[codt]
9+
10+
*.so
11+
*.egg
12+
*.egg-info
13+
staticfiles
14+
15+
pip-log.txt
16+
.coverage
17+
.tox
18+
nosetests.xml
19+
20+
21+
*.key
22+
*.pem
23+
credentials/
24+
25+
logs/*
26+
27+
!logs/holder.txt
28+
29+
project/media/*
30+
!project/media/profiles/holder.txt
31+
32+
# npm
33+
34+
*.min.js
35+
36+
37+
# redis
38+
dump.rdb
39+

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# AWS CodeDeploy Simple setting for Django Framework

appspec.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
version: 0.0
2+
os: linux
3+
files:
4+
- source: /
5+
destination: /home/ec2-user/www/project
6+
permissions:
7+
- object: /home/ec2-user/www
8+
pattern: "**"
9+
owner: ec2-user
10+
group: ec2-user
11+
hooks:
12+
BeforeInstall:
13+
- location: scripts/clean_instance.sh
14+
timeout: 6000
15+
runas: root
16+
AfterInstall:
17+
- location: scripts/install_os_dependencies.sh
18+
timeout: 6000
19+
runas: root
20+
- location: scripts/install_python_dependencies.sh
21+
timeout: 6000
22+
runas: ec2-user
23+
- location: scripts/migrate.sh
24+
timeout: 6000
25+
runas: ec2-user
26+
- location: scripts/ngnix.sh
27+
timeout: 6000
28+
runas: ec2-user
29+
ApplicationStart:
30+
- location: scripts/start_application.sh
31+
timeout: 6000
32+
runas: ec2-user
33+
ApplicationStop:
34+
- location: scripts/stop_application.sh
35+
timeout: 6000
36+
runas: ec2-user

fabfile.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from fabric.api import local
2+
from fabric.decorators import task
3+
4+
postgres_dir = "/usr/local/var/postgres"
5+
postgres_log = "/usr/local/var/postgres/server.log"
6+
7+
8+
@task
9+
def run_db_on_mac():
10+
local("pg_ctl -D {} -l {} start".format(postgres_dir, postgres_log), capture=False)

logs/holder.txt

Whitespace-only changes.

manage.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
5+
if __name__ == "__main__":
6+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
7+
8+
from django.core.management import execute_from_command_line
9+
10+
execute_from_command_line(sys.argv)

nginx/default.conf

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# For more information on configuration, see:
2+
# * Official English Documentation: http://nginx.org/en/docs/
3+
# * Official Russian Documentation: http://nginx.org/ru/docs/
4+
5+
user nginx;
6+
worker_processes auto;
7+
8+
error_log /var/log/nginx/error.log;
9+
#error_log /var/log/nginx/error.log notice;
10+
#error_log /var/log/nginx/error.log info;
11+
12+
pid /var/run/nginx.pid;
13+
14+
events {
15+
worker_connections 1024;
16+
}
17+
18+
http {
19+
include /etc/nginx/mime.types;
20+
default_type application/octet-stream;
21+
22+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
23+
'$status $body_bytes_sent "$http_referer" '
24+
'"$http_user_agent" "$http_x_forwarded_for"';
25+
26+
access_log /var/log/nginx/access.log main;
27+
28+
sendfile on;
29+
tcp_nopush on;
30+
tcp_nodelay on;
31+
32+
#keepalive_timeout 0;
33+
keepalive_timeout 65;
34+
types_hash_max_size 2048;
35+
36+
#gzip on;
37+
38+
# Load modular configuration files from the /etc/nginx/conf.d directory.
39+
# See http://nginx.org/en/docs/ngx_core_module.html#include
40+
# for more information.
41+
include /etc/nginx/conf.d/*.conf;
42+
43+
index index.html index.htm;
44+
45+
server {
46+
listen 80;
47+
server_name localhost;
48+
root /usr/share/nginx/html;
49+
50+
#charset koi8-r;
51+
52+
#access_log /var/log/nginx/host.access.log main;
53+
54+
location / {
55+
}
56+
57+
# redirect server error pages to the static page /40x.html
58+
#
59+
error_page 404 /404.html;
60+
location = /40x.html {
61+
}
62+
63+
# redirect server error pages to the static page /50x.html
64+
#
65+
error_page 500 502 503 504 /50x.html;
66+
location = /50x.html {
67+
}
68+
69+
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
70+
#
71+
#location ~ \.php$ {
72+
# proxy_pass http://127.0.0.1;
73+
#}
74+
75+
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
76+
#
77+
#location ~ \.php$ {
78+
# root html;
79+
# fastcgi_pass 127.0.0.1:9000;
80+
# fastcgi_index index.php;
81+
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
82+
# include fastcgi_params;
83+
#}
84+
85+
# deny access to .htaccess files, if Apache's document root
86+
# concurs with nginx's one
87+
#
88+
#location ~ /\.ht {
89+
# deny all;
90+
#}
91+
}
92+
93+
94+
# another virtual host using mix of IP-, name-, and port-based configuration
95+
#
96+
#server {
97+
# listen 8000;
98+
# listen somename:8080;
99+
# server_name somename alias another.alias;
100+
# root html;
101+
102+
# location / {
103+
# }
104+
#}
105+
106+
107+
# HTTPS server
108+
#
109+
#server {
110+
# listen 443;
111+
# server_name localhost;
112+
# root html;
113+
114+
# ssl on;
115+
# ssl_certificate cert.pem;
116+
# ssl_certificate_key cert.key;
117+
118+
# ssl_session_timeout 5m;
119+
120+
# ssl_protocols SSLv2 SSLv3 TLSv1;
121+
# ssl_ciphers HIGH:!aNULL:!MD5;
122+
# ssl_prefer_server_ciphers on;
123+
124+
# location / {
125+
# }
126+
#}
127+
128+
include /etc/nginx/sites-enabled/*.conf;
129+
}

nginx/staging.conf

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
upstream app_server {
2+
server localhost:8000;
3+
}
4+
5+
server {
6+
7+
listen 80;
8+
server_name your-domain-here;
9+
access_log /etc/nginx/log/local-wc.access.log;
10+
error_log /etc/nginx/log/local-wc.error.log;
11+
12+
13+
location /api/v1 {
14+
proxy_pass http://app_server/api/v1;
15+
proxy_redirect off;
16+
proxy_set_header Host $host;
17+
proxy_set_header X-Real-IP $remote_addr;
18+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
19+
proxy_set_header X-Forwarded-Protocol $scheme;
20+
}
21+
22+
location / {
23+
proxy_pass http://app_server/;
24+
proxy_redirect off;
25+
proxy_set_header Host $host;
26+
proxy_set_header X-Real-IP $remote_addr;
27+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
28+
proxy_set_header X-Forwarded-Protocol $scheme;
29+
}
30+
}

project/__init__.py

Whitespace-only changes.

project/apps/__init__.py

Whitespace-only changes.

project/apps/authentication/__init__.py

Whitespace-only changes.

project/apps/authentication/urls.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.conf.urls import url
2+
3+
urlpatterns = [
4+
url(r'auth/login/$', 'rest_framework_jwt.views.obtain_jwt_token', name="obtain_jwt"),
5+
]

project/apps/authentication/utils.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from rest_framework_jwt.settings import api_settings
2+
3+
4+
def create_jwt_token(user):
5+
jwt_payload_handler = api_settings.JWT_PAYLOAD_HANDLER
6+
jwt_encode_handler = api_settings.JWT_ENCODE_HANDLER
7+
8+
if user:
9+
payload = jwt_payload_handler(user)
10+
return jwt_encode_handler(payload)
11+
12+
return None

project/apps/core/__init__.py

Whitespace-only changes.

project/apps/core/utils.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import os
2+
import random
3+
import string
4+
from rest_framework.exceptions import ParseError
5+
6+
# http://stackoverflow.com/questions/2257441/random-string-generation-with-upper-case-letters-and-digits-in-python/23728630#23728630
7+
from uuid import uuid4
8+
from django.utils.deconstruct import deconstructible
9+
10+
11+
def get_random_string(length=10):
12+
return ''.join(random.SystemRandom().choice(string.ascii_letters + string.digits) for _ in range(length))
13+
14+
def delete_file_local(path):
15+
print "%s deleted" % (path,)
16+
os.remove(path)
17+
18+
19+
@deconstructible
20+
class GenerateRandomFilename(object):
21+
22+
def __init__(self, sub_path, allowed_ext=None):
23+
self.path = sub_path
24+
self.allowed_ext = allowed_ext
25+
26+
def __call__(self, instance, filename):
27+
ext = filename.split('.')[-1]
28+
ext = ext.lower()
29+
if self.allowed_ext and (ext not in self.allowed_ext):
30+
raise ParseError(detail="this file is not proper.")
31+
# set filename as random string
32+
filename = '{}.{}'.format(uuid4().hex, ext)
33+
# return the whole path to the file
34+
return os.path.join(self.path, filename)

project/apps/core/views.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.http import JsonResponse
2+
3+
4+
def api_404(request):
5+
return JsonResponse({'detail': 'url not found'}, status=404)

project/apps/profiles/__init__.py

Whitespace-only changes.

project/apps/profiles/admin.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.
4+
from .models import User
5+
6+
admin.site.register(User)

project/apps/profiles/models.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from __future__ import unicode_literals
2+
3+
from django.db import models
4+
from django.conf import settings
5+
from django.contrib.auth.models import AbstractUser, UserManager
6+
7+
from core.utils import GenerateRandomFilename
8+
9+
10+
image_dir = "profiles"
11+
allowed_ext = ['png', 'jpeg', 'jpg', 'gif', 'bmp']
12+
generate_random_filename = GenerateRandomFilename(image_dir, allowed_ext=allowed_ext)
13+
14+
class User(AbstractUser):
15+
16+
# common
17+
profile_img = models.ImageField(upload_to=generate_random_filename, blank=True, null=True)
18+
19+
def __unicode__(self):
20+
return self.username
21+
22+
@property
23+
def profile_img_url(self):
24+
if self.profile_img and self.profile_img.url:
25+
return self.profile_img.url
26+
27+
return settings.MEDIA_URL + "%s/empty_user_profile_img.png" % (image_dir,)
28+

0 commit comments

Comments
 (0)