Skip to content

Commit

Permalink
[Backend] Prepare production server
Browse files Browse the repository at this point in the history
  • Loading branch information
danghh-1998 committed Jun 11, 2020
1 parent 7737d55 commit 71c8088
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 25 deletions.
13 changes: 0 additions & 13 deletions backend/project.conf

This file was deleted.

2 changes: 1 addition & 1 deletion backend/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@
]

MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'corsheaders.middleware.CorsMiddleware',
]

REST_FRAMEWORK = {
Expand Down
3 changes: 2 additions & 1 deletion backend/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
DEFAULT_FROM_EMAIL = os.environ.get('DEFAULT_FROM_EMAIL')
SENDGRID_API_KEY = os.environ.get('SENDGRID_API_KEY')

ALLOWED_HOSTS = [os.environ.get('HOST_IP')]
ALLOWED_HOSTS = ['*']
CORS_ORIGIN_ALLOW_ALL = True

DATABASES = {
'default': {
Expand Down
2 changes: 1 addition & 1 deletion backend/utils/static_file_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def download_s3(path):
s3 = boto3.client(service_name='s3', aws_access_key_id=settings.AWS_ACCESS_KEY,
aws_secret_access_key=settings.AWS_ACCESS_TOKEN)
bucket_name = settings.AWS_BUCKET_NAME
tmp_file = os.path.join('/tmp', f"{str(datetime.datetime.now())}.png")
tmp_file = os.path.join('/tmp', f"{str(datetime.now())}.png")
s3.download_file(bucket_name, path, tmp_file)
with open(tmp_file, 'rb+') as file:
return file.read()
Expand Down
1 change: 1 addition & 0 deletions frontend/.env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VUE_APP_BASE_URL=http://localhost:8000/api
1 change: 1 addition & 0 deletions frontend/.env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VUE_APP_BASE_URL=http://54.254.253.226/api
4 changes: 2 additions & 2 deletions frontend/src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios from 'axios'
import camelcaseKeys from "camelcase-keys";

export const api = axios.create({
baseURL: 'http://localhost:8000/api',
baseURL: process.env.VUE_APP_BASE_URL,
transformResponse: [data => {
if (data) {
return (camelcaseKeys(JSON.parse(data), {deep: true}))
Expand All @@ -11,6 +11,6 @@ export const api = axios.create({
});

export const imageApi = axios.create({
baseURL: 'http://localhost:8000/api',
baseURL: process.env.VUE_APP_BASE_URL,
responseType: "blob"
});
4 changes: 2 additions & 2 deletions frontend/src/components/folders/GridTemplate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@
},
thumbnailBackgroundImage: function () {
return {
'background-image': `url(http://127.0.0.1:8000/api/templates/${this.$props.template.id}/image/0?token=${this.token})`,
'background-image': `url(${process.env.VUE_APP_BASE_URL}/templates/${this.$props.template.id}/image/0?token=${this.token})`,
'width': '100%',
'height': '190px',
'height': '190px',
'background-position': 'center center',
'background-repeat': 'no-repeat',
'background-size': 'cover'
Expand Down
47 changes: 47 additions & 0 deletions project.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#

upstream backend {
server 127.0.0.1:8000;
}

server {
listen 80 default_server;
listen [::]:80 default_server;
index index.html index.htm index.nginx-debian.html;

server_name _;

location / {

root /home/deploy/7_trinhvt/frontend/dist;
try_files $uri $uri/ /index.html;
}

location /api/ {
proxy_pass http://backend;
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;
}
}
9 changes: 4 additions & 5 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

eval $(ssh-agent -s)
if [ -d "7_trinhvt" ]; then
if [[ -d "7_trinhvt" ]]; then
cd 7_trinhvt
git pull origin master
else
Expand All @@ -11,12 +11,11 @@ fi

CURRENT_TIME=$(date +%Y-%m-%d__%H_%M_%S)
LOG_FILE=/tmp/project/project.uwsgi.log
[ -f ${LOG_FILE} ] && mv ${LOG_FILE} /tmp/project/project.uwsgi.${CURRENT_TIME}.log
[[ -f ${LOG_FILE} ]] && mv ${LOG_FILE} /tmp/project/project.uwsgi.${CURRENT_TIME}.log

MASTER_PROCESS=$(ps aux | grep uwsgi | grep -v grep | awk '{print $2}' | head -n 1)
[ ${MASTER_PROCESS} ] && kill -9 ${MASTER_PROCESS}
[[ ${MASTER_PROCESS} ]] && kill -9 ${MASTER_PROCESS}

git checkout master
cd backend
whoami
pwd
/home/deploy/anaconda3/envs/project/bin/uwsgi project.ini

0 comments on commit 71c8088

Please sign in to comment.