Rewriting README, simplifying setup.

This commit is contained in:
Julien Palard 2020-05-31 16:36:25 +02:00
parent a539d9096f
commit 1ea84d6652
10 changed files with 50 additions and 208 deletions

1
.gitignore vendored
View File

@ -17,3 +17,4 @@ media
# End of https://www.gitignore.io/api/django
/static/
/var/
.venv/

186
README.md
View File

@ -1,16 +1,17 @@
Pasteque
========
# Pasteque
About
-----
**Pasteque** is a free and open source (MIT License) **Pastebin like** application written in Python/Django.
## About
Demo
----
A **demo** instance of **Pasteque** is running at [http://paste.henriet.eu](http://paste.henriet.eu).
**Pasteque** is a free and open source (MIT License) **Pastebin like**
application written in Python/Django.
An instance can be found at: [wyz.fr](https://wyz.fr). The wyz.fr
instance is installed by ansible, the role is available here:
https://github.com/JulienPalard/playbooks/tree/master/roles/pasteque.
## Features
Features
--------
- Support any database supported by Django (Sqlite3, MySQL, PostgreSQL, Oracle, ...)
- Available in english, french .. and easily translatable into another languages.
- Syntax highlighting for a bunch of languages using Pygments.
@ -21,165 +22,32 @@ Features
- Limit pastes size.
- Pastes history.
Upcoming releases features
--------------------------
- Duplicate paste
- Locale selector
- Search engine
- Disable pastes via link submitted by email
- Copy to clipboard JS
- Google Analytics easy-integration
Deployment with Sqlite3, nginx and UWSGI
----------------------------------------
## Running Pasteque
This procedure will guide you step-by-step through the setup of your own instance of **Pasteque** using
nginx et UWSGI. In this tutorial, app files and servers processes are owned by unprivilegied **web** user.
In a [venv](https://docs.python.org/3/library/venv.html), install the requirements:
### Pre-required system packages
pip install -r requirements.txt
It is assumed that some system packages are installed on the server where you plan to setup **Pasteque**.
In `settings.py` edit:
**On Debian**
<pre>
sudo apt-get install python python-pip python-dev nginx git
</pre>
DISPLAY_NAME = 'YourCompany-Paste'
COMPRESS_ENABLED = True
SECRET_KEY = 'fill_a_secret_key_here'
ALLOWED_HOSTS = ['localhost','127.0.0.1','paste.henriet.eu']
### Application deployment
Then create the database:
The application is deployed into **/opt/app/webtools** which is owner by user **web**.
./manage.py migrate
<pre>
sudo mkdir -p /opt/app/webtools/
sudo chown -R web: /opt/app/webtools/
cd /opt/app/webtools/
git clone https://github.com/setsuna-/pasteque .
mkdir -p var/logs var/db var/pygments-static
</pre>
Insert initial data (like known languages):
### Install required python packages
./manage.py loaddata initial
Even if python packages are installed system-wide in this tutorial, **virtualenv** is of course the way to go.
If you're in production collect static files:
<pre>
sudo -s
export CFLAGS="-march=native -O2 -fomit-frame-pointer -pipe" && export CXXFLAGS="-march=native -O2 -fomit-frame-pointer -pipe"
pip install -r /opt/app/webtools/share/requirements.pip
</pre>
./manage.py collectstatic
### Pasteque configuration and customization
Run it:
<pre>
vim /opt/app/webtools/webtools/settings.py
DISPLAY_NAME = 'YourCompany-Paste'
COMPRESS_ENABLED = True
SECRET_KEY = 'fill_a_secret_key_here'
ALLOWED_HOSTS = ['localhost','127.0.0.1','paste.henriet.eu']
</pre>
### Sqlite3 database creation
<pre>
cd /opt/app/webtools/
./manage.py syncdb
Creating tables ...
Creating table paste_language
Creating table paste_paste
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
sqlite3 var/db/webtools.sqlite3
sqlite> .read share/language-dml.sql
sqlite> .quit
</pre>
### Deploy static assets
<pre>
./manage.py collectstatic
ls static/
css font img js
</pre>
### Test application
Validate application setup using the development web server.
<pre>
./manage.py runserver paste.henriet.eu:16000
</pre>
### Configure UWSGI
<pre>
cp /opt/app/webtools/share/uwsgi.ini /opt/app/webtools/uwsgi.ini
vim /opt/app/webtools/uwsgi.ini
[uwsgi]
chdir=/opt/app/webtools
module=webtools.wsgi:application
master=True
env=DJANGO_SETTINGS_MODULE=webtools.settings
pidfile=/opt/app/webtools/var/uwsgid-pasteque.pid
socket=/opt/app/webtools/var/uwsgid-pasteque.sock
processes=5
uid=1002
gid=1002
harakiri=20
limit-as=128
max-requests=5000
vacuum=True
daemonize=/opt/app/webtools/var/uwsgid-pasteque.log
</pre>
### Run UWSGI
<pre>
uwsgi --ini /opt/app/webtools/uwsgi.ini
[uWSGI] getting INI configuration from /opt/app/webtools/uwsgi.ini
ps -ef |grep uwsgi
web 2269 1 0 11:32 ? 00:00:00 uwsgi --ini /opt/app/webtools/uwsgi.ini
web 2271 2269 0 11:32 ? 00:00:00 uwsgi --ini /opt/app/webtools/uwsgi.ini
web 2272 2269 0 11:32 ? 00:00:00 uwsgi --ini /opt/app/webtools/uwsgi.ini
web 2273 2269 0 11:32 ? 00:00:00 uwsgi --ini /opt/app/webtools/uwsgi.ini
web 2274 2269 0 11:32 ? 00:00:00 uwsgi --ini /opt/app/webtools/uwsgi.ini
web 2275 2269 0 11:32 ? 00:00:00 uwsgi --ini /opt/app/webtools/uwsgi.ini
cat /opt/app/webtools/var/uwsgid-pasteque.log to check if everything is ok.
</pre>
### Configure NGINX
<pre>
sudo vim /etc/nginx/nginx.conf
user web;
sudo vim /etc/nginx/sites-available/webtools-pasteque
upstream uwsgi {
server unix:///opt/app/webtools/var/uwsgid-pasteque.sock;
}
server {
listen 80;
server_name paste.henriet.eu;
charset utf-8;
error_log /opt/app/webtools/var/nginx-error.log;
access_log /opt/app/webtools/var/nginx-access.log;
client_max_body_size 8M;
location /static {
alias /opt/app/webtools/static;
expires 30d;
}
location / {
uwsgi_pass uwsgi;
include /etc/nginx/uwsgi_params;
}
}
cd /etc/nginx/sites-enabled/
sudo ln -s ../sites-available/webtools-pasteque
</pre>
### Run nginx
<pre>
sudo /etc/init.d/nginx restart
Restarting nginx: nginx.
</pre>
./manage.py runserver

View File

@ -1,9 +0,0 @@
#!/usr/bin/env bash
# Clean the database instead of erasing it
# sqlite3 var/db/webtools.sqlite3 "delete from paste_paste;"
[ -f var/db/webtools.sqlite3 ] && rm var/db/webtools.sqlite3
rm -rf var/cache/*
rm -rf var/logs/*
rm -rf static/*
find . -name "*.pyc" -exec rm {} +;

View File

@ -0,0 +1 @@
[{"model": "paste.language", "pk": 1, "fields": {"name": "Bash (shell)", "slug": "bash"}}, {"model": "paste.language", "pk": 2, "fields": {"name": "C#", "slug": "csharp"}}, {"model": "paste.language", "pk": 3, "fields": {"name": "C", "slug": "c"}}, {"model": "paste.language", "pk": 4, "fields": {"name": "C++", "slug": "cpp"}}, {"model": "paste.language", "pk": 5, "fields": {"name": "CSS", "slug": "css"}}, {"model": "paste.language", "pk": 6, "fields": {"name": "Diff", "slug": "diff"}}, {"model": "paste.language", "pk": 7, "fields": {"name": "Go", "slug": "go"}}, {"model": "paste.language", "pk": 8, "fields": {"name": "HTML", "slug": "html"}}, {"model": "paste.language", "pk": 9, "fields": {"name": "Java", "slug": "java"}}, {"model": "paste.language", "pk": 10, "fields": {"name": "Javascript", "slug": "javascript"}}, {"model": "paste.language", "pk": 11, "fields": {"name": "Perl", "slug": "perl"}}, {"model": "paste.language", "pk": 12, "fields": {"name": "PHP", "slug": "php"}}, {"model": "paste.language", "pk": 13, "fields": {"name": "Plain text", "slug": "text"}}, {"model": "paste.language", "pk": 14, "fields": {"name": "Python", "slug": "python"}}, {"model": "paste.language", "pk": 15, "fields": {"name": "Ruby", "slug": "ruby"}}, {"model": "paste.language", "pk": 16, "fields": {"name": "SQL", "slug": "sql"}}, {"model": "paste.language", "pk": 17, "fields": {"name": "XML", "slug": "xml"}}, {"model": "paste.language", "pk": 18, "fields": {"name": "YAML", "slug": "yaml"}}]

4
requirements.in Normal file
View File

@ -0,0 +1,4 @@
Django
Pygments
shortuuid
django_compressor

17
requirements.txt Normal file
View File

@ -0,0 +1,17 @@
#
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile requirements.in
#
asgiref==3.2.7 # via django
django-appconf==1.0.4 # via django-compressor
django-compressor==2.4 # via -r requirements.in
django==3.0.6 # via -r requirements.in, django-appconf
pygments==2.6.1 # via -r requirements.in
pytz==2020.1 # via django
rcssmin==1.0.6 # via django-compressor
rjsmin==1.1.0 # via django-compressor
shortuuid==1.0.1 # via -r requirements.in
six==1.15.0 # via django-compressor
sqlparse==0.3.1 # via django

View File

@ -1,18 +0,0 @@
INSERT INTO paste_language (name, slug) VALUES ('Bash (shell)', 'bash');
INSERT INTO paste_language (name, slug) VALUES ('C#','csharp');
INSERT INTO paste_language (name, slug) VALUES ('C','c');
INSERT INTO paste_language (name, slug) VALUES ('C++','cpp');
INSERT INTO paste_language (name, slug) VALUES ('CSS','css');
INSERT INTO paste_language (name, slug) VALUES ('Diff','diff');
INSERT INTO paste_language (name, slug) VALUES ('Go','go');
INSERT INTO paste_language (name, slug) VALUES ('HTML','html');
INSERT INTO paste_language (name, slug) VALUES ('Java','java');
INSERT INTO paste_language (name, slug) VALUES ('Javascript','javascript');
INSERT INTO paste_language (name, slug) VALUES ('Perl','perl');
INSERT INTO paste_language (name, slug) VALUES ('PHP','php');
INSERT INTO paste_language (name, slug) VALUES ('Plain text','text');
INSERT INTO paste_language (name, slug) VALUES ('Python','python');
INSERT INTO paste_language (name, slug) VALUES ('Ruby','ruby');
INSERT INTO paste_language (name, slug) VALUES ('SQL','sql');
INSERT INTO paste_language (name, slug) VALUES ('XML','xml');
INSERT INTO paste_language (name, slug) VALUES ('YAML','yaml');

View File

@ -1,6 +0,0 @@
Django==2.0.5
uWSGI==2.0.17
Pygments==2.2.0
shortuuid==0.5.0
django_compressor==2.2
beautifulsoup4==4.6.0

View File

@ -1,15 +0,0 @@
[uwsgi]
chdir=/opt/app/webtools
module=webtools.wsgi:application
master=True
env=DJANGO_SETTINGS_MODULE=webtools.settings
pidfile=/opt/app/webtools/var/uwsgid-pasteque.pid
socket=/opt/app/webtools/var/uwsgid-pasteque.sock
processes=5
uid=1000
gid=1000
harakiri=20
limit-as=128
max-requests=5000
vacuum=True
daemonize=/opt/app/webtools/var/uwsgid-pasteque.log

View File

@ -1 +0,0 @@
uwsgi --chdir=/home/alex/coding/django/webtools --module=webtools.wsgi:application --env DJANGO_SETTINGS_MODULE=webtools.settings --master --pidfile=/tmp/uwsgid-pasteque.pid --socket=/tmp/uwsgid-pasteque.sock --processes=5 --uid=1000 --gid=1000 --harakiri=20 --limit-as=128 --max-requests=5000 --vacuum --daemonize=/tmp/uwsgid-pasteque.log