Skip to content

Commit

Permalink
Slim setup & python 2to3 & upgrade requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
Iago Veloso committed Oct 28, 2018
1 parent a4369e4 commit 0e37809
Show file tree
Hide file tree
Showing 118 changed files with 913 additions and 1,154 deletions.
2 changes: 1 addition & 1 deletion .bowerrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"allow_root": true,
"directory" : "radioco/apps/radioco/static/bower"
"directory" : "tmp_bower"
}
5 changes: 4 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
[paths]
source =
radioco/
/radioco/radioco/
/radioco/radioco/
[run]
source =
radioco
13 changes: 13 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
**/node_modules
**/__pycache__
**/.cache
test_reports/
venv/
env/
**/.pyc
**/.kdbx
**/.ipynb
**/db.sqlite3
**/.vscode
radioco/static/
radioco/apps/radioco/static/bower/
12 changes: 5 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# django collectstatic files
radioco/media/_versions/
radioco/components/
radioco/static/
/radioco/media/_versions/
/radioco/components/
/radioco/static/
/radioco/media/

# source locale
radioco/locale/en/*
Expand Down Expand Up @@ -52,6 +53,7 @@ pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
reports/
htmlcov/
nosetests.xml
coverage.xml
Expand All @@ -65,7 +67,3 @@ docs/_build/

# Files ending in ~
*~

# Docker tmp files (just in case)
id_rsa.pub
tmp_requirements.txt
10 changes: 10 additions & 0 deletions .sample.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
LANG=C.UTF-8
COMPOSE_PROJECT_NAME=radioco

SECRET_KEY=REPLACE_ME
DJANGO_LOG_LEVEL=ERROR
TIME_ZONE=Europe/Madrid
DISQUS_API_KEY=
DISQUS_WEBSITE_SHORTNAME=

PORT_BACKEND=8000
12 changes: 5 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@ services:
- docker

python:
- "2.7"
- "3.6"

branches:
only:
- master
- develop

install:
- pip install coverage coveralls invoke
- pip install coverage coveralls

script:
- inv --echo docker.setup -e base
- inv --echo docker.run_coverage -e base
- inv --echo docker.destroy -e base
- coverage combine
- sh -x run coverage
- cd reports && coverage combine

after_success:
coveralls
cd reports && coveralls
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Open a terminal and introduce the following commands::
git clone https://github.com/iago1460/django-radio
cd django-radio
chmod +x ./run
./run start
./run start_dev
./run manage create_example_data


Expand Down
16 changes: 16 additions & 0 deletions docker-compose.override.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: '3.4'
services:


# Backend server -------------------------------------------------------------

django:
environment:
- DEBUG=True
volumes:
- ./:/radioco/
ports:
- ${PORT_BACKEND}:8000
command: /bin/sh -c "cd /radioco && ./docker/scripts/launch_dev_server.sh"
#stdin_open: true
#tty: true # ERROR: An HTTP request took too long to complete. https://github.com/docker/compose/issues/3633
31 changes: 31 additions & 0 deletions docker-compose.staging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: '3.4'
services:


# Backend server -------------------------------------------------------------

django:
environment:
- DEBUG=False
volumes:
- ./radioco/static/:/radioco/radioco/static/
command: /bin/sh -c "cd /radioco && ./docker/scripts/launch_server.sh"

nginx:
image: nginx:1.13.1-alpine
restart: always
volumes:
- ./docker/nginx.conf:/etc/nginx/nginx.conf:ro
- ./radioco/static:/static:ro
- ./radioco/media:/media:ro
ports:
- ${PORT_BACKEND}:8000
env_file:
- .env
command: /bin/sh -c "nginx -g 'daemon off;'"
links:
- django

memcached:
image: memcached:1.4.37-alpine
command: memcached -m 512m
36 changes: 25 additions & 11 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3'
version: '3.4'
services:


Expand All @@ -9,14 +9,28 @@ services:
context: .
dockerfile: docker/django.Dockerfile
environment:
- DJANGO_LOG_LEVEL=ERROR
- MANAGE_PY=${MANAGE_PY:-python manage.py}
- SECRET_KEY=$SECRET_KEY
- DJANGO_LOG_LEVEL=$DJANGO_LOG_LEVEL
- TIME_ZONE=$TIME_ZONE
- DISQUS_API_KEY=$DISQUS_API_KEY
- DISQUS_WEBSITE_SHORTNAME=$DISQUS_WEBSITE_SHORTNAME
volumes:
- ./:/radioco
expose:
- ${PORT_BACKEND}
ports:
- ${PORT_BACKEND}:8000
command: /radioco/docker/scripts/launch_server.sh
stdin_open: true
#tty: true # ERROR: An HTTP request took too long to complete. https://github.com/docker/compose/issues/3633
- ./radioco/media/:/radioco/radioco/media/
links:
- postgres

postgres:
image: postgres:11.0
restart: always
environment:
POSTGRES_DB: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
volumes:
- database_data:/var/lib/postgresql/data

# Volumes ---------------------------------------------------------------------

volumes:
database_data:
name: database_data
30 changes: 18 additions & 12 deletions docker/django.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
FROM python:2.7
FROM python:3.6-jessie


# Installing libraries

RUN apt-get update && apt-get install -y --no-install-recommends \
python-setuptools \
python-pip \
RUN apt-get update && apt-get install -yq --fix-missing --no-install-recommends \
libmysqlclient-dev \
mysql-client \
python3-setuptools \
python3-pip \
git-core \
netcat \
nodejs-legacy \
npm \
gettext \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

RUN npm install -g bower
# Installing libraries

RUN npm install -g bower

# Install pip dependencies
RUN pip3 install --upgrade pip setuptools virtualenv

COPY .bowerrc bower.json /
RUN bower install

COPY requirements.txt /
RUN pip3 install -r requirements.txt

RUN pip install --upgrade pip setuptools virtualenv
COPY ./ /radioco/

COPY requirements.txt requirements.txt
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
WORKDIR /radioco/
129 changes: 129 additions & 0 deletions docker/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;

# Hide nginx version information.
server_tokens off;

# Compression
gunzip on;
gzip on;
gzip_comp_level 2;
gzip_proxied any;
gzip_types
image/svg+xml
image/x-icon
text/x-component
text/css
text/javascript
text/xml
text/plain
application/javascript
application/x-javascript
application/json
application/atom+xml
application/rss+xml
application/xhtml+xml;

uwsgi_cache_path /tmp/cache1 levels=1:2 keys_zone=web:1m max_size=1g inactive=8h use_temp_path=off;
uwsgi_cache_path /tmp/cache2 levels=1:2 keys_zone=api:10m max_size=1g inactive=24h use_temp_path=off;

upstream django {
server django:8000;
}
server {
listen 8000;
charset utf-8;

include /etc/nginx/uwsgi_params;

uwsgi_param Host $host;
uwsgi_param X-Real-IP $remote_addr;
uwsgi_param X-Forwarded-For $proxy_add_x_forwarded_for;
uwsgi_param X-Forwarded-Proto $http_x_forwarded_proto;

# server cache
uwsgi_cache_key "$scheme$host$uri$is_args$args";
uwsgi_cache_methods GET HEAD;

# cache debug info
#add_header X-uWSGI-Cache $upstream_cache_status;
#add_header X-uWSGI-Cache-Key "$scheme$host$uri$is_args$args";

location /static/ {
alias /static/;
expires 1d;
log_not_found off;
access_log off;
}

location /media/ {
alias /media/;
expires 1d;
log_not_found off;
access_log off;
}

location /admin/ {
# disable any cache
expires 0;
uwsgi_no_cache 1;
uwsgi_pass django;
}

location / {
# client cache
expires 10m;

# server cache
uwsgi_cache web;
uwsgi_cache_valid 200 5m;

uwsgi_pass django;
}

location ~ /rss/$ {
# client cache
expires 1h;

# server cache
uwsgi_cache web;
uwsgi_cache_valid 200 45m;

uwsgi_pass django;
}

location /api/ {
# disable client cache
expires 0;

# server cache except for authenticated users (calendar manager)
uwsgi_cache api;
uwsgi_cache_valid 200 30m;
uwsgi_no_cache $cookie_sessionid;

uwsgi_pass django;
}

location ~ ^/api/2/(radiocom/)?transmissions/now {
# same as before but cache for a shorter period
expires 0;

uwsgi_cache api;
uwsgi_cache_valid 200 1m;

uwsgi_pass django;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}
8 changes: 8 additions & 0 deletions docker/scripts/launch_dev_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash -x

script_full_path=$(dirname "$0")
$script_full_path/wait_for.sh postgres 5432

mv -f /tmp_bower /radioco/radioco/apps/radioco/static/bower
python3 manage.py migrate
python3 manage.py runserver 0.0.0.0:8000
9 changes: 8 additions & 1 deletion docker/scripts/launch_server.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
#!/bin/bash -x
${MANAGE_PY} runserver 0.0.0.0:8000

script_full_path=$(dirname "$0")
$script_full_path/wait_for.sh postgres 5432

mv -f /tmp_bower /radioco/radioco/apps/radioco/static/bower
python3 manage.py migrate
python3 manage.py collectstatic --noinput
uwsgi --socket 0.0.0.0:8000 --module radioco.configs.base.wsgi --master --processes 2 --threads 1
Loading

0 comments on commit 0e37809

Please sign in to comment.