├── .gitignore ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── README.rst ├── commands ├── base ├── check ├── gcat ├── install_redis ├── makemigrations ├── restart ├── shell ├── superuser └── userssh ├── config.txt ├── deploy.sh ├── docs ├── Makefile ├── changes.rst ├── commands.rst ├── contributing.rst ├── index.rst └── installation.rst ├── status.txt └── tlp ├── bitbucket-pipelines.yml ├── default ├── gunicorn.service ├── pipeline.sh └── redis.service /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | .idea/ 3 | __pycache__/ 4 | .deploy.sh.swp 5 | *.py[cod] 6 | *$py.class 7 | 8 | # C extensions 9 | *.so 10 | 11 | # Distribution / packaging 12 | .Python 13 | env/ 14 | build/ 15 | develop-eggs/ 16 | dist/ 17 | downloads/ 18 | eggs/ 19 | .eggs/ 20 | lib/ 21 | lib64/ 22 | parts/ 23 | sdist/ 24 | var/ 25 | wheels/ 26 | *.egg-info/ 27 | .installed.cfg 28 | *.egg 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | .hypothesis/ 50 | 51 | # Translations 52 | *.mo 53 | *.pot 54 | 55 | # Django stuff: 56 | *.log 57 | local_settings.py 58 | 59 | # Flask stuff: 60 | instance/ 61 | .webassets-cache 62 | 63 | # Scrapy stuff: 64 | .scrapy 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # celery beat schedule file 79 | celerybeat-schedule 80 | 81 | # SageMath parsed files 82 | *.sage.py 83 | 84 | # dotenv 85 | .env 86 | 87 | # virtualenv 88 | .venv 89 | venv/ 90 | ENV/ 91 | 92 | # Spyder project settings 93 | .spyderproject 94 | .spyproject 95 | 96 | # Rope project settings 97 | .ropeproject 98 | 99 | # mkdocs documentation 100 | /site 101 | 102 | # mypy 103 | .mypy_cache/ 104 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at munisisazade@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Munis Isazade 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # README # 2 | 3 | # Django deployment Tool # 4 | 5 | [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/hyperium/hyper/master/LICENSE) 6 | [![Documentation Status](https://readthedocs.org/projects/django-deployment-tool/badge/?version=latest)](http://django-deployment-tool.readthedocs.io/en/latest/?badge=latest) 7 | [![Python Django](https://img.shields.io/badge/python-django-blue.svg)](http://django-deployment-tool.readthedocs.io/en/latest/?badge=latest) 8 | [![Devloper Munis](https://img.shields.io/badge/developer-Munis-brightgreen.svg)](http://django-deployment-tool.readthedocs.io/en/latest/?badge=latest) 9 | [![GitHub issues](https://img.shields.io/github/issues/munisisazade/django_deployment_tool.svg)](https://github.com/munisisazade/django_deployment_tool/issues) 10 | [![GitHub forks](https://img.shields.io/github/forks/munisisazade/django_deployment_tool.svg)](https://github.com/munisisazade/django_deployment_tool/network) 11 | [![GitHub stars](https://img.shields.io/github/stars/munisisazade/django_deployment_tool.svg)](https://github.com/munisisazade/django_deployment_tool/stargazers) 12 | [![Twitter](https://img.shields.io/twitter/url/https/github.com/munisisazade/django_deployment_tool.svg?style=social)](https://twitter.com/intent/tweet?text=Wow:&url=https://github.com/munisisazade/django_deployment_tool) 13 | 14 | ### --- How to install and use for Ubuntu 16.04 ### 15 | 16 | First you need to install python3 and after install django you can run the project following bellow steps 17 | if you have a python3 follow this step 18 | ``` 19 | $ git clone https://github.com/munisisazade/django_deployment_tool.git 20 | $ cd django_deployment_tool 21 | $ chmod +x deploy.sh 22 | $ ./deploy.sh usage 23 | $ ./deploy.sh deploy 24 | $ ./deploy.sh status 25 | ``` 26 | # And Read full [Documentation](http://django-deployment-tool.readthedocs.io/en/latest/) # 27 | # 28 | [![Deployment Tool Django](http://img.youtube.com/vi/hlGdZ9ML7NI/0.jpg)](http://www.youtube.com/watch?v=hlGdZ9ML7NI "Django Deployment Tool testing") 29 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | # README # 2 | 3 | # Django deployment Tool # 4 | 5 | [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/hyperium/hyper/master/LICENSE) 6 | ### --- How to install and use for Ubuntu 16.04 ### 7 | 8 | First you need to install python3 and after install django you can run the project following bellow steps 9 | if you have a python3 follow this step 10 | ``` 11 | $ git clone https://github.com/munisisazade/django_deployment_tool.git 12 | $ cd django_deployment_tool 13 | $ chmod +x deploy.sh 14 | $ ./deploy.sh usage 15 | $ ./deploy.sh deploy 16 | $ ./deploy.sh status 17 | ``` -------------------------------------------------------------------------------- /commands/base: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | APP_USER_LINUX=#{APP_USER_LINUX} 4 | bold=$(tput bold) 5 | normal=$(tput sgr0) 6 | 7 | sudo su - $APP_USER_LINUX << \EOF 8 | CONF_ROOT=/var/local 9 | source $CONF_ROOT/config.txt 10 | source $CONF_ROOT/status.txt 11 | if [ $REPO_CLONE ]; then 12 | echo "Repository check ...." 13 | sleep 3 14 | echo "\e[32mAlready have $GIT_REPO_URL ............... [OK]\e[0m" 15 | else 16 | echo -e "Clonig git repository from this url: $GIT_REPO_URL" 17 | cd /home/$APP_USER 18 | git clone $GIT_REPO_URL 19 | echo "REPO_CLONE=True" >> $CONF_ROOT/status.txt 20 | fi 21 | cd $GIT_ROOT 22 | if [ $ROOT_DIRECTOR ]; then 23 | echo "Check project root directory" 24 | else 25 | APP_ROOT_DIRECTOR=$(pwd) 26 | echo "APP_ROOT_DIRECTOR=$APP_ROOT_DIRECTOR" >> "$CONF_ROOT/config.txt" 27 | echo "ROOT_DIRECTOR=True" >> $CONF_ROOT/status.txt 28 | fi 29 | cd $APP_ROOT_DIRECTOR 30 | if [ ! -f "manage.py" ]; then 31 | echo -e "\e[31mERROR : manage.py file doest exist the system\e[0m" 32 | echo -e "\e[34mPlease make sure your django application modern root directory look like:" 33 | echo -e "|-- base_app_name" 34 | echo -e "| |-- __init__.py" 35 | echo -e "| |-- settings.py" 36 | echo -e "| |-- urls.py" 37 | echo -e "| +-- wsgi.py" 38 | echo -e "|-- app_name" 39 | echo -e "| |-- admin.py" 40 | echo -e "| |-- apps.py" 41 | echo -e "| |-- __init__.py" 42 | echo -e "| |-- models.py" 43 | echo -e "| |-- views.py" 44 | echo -e "| +-- tests.py" 45 | echo -e "|-- ${bold}manage.py${normal}" 46 | echo -e "|-- ${bold}requirements.txt${normal}\e[0m" 47 | touch /home/$APP_USER/error.log 48 | echo "ERROR : manage.py file doest exist the system" >> /home/$APP_USER/error.log 49 | exit 123 50 | else 51 | sudo rm -rf /home/$APP_USER/error.log 52 | fi 53 | if [ ! -f "requirements.txt" ]; then 54 | echo -e "\e[31mERROR : requirements.txt file doest exist the system\e[0m" 55 | echo -e "\e[34mPlease make sure your django application have requirements.txt if not:" 56 | echo -e "Add application requirements files your project" 57 | echo -e "pip install gunicorn" 58 | echo -e "pip freeze > ${bold}requirements.txt${normal}" 59 | touch /home/$APP_USER/error.log 60 | echo "ERROR : requirements.txt file doest exist the system" >> /home/$APP_USER/error.log 61 | exit 123 62 | else 63 | rm -rf /home/$APP_USER/error.log 64 | fi 65 | echo -e "Create Virtualenviroment" 66 | python3 -m venv .venv 67 | echo -e "Activate virtualenviroment" 68 | source .venv/bin/activate 69 | pip install -r requirements.txt 70 | pip install -U pip 71 | python manage.py check 72 | python manage.py makemigrations 73 | python manage.py migrate 74 | echo -e "Configuration Nginx credentials.." 75 | sed -i -e 's|#{APP_SERVER}|'$APP_SERVER'|g' -e 's|#{APP_ROOT_DIRECTOR}|'$APP_ROOT_DIRECTOR'|g' -e 's|#{APP_NAME}|'$APP_NAME'|g' $CONF_ROOT/tlp/default 76 | echo -e "Create nginx default server.." 77 | sudo cp -r $CONF_ROOT/tlp/default /etc/nginx/sites-available/default 78 | echo -e "Gunicorn file created.." 79 | sed -i -e 's|#{APP_USER}|'$APP_USER'|g' -e 's|#{APP_ROOT_DIRECTOR}|'$APP_ROOT_DIRECTOR'|g' -e 's|#{APP_NAME}|'$APP_NAME'|g' $CONF_ROOT/tlp/gunicorn.service 80 | sudo cp -r $CONF_ROOT/tlp/gunicorn.service /etc/systemd/system/ 81 | echo -e "Everything works cool :)" 82 | sudo cp -r $CONF_ROOT/commands/restart /bin/ 83 | sudo chmod +x /bin/restart 84 | sudo cp -r $CONF_ROOT/commands/makemigrations /bin/ 85 | sudo chmod +x /bin/makemigrations 86 | sudo cp -r $CONF_ROOT/commands/shell /bin/ 87 | sudo chmod +x /bin/shell 88 | sudo cp -r $CONF_ROOT/commands/check /bin/ 89 | sudo chmod +x /bin/check 90 | sudo cp -r $CONF_ROOT/commands/install_redis /bin/ 91 | sudo chmod +x /bin/install_redis 92 | sudo systemctl start nginx 93 | sudo systemctl start gunicorn 94 | restart 95 | EOF -------------------------------------------------------------------------------- /commands/check: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Starting check django application ......" 4 | source .venv/bin/activate 5 | if ./manage.py check; then 6 | echo "If nothing happen everything was good :)" 7 | echo "Keep it rock, Happy Coding!" 8 | else 9 | echo "Some error ocurred don't be blame :(" 10 | echo "Try to solve this error, else program not working correctly :/" 11 | fi 12 | deactivate -------------------------------------------------------------------------------- /commands/gcat: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | fileType="$(file "$1" | grep -o 'text')" 4 | if [ "$fileType" == 'text' ]; then 5 | echo -en "\033[0;32m" 6 | else 7 | echo -en "\033[0;32m" 8 | fi 9 | cat $1 10 | echo -en "\033[0m" -------------------------------------------------------------------------------- /commands/install_redis: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo -e "Installing redis-server for Ubuntu 16.04" 4 | cd ~/ 5 | whoami 6 | echo -e "Download, Compile, and Install Redis" 7 | echo -e "Download and Extract the Source Code" 8 | cd /tmp 9 | echo -e "Now, download the latest stable version of Redis. This is always available at a stable" 10 | curl -O http://download.redis.io/redis-stable.tar.gz 11 | echo -e "Unpack the tarball" 12 | tar xzvf redis-stable.tar.gz 13 | echo -e "Move into the Redis source directory structure that was just extracted" 14 | cd redis-stable 15 | echo -e "Build and Install Redis" 16 | make 17 | echo -e "After the binaries are compiled, run the test suite to make sure everything was built correctly. You can do make test" 18 | make test 19 | echo -e "This will typically take a few minutes to run. Once it is complete, you can install the binaries onto the system by typing make install" 20 | echo -e "/n" 21 | echo -e "Configure Redis" 22 | cd ~/ 23 | sudo mkdir /etc/redis 24 | echo -e "Now, copy over the sample Redis configuration file included in the Redis source archive" 25 | sudo cp /tmp/redis-stable/redis.conf /etc/redis 26 | 27 | sudo sed -i -e 's|supervised no|supervised systemd|g' -e 's|dir ./|dir /var/lib/redis|g' /etc/redis/redis.conf 28 | sudo cp -r /var/local/redis.service /etc/systemd/system/ 29 | echo -e "Create redis user" 30 | sudo adduser --system --group --no-create-home redis 31 | echo -e "Now, we can create the /var/lib/redis directory" 32 | sudo mkdir /var/lib/redis 33 | echo -e "We should give the redis user and group ownership over this directory" 34 | sudo chown redis:redis /var/lib/redis 35 | echo -e "Adjust the permissions so that regular users cannot access this location" 36 | sudo chmod 770 /var/lib/redis 37 | sudo systemctl start redis 38 | echo -e "Check status" 39 | sudo systemctl status redis 40 | 41 | -------------------------------------------------------------------------------- /commands/makemigrations: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo -e "Connecting to virtualenv ........" 4 | source .venv/bin/activate 5 | echo -e "Create migrations if we have migration" 6 | python manage.py makemigrations 7 | echo -e "Then we must do migrate them ...." 8 | python manage.py migrate 9 | echo -e "If status code [OK] everything is ok :)" 10 | deactivate 11 | echo -e "Thanks for using my tool :)" 12 | 13 | -------------------------------------------------------------------------------- /commands/restart: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo -e "Git pull update project and Restart Nginx and Gunicorn" 4 | git pull 5 | sudo systemctl restart nginx 6 | echo "Restarting nginx: [OK]" 7 | sudo systemctl restart gunicorn 8 | echo "Restarting Gunicorn: [OK]" 9 | echo "Everything is OK :)" 10 | -------------------------------------------------------------------------------- /commands/shell: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo -e "Starting Django shell" 4 | echo -e "Python and Django developer" 5 | echo -e "swich virtual enviroment" 6 | source .venv/bin/activate 7 | ./manage.py shell 8 | deactivate 9 | -------------------------------------------------------------------------------- /commands/superuser: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo -e "Create Django Superuser" 4 | source .venv/bin/activate 5 | 6 | python manage.py createsuperuser -------------------------------------------------------------------------------- /commands/userssh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | APP_USER_LINUX=#{APP_USER_LINUX} 4 | 5 | sudo su - $APP_USER_LINUX << EOF 6 | ssh-keygen -b 2048 -t rsa -f ~/.ssh/id_rsa -q -N "" 7 | gcat ~/.ssh/id_rsa.pub 8 | EOF -------------------------------------------------------------------------------- /config.txt: -------------------------------------------------------------------------------- 1 | # This file generated by Atomaticly please don't write here anything 2 | # Created by Munis Isazade Django developer 3 | -------------------------------------------------------------------------------- /deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Author Munis Isazade Django developer 3 | VERSION="1.5" 4 | ERROR_STATUS=0 5 | CONF_ROOT=/root/django_deployment_tool 6 | POSTGRESQL_USER=postgres 7 | # POSTGRESQL_CLUSTER_VERSION="$(sudo pg_lsclusters | egrep -o '[0-9]{1,}\.[0-9]{1,}' | (read a; echo $a;))" # $(pg_config --version | egrep -o '[0-9]{1,}\.[0-9]{1,}') 8 | POSTGRESQL_UPGRADE_TO=9.5 9 | 10 | 11 | 12 | function usage { 13 | echo -e "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n" 14 | echo -e "\t Django Deployment Tool v$VERSION" 15 | echo -e "\t Munis Isazade - munisisazade@gmail.com" 16 | echo -e "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n" 17 | echo -e "Usage: bash $0 " 18 | echo -e "\nCommands:" 19 | 20 | echo -e "\t usage \t\t\t\t - For helping available commands to use" 21 | echo -e "\t deploy \t\t\t\t - Base command to deployment" 22 | echo -e "\t status \t\t\t\t - Show status of deployment" 23 | echo -e "\t delete \t\t\t - Delete DB" 24 | echo -e "\t create \t\t\t - Create DB" 25 | echo -e "\t upgrade \t\t\t - Upgrade cluster version of PostgreSQL to $POSTGRESQL_UPGRADE_TO" 26 | echo -e "\t dump \t\t\t - Dump DB to given folder" 27 | echo -e "\t restore \t\t\t - Restore DB from given SQL file" 28 | 29 | exit 1 30 | } 31 | 32 | function deployment_status() { 33 | . $CONF_ROOT/config.txt 34 | if [[ $APP_USER && $DEPLOYMENT_STATUS ]]; then 35 | echo -e "Current deploy status:" 36 | echo -e "\n" 37 | echo -e "\nDjango\t\t\t\t\tAlready Deploy" 38 | echo -e "\n" 39 | echo -e "The Application is ready to use please use" 40 | echo -e "Change the user by command sudo su - $APP_USER" 41 | else 42 | echo -e "Current deploy status:" 43 | echo -e "\n" 44 | echo -e "Django\t\t\t\t\tnot deploy" 45 | echo -e "\n" 46 | echo -e "The Application is not Deploy please use ./deploy.sh deploy" 47 | fi 48 | 49 | 50 | } 51 | 52 | 53 | function get_user_credential { 54 | . $CONF_ROOT/status.txt 55 | . $CONF_ROOT/config.txt 56 | if [ $INSTALLATION_STEP ]; then 57 | echo -e "Check the installation step .........." 58 | sleep 3 59 | echo -e "\e[32mInstallation step ....................... [OK]\e[0m" 60 | else 61 | clear 62 | echo "************************************************************************" 63 | echo "!!!!!!!!!!!!!!!!!!!! Start Installing as `whoami`... !!!!!!!!!!!!!!!!!!!" 64 | echo "************************************************************************" 65 | echo "" 66 | echo -e "Ubuntu Update apt package ...." 67 | chmod +x config.txt 68 | chmod +x status.txt 69 | echo -e "Installing python2 pip and depencies ..." 70 | apt-get -y update 71 | apt-get -y install python-pip python-dev libpq-dev postgresql postgresql-contrib nginx gettext 72 | apt-get -y update 73 | echo -e "Installing python3 pip and depencies ..." 74 | apt-get -y install python3-pip python3-dev libpq-dev postgresql postgresql-contrib nginx 75 | apt-get -y install python3-venv 76 | echo -e "Installing Pillow for $(uname -a)" 77 | apt-get -y install libtiff5-dev libjpeg8-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python-tk 78 | apt-get -y install libtiff4-dev libjpeg8-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.5-dev tk8.5-dev python-tk 79 | echo "INSTALLATION_STEP=True" >> "$CONF_ROOT/status.txt" 80 | fi 81 | if [ $CREATE_LINUX_USER_STEP ]; then 82 | echo -e "Check Linux user ............" 83 | sleep 3 84 | echo -e "\e[32mLinux User step ......................... [OK]\e[0m" 85 | else 86 | echo -e "Creating new User for $(uname -a)" 87 | echo "APP_SERVER=$(curl -4 https://icanhazip.com/)" >> "$CONF_ROOT/config.txt" 88 | echo -e "Please write New Linux User name and password" 89 | read -p "Please enter your linux username: " APP_USER 90 | while true ; do 91 | if [ $APP_USER ]; then 92 | break 93 | fi 94 | read -p "Please enter your linux username: " APP_USER 95 | done 96 | echo "APP_USER=$APP_USER" >> "$CONF_ROOT/config.txt" 97 | echo -e "Please enter your linux user password: " 98 | echo -n "Password :" 99 | read -s APP_USER_PASSWORD 100 | while true ; do 101 | if [ $APP_USER_PASSWORD ]; then 102 | break 103 | fi 104 | echo -n "Password :" 105 | read -s APP_USER_PASSWORD 106 | done 107 | echo "APP_USER_PASSWORD=$APP_USER_PASSWORD" >> "$CONF_ROOT/config.txt" 108 | echo "CREATE_LINUX_USER_STEP=True" >> "$CONF_ROOT/status.txt" 109 | fi 110 | } 111 | 112 | 113 | function fix_perl_locale_error() { 114 | echo -e "Fixing perl warning: Setting locale error..." 115 | export LANGUAGE=en_US.UTF-8 116 | export LC_ALL=en_US.UTF-8 117 | export LANG=en_US.UTF-8 118 | export LC_TYPE=en_US.UTF-8 119 | uname -a 120 | perl -e exit 121 | } 122 | 123 | function create_new_linux_user { 124 | . $CONF_ROOT/config.txt 125 | if [ $ALREADY_CREATE_USER ] ; then 126 | echo -e "Already You was created New user with Bellow credential" 127 | echo -e "\t Username : \t - $APP_USER" 128 | echo -e "\t Password : \t - $APP_USER_PASSWORD" 129 | echo -e "\t Created time \t - $(date)" 130 | else 131 | echo -e "Creating New Linux User please wait .." 132 | pass=$(perl -e 'print crypt($ARGV[0], "password")' $APP_USER_PASSWORD) 133 | useradd -m -p $pass $APP_USER 134 | echo -e "Users created and add to sudoers" 135 | echo "$APP_USER ALL=(ALL:ALL) ALL" >> /etc/sudoers 136 | echo -e "Successfuly Created user with Bellow credential" 137 | echo -e "\t Username : \t - $APP_USER" 138 | echo -e "\t Password : \t - $APP_USER_PASSWORD" 139 | echo -e "\t Created time \t - $(date)" 140 | echo "ALREADY_CREATE_USER=True" >> $CONF_ROOT/config.txt 141 | fi 142 | 143 | } 144 | 145 | function get_project_details { 146 | . $CONF_ROOT/config.txt 147 | . $CONF_ROOT/status.txt 148 | if [ $INSTALLATION_GIT_PROJECT ]; then 149 | echo "Check Git project installtion step ........." 150 | sleep 3 151 | echo -e "\e[32mGit configuration ....................... [OK]\e[0m" 152 | else 153 | echo -e "Please Write your projects detailed...." 154 | apt-get -y update 155 | echo -e "Please write your git repository url here" 156 | read -p "Git Repo : " GIT_REPO_URL 157 | while true ; do 158 | if [ $GIT_REPO_URL ]; then 159 | break 160 | fi 161 | read -p "Please enter Repo Url : " GIT_REPO_URL 162 | done 163 | echo "GIT_REPO_URL=$GIT_REPO_URL" >> "$CONF_ROOT/config.txt" 164 | if [[ $GIT_REPO_URL == *git@* ]]; then 165 | GIT_ROOT=$(echo $GIT_REPO_URL | cut -d'/' -f 2 | cut -d'.' -f 1) 166 | echo "GIT_ROOT=$GIT_ROOT" >> "$CONF_ROOT/config.txt" 167 | echo -e "Using the SSH protocol, you can connect and authenticate to remote servers and services. With SSH keys, you can connect to GitHub without supplying your username or password at each visit." 168 | echo -e "Generating a new SSH key and adding it to the ssh-agent" 169 | cp -r $CONF_ROOT/commands/gcat /bin/ 170 | chmod +x /bin/gcat 171 | sed -i -e 's|#{APP_USER_LINUX}|'$APP_USER'|g' $CONF_ROOT/commands/userssh 172 | cp -r $CONF_ROOT/commands/userssh /bin/ 173 | chmod +x /bin/userssh 174 | echo -e "Plase write this ssh-keygen register your Github or Bitbucket account " 175 | userssh 176 | read -p "If you did please confirm to continued(yes/no)?" confirm 177 | while true ; do 178 | if [ "$confirm"==yes ]; then 179 | break 180 | fi 181 | echo -e "Ssh key is bellow:" 182 | gcat ~/home/$APP_USER/.ssh/id_rsa.pub 183 | read -p "Please confirm to continued(yes/no)?" confirm 184 | done 185 | else 186 | GIT_ROOT=$(echo $GIT_REPO_URL | cut -d'.' -f 2 | cut -d'/' -f 3) 187 | echo "GIT_ROOT=$GIT_ROOT" >> "$CONF_ROOT/config.txt" 188 | fi 189 | echo -e "Please Last time write to project name (Django base app name) :" 190 | read -p "Project name : " APP_NAME 191 | while true ; do 192 | if [ $APP_NAME ]; then 193 | break 194 | fi 195 | read -p "Project name : " APP_NAME 196 | done 197 | echo "APP_NAME=$APP_NAME" >> "$CONF_ROOT/config.txt" 198 | echo -e "Make commands executable" 199 | cp -r $CONF_ROOT/config.txt /var/local/ 200 | chown -R $APP_USER:$APP_USER /var/local/config.txt 201 | chmod -R 777 /var/local/config.txt 202 | cp -r $CONF_ROOT/status.txt /var/local/ 203 | chown -R $APP_USER:$APP_USER /var/local/status.txt 204 | chmod -R 777 /var/local/status.txt 205 | cp -r $CONF_ROOT/commands /var/local/ 206 | chown -R $APP_USER:$APP_USER /var/local/commands 207 | chown -R $APP_USER:$APP_USER /var/local/commands/* 208 | chmod -R 777 /var/local/commands/* 209 | cp -r $CONF_ROOT/tlp /var/local/ 210 | chown -R $APP_USER:$APP_USER /var/local/tlp 211 | chown -R $APP_USER:$APP_USER /var/local/tlp/* 212 | chmod -R 777 /var/local/tlp/* 213 | sed -i -e 's|#{APP_ROOT_DIRECTOR}|'$APP_ROOT_DIRECTOR'|g' -e 's|#{APP_USER}|'$APP_USER'|g' /var/local/tlp/pipeline.sh 214 | cp -r /var/local/tlp/pipeline.sh /root/ 215 | chmod +x /root/pipeline.sh 216 | echo -e "Base command sed " 217 | sed -i -e 's|#{APP_USER_LINUX}|'$APP_USER'|g' $CONF_ROOT/commands/base 218 | cp -r $CONF_ROOT/commands/base /bin/ 219 | chmod +x /bin/base 220 | echo "INSTALLATION_GIT_PROJECT=True" >> $CONF_ROOT/status.txt 221 | fi 222 | base 223 | } 224 | 225 | function configuration_server() { 226 | . $CONF_ROOT/config.txt 227 | echo -e "Configuration Nginx credentials.." 228 | sed -i -e 's|#{APP_SERVER}|'$APP_SERVER'|g' -e 's|#{APP_ROOT_DIRECTORY}|'$APP_ROOT_DIRECTORY'|g' -e 's|#{APP_NAME}|'$APP_NAME'|g' $CONF_ROOT/tlp/default 229 | echo -e "Create nginx default server.." 230 | cp -r tlp/default /etc/nginx/sites-available/default 231 | echo -e "Gunicorn file created.." 232 | sed -i -e 's|#{APP_USER}|'$APP_USER'|g' -e 's|#{APP_ROOT_DIRECTORY}|'$APP_ROOT_DIRECTORY'|g' -e 's|#{APP_NAME}|'$APP_NAME'|g' $CONF_ROOT/tlp/gunicorn.service 233 | cp -r tlp/gunicorn.service /etc/systemd/system/ 234 | echo -e "Everything works cool :)" 235 | } 236 | 237 | 238 | function create_database { 239 | # Database creation 240 | . $CONF_ROOT/config.txt 241 | read -p "Postgres Database name : " APP_DB_NAME 242 | while true ; do 243 | if [ $APP_DB_NAME ]; then 244 | break 245 | fi 246 | read -p "Please enter Postgres Database name : " APP_DB_NAME 247 | done 248 | echo "APP_DB_NAME=$APP_DB_NAME" >> "$CONF_ROOT/config.txt" 249 | read -p "Postgres Database password : " APP_DB_PASSWORD 250 | while true ; do 251 | if [ $APP_DB_PASSWORD ]; then 252 | break 253 | fi 254 | read -p "Please enter Postgres Database password : " APP_DB_PASSWORD 255 | done 256 | echo "APP_DB_PASSWORD=$APP_DB_PASSWORD" >> "$CONF_ROOT/config.txt" 257 | echo "----- PostgreSQL v$POSTGRESQL_CLUSTER_VERSION: Creating database and user..." 258 | sudo su - ${POSTGRESQL_USER} << EOF 259 | # -------[script begins]------- 260 | # psql --help 261 | psql -c " 262 | CREATE USER $APP_USER WITH PASSWORD '$APP_DB_PASSWORD'; 263 | " 264 | createdb --owner $APP_DB_USER $APP_DB_NAME 265 | # -------[script ends]------- 266 | EOF 267 | } 268 | 269 | function delete_database { 270 | # Delete database 271 | . $CONF_ROOT/config.txt 272 | clear 273 | echo "************************************************************************" 274 | echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! DANGER !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" 275 | echo "************************************************************************" 276 | echo "" 277 | read -p "Are you sure you want flush entirely DATABASE? (y/n): " confirm_delete 278 | if [ "$confirm_delete" == y ] ; then 279 | echo "----- PostgreSQL v$POSTGRESQL_CLUSTER_VERSION: Delete DB and user" 280 | 281 | # restart cluster 282 | sudo pg_ctlcluster ${POSTGRESQL_CLUSTER_VERSION} main restart --force 283 | # sudo /etc/init.d/postgresql restart 284 | 285 | # delete user 286 | sudo su - ${POSTGRESQL_USER} << EOF 287 | # -------[script begins]------- 288 | dropdb ${APP_DB_NAME} 289 | psql -c "DROP USER ${APP_USER};" 290 | # -------[script ends]------- 291 | EOF 292 | fi 293 | } 294 | 295 | function upgrade_cluster { 296 | . $CONF_ROOT/config.txt 297 | # Upgrade PostgreSQL 9.3 to 9.5 on Ubuntu 14.04 and Ubuntu 16.04 298 | # ref: https://medium.com/@tk512/upgrading-postgresql-from-9-3-to-9-4-on-ubuntu-14-04-lts-2b4ddcd26535#.4i136rihe 299 | if [ "$POSTGRESQL_CLUSTER_VERSION" != "$POSTGRESQL_UPGRADE_TO" ]; then 300 | echo "----- PostgreSQL v$POSTGRESQL_CLUSTER_VERSION: Dump" 301 | # http://www.postgresql.org/docs/9.4/static/backup-dump.html 302 | 303 | sudo su - ${POSTGRESQL_USER} << EOF 304 | # -------[script begins]------- 305 | psql -U ${POSTGRESQL_USER} -l 306 | mkdir -p ./backups 307 | pg_dumpall > ./backups/old_.db 308 | # -------[script ends]------- 309 | EOF 310 | 311 | echo "----- PostgreSQL: stop the current database..." 312 | sudo /etc/init.d/postgresql stop 313 | 314 | echo "----- PostgreSQL: Create a new list..." 315 | sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' 316 | wget -q -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - 317 | 318 | echo "----- PostgreSQL: download $POSTGRESQL_UPGRADE_TO" 319 | sudo apt-get update 320 | sudo apt-get install -y postgresql-${POSTGRESQL_UPGRADE_TO} 321 | 322 | sudo pg_lsclusters 323 | 324 | sudo pg_dropcluster --stop ${POSTGRESQL_UPGRADE_TO} main 325 | sudo /etc/init.d/postgresql start 326 | 327 | echo "----- PostgreSQL: Upgrade to $POSTGRESQL_UPGRADE_TO" 328 | sudo pg_upgradecluster ${POSTGRESQL_CLUSTER_VERSION} main 329 | sudo pg_dropcluster ${POSTGRESQL_CLUSTER_VERSION} main 330 | sudo pg_lsclusters 331 | else 332 | echo -e "\n ==> Cluster up to date! \n" 333 | fi 334 | } 335 | 336 | # ------------------------ 337 | # Dump the DB that given in config file to the passed destination 338 | function restore_from_source { 339 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 340 | # * Restoring Django database 341 | # - http://stackoverflow.com/a/2732521/968751 342 | # 343 | # 1) Include project variables 344 | # 2) Drop existing database if you want overwrite 345 | # 3) Drop the User, database associated with 346 | # 4) Create User 347 | # 5) Create Database but don't `migrate` yet 348 | # 6) Restore the database from dump file 349 | # 7) Create proper rules for the restored tables 350 | # 351 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 352 | # 1) . /vagrant/vagrant_setup/config.txt 353 | # 2) dropdb $APP_DB_NAME 354 | # 3) psql -c " DROP USER $APP_DB_USER;" 355 | # 4) psql -c " CREATE USER $APP_DB_USER WITH PASSWORD '$APP_DB_PASSWORD'; " 356 | # 5) createdb --owner $APP_DB_USER $APP_DB_NAME 357 | # 6) psql $APP_DB_NAME -f ./backups/dump_24aug.sql 358 | # 7) for tbl in `psql -qAt -c "select tablename from pg_tables where schemaname = 'public';" $APP_DB_NAME` ; do psql -c "alter table \"$tbl\" owner to $APP_DB_USER" $APP_DB_NAME ; done 359 | # for tbl in `psql -qAt -c "select sequence_name from information_schema.sequences where sequence_schema = 'public';" $APP_DB_NAME` ; do psql -c "alter table \"$tbl\" owner to $APP_DB_USER" $APP_DB_NAME ; done 360 | # for tbl in `psql -qAt -c "select table_name from information_schema.views where table_schema = 'public';" $APP_DB_NAME` ; do psql -c "alter table \"$tbl\" owner to $APP_DB_USER" $APP_DB_NAME ; done 361 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 362 | # pg_restore -U $APP_DB_USER -d $APP_DB_NAME -1 363 | # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 364 | . $CONF_ROOT/config.txt 365 | local SRC=$(normalize_path "$1") 366 | local FILENAME="${SRC##*/}" 367 | 368 | if [ ! -f ${SRC} ]; then 369 | echo -e "\n==> File not found: '$SRC'\n" 370 | exit 1 371 | fi 372 | 373 | echo "----- PostgreSQL v$POSTGRESQL_CLUSTER_VERSION: Importing DB from file '$SRC'" 374 | cp --no-preserve=mode,ownership ${SRC} /tmp/ 375 | sudo su - ${POSTGRESQL_USER} << EOF 376 | # -------[script begins]------- 377 | pg_restore -U ${POSTGRESQL_USER} -d ${APP_DB_NAME} -1 /tmp/${FILENAME} 378 | # -------[script ends]------- 379 | EOF 380 | sudo rm -rf /tmp/${FILENAME} 381 | } 382 | 383 | # ------------------------ 384 | # Dump the DB that given in config file to the passed destination 385 | function dump_to_destination { 386 | # Dump DB to given destination 387 | . $CONF_ROOT/config.txt 388 | local DST=$(normalize_path "$1") 389 | local BACKUP_DATE=$(date '+%d-%b-%Y') 390 | 391 | echo "----- PostgreSQL v$POSTGRESQL_CLUSTER_VERSION: Exporting DB to '$DST'" 392 | sudo su - ${POSTGRESQL_USER} << EOF 393 | # -------[script begins]------- 394 | mkdir -p ./backups 395 | pg_dump -E UTF-8 -Fc ${APP_DB_NAME} > ./backups/${APP_DB_NAME}\_${BACKUP_DATE}.sql 396 | \cp -i ./backups/${APP_DB_NAME}\_${BACKUP_DATE}.sql /tmp 397 | # -------[script ends]------- 398 | EOF 399 | cp --no-preserve=mode,ownership /tmp/${APP_DB_NAME}\_${BACKUP_DATE}.sql ${DST} 400 | sudo rm /tmp/${APP_DB_NAME}\_${BACKUP_DATE}.sql 401 | } 402 | 403 | 404 | 405 | 406 | function done_script() { 407 | . $CONF_ROOT/config.txt 408 | if [ ! -f "/home/$APP_USER/error.log" ]; then 409 | echo "Everything is OK :)" 410 | echo "---" 411 | echo "---" 412 | echo "Deployment ready! Now log into linux user, intialize the virtual environment, \ 413 | start the server and you'll be able to see the django-app!" 414 | echo "---" 415 | echo "---" 416 | echo "DEPLOYMENT_STATUS=True" >> $CONF_ROOT/config.txt 417 | sudo su - $APP_USER 418 | else 419 | echo "You have a error :(" 420 | echo "Deployment unsuccessfull" 421 | echo "If you want to show error log write cat /home/$APP_USER/error.log" 422 | fi 423 | 424 | } 425 | 426 | function normalize_path 427 | { 428 | #The printf is necessary to correctly decode unicode sequences 429 | path=$($PRINTF "${1//\/\///}") 430 | if [[ $HAVE_READLINK == 1 ]]; then 431 | new_path=$(readlink -m "$path") 432 | 433 | #Adding back the final slash, if present in the source 434 | if [[ ${path: -1} == "/" && ${#path} > 1 ]]; then 435 | new_path="$new_path/" 436 | fi 437 | 438 | echo "$new_path" 439 | else 440 | echo "$path" 441 | fi 442 | } 443 | 444 | 445 | ################ 446 | #### START #### 447 | ################ 448 | 449 | COMMAND=${@:$OPTIND:1} 450 | ARG1=${@:$OPTIND+1:1} 451 | 452 | 453 | #CHECKING PARAMS VALUES 454 | case ${COMMAND} in 455 | 456 | usage) 457 | 458 | usage 459 | 460 | ;; 461 | 462 | status) 463 | 464 | deployment_status 465 | 466 | ;; 467 | 468 | deploy) 469 | 470 | get_user_credential 471 | fix_perl_locale_error 472 | create_new_linux_user 473 | get_project_details 474 | done_script 475 | ;; 476 | 477 | flush) 478 | 479 | delete_database 480 | create_database 481 | 482 | ;; 483 | 484 | delete) 485 | 486 | delete_database 487 | 488 | ;; 489 | 490 | create) 491 | 492 | create_database 493 | 494 | ;; 495 | 496 | upgrade) 497 | 498 | upgrade_cluster 499 | 500 | ;; 501 | 502 | test) 503 | testing 504 | ;; 505 | 506 | dump) 507 | 508 | # if path not provided show usage message 509 | if [ "$#" -ne 2 ]; then 510 | usage 511 | fi 512 | 513 | FILE_DST=${ARG1} 514 | dump_to_destination ${FILE_DST} 515 | 516 | ;; 517 | 518 | restore) 519 | 520 | # if source not provided show usage message 521 | if [ "$#" -ne 2 ]; then 522 | usage 523 | fi 524 | 525 | FILE_SRC=${ARG1} 526 | restore_from_source ${FILE_SRC} 527 | 528 | ;; 529 | *) 530 | 531 | if [[ $COMMAND != "" ]]; then 532 | echo "Error: Unknown command: $COMMAND" 533 | ERROR_STATUS=1 534 | fi 535 | usage 536 | 537 | ;; 538 | esac 539 | 540 | exit $ERROR_STATUS -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # User-friendly check for sphinx-build 11 | ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) 12 | $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) 13 | endif 14 | 15 | # Internal variables. 16 | PAPEROPT_a4 = -D latex_paper_size=a4 17 | PAPEROPT_letter = -D latex_paper_size=letter 18 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 19 | # the i18n builder cannot share the environment and doctrees with the others 20 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 21 | 22 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext 23 | 24 | help: 25 | @echo "Please use \`make ' where is one of" 26 | @echo " html to make standalone HTML files" 27 | @echo " dirhtml to make HTML files named index.html in directories" 28 | @echo " singlehtml to make a single large HTML file" 29 | @echo " pickle to make pickle files" 30 | @echo " json to make JSON files" 31 | @echo " htmlhelp to make HTML files and a HTML help project" 32 | @echo " qthelp to make HTML files and a qthelp project" 33 | @echo " devhelp to make HTML files and a Devhelp project" 34 | @echo " epub to make an epub" 35 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 36 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 37 | @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" 38 | @echo " text to make text files" 39 | @echo " man to make manual pages" 40 | @echo " texinfo to make Texinfo files" 41 | @echo " info to make Texinfo files and run them through makeinfo" 42 | @echo " gettext to make PO message catalogs" 43 | @echo " changes to make an overview of all changed/added/deprecated items" 44 | @echo " xml to make Docutils-native XML files" 45 | @echo " pseudoxml to make pseudoxml-XML files for display purposes" 46 | @echo " linkcheck to check all external links for integrity" 47 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 48 | 49 | clean: 50 | rm -rf $(BUILDDIR)/* 51 | 52 | html: 53 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 54 | @echo 55 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 56 | 57 | dirhtml: 58 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 59 | @echo 60 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 61 | 62 | singlehtml: 63 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 64 | @echo 65 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 66 | 67 | pickle: 68 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 69 | @echo 70 | @echo "Build finished; now you can process the pickle files." 71 | 72 | json: 73 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 74 | @echo 75 | @echo "Build finished; now you can process the JSON files." 76 | 77 | htmlhelp: 78 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 79 | @echo 80 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 81 | ".hhp project file in $(BUILDDIR)/htmlhelp." 82 | 83 | qthelp: 84 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 85 | @echo 86 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 87 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 88 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/DjangoDebugToolbar.qhcp" 89 | @echo "To view the help file:" 90 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/DjangoDebugToolbar.qhc" 91 | 92 | devhelp: 93 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 94 | @echo 95 | @echo "Build finished." 96 | @echo "To view the help file:" 97 | @echo "# mkdir -p $$HOME/.local/share/devhelp/DjangoDebugToolbar" 98 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/DjangoDebugToolbar" 99 | @echo "# devhelp" 100 | 101 | epub: 102 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 103 | @echo 104 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 105 | 106 | latex: 107 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 108 | @echo 109 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 110 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 111 | "(use \`make latexpdf' here to do that automatically)." 112 | 113 | latexpdf: 114 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 115 | @echo "Running LaTeX files through pdflatex..." 116 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 117 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 118 | 119 | latexpdfja: 120 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 121 | @echo "Running LaTeX files through platex and dvipdfmx..." 122 | $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja 123 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 124 | 125 | text: 126 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 127 | @echo 128 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 129 | 130 | man: 131 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 132 | @echo 133 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 134 | 135 | texinfo: 136 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 137 | @echo 138 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 139 | @echo "Run \`make' in that directory to run these through makeinfo" \ 140 | "(use \`make info' here to do that automatically)." 141 | 142 | info: 143 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 144 | @echo "Running Texinfo files through makeinfo..." 145 | make -C $(BUILDDIR)/texinfo info 146 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 147 | 148 | gettext: 149 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 150 | @echo 151 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 152 | 153 | changes: 154 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 155 | @echo 156 | @echo "The overview file is in $(BUILDDIR)/changes." 157 | 158 | linkcheck: 159 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 160 | @echo 161 | @echo "Link check complete; look for any errors in the above output " \ 162 | "or in $(BUILDDIR)/linkcheck/output.txt." 163 | 164 | doctest: 165 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 166 | @echo "Testing of doctests in the sources finished, look at the " \ 167 | "results in $(BUILDDIR)/doctest/output.txt." 168 | 169 | xml: 170 | $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml 171 | @echo 172 | @echo "Build finished. The XML files are in $(BUILDDIR)/xml." 173 | 174 | pseudoxml: 175 | $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml 176 | @echo 177 | @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." -------------------------------------------------------------------------------- /docs/changes.rst: -------------------------------------------------------------------------------- 1 | Change log 2 | ========== 3 | 4 | 1.9 (upcoming) 5 | -------------- 6 | 7 | Bugfixes 8 | ~~~~~~~~ 9 | 10 | * The profiling panel now escapes reported data resulting in valid HTML. 11 | 12 | 1.8 13 | --- 14 | 15 | This version is compatible with Django 1.11 and requires Django 1.8 or 16 | later. 17 | 18 | Features 19 | ~~~~~~~~ 20 | 21 | * New decorator ``debug_toolbar.decorators.require_show_toolbar`` prevents 22 | unauthorized access to decorated views by checking ``SHOW_TOOLBAR_CALLBACK`` 23 | every request. Unauthorized access results in a 404. 24 | * The ``SKIP_TEMPLATE_PREFIXES`` setting allows skipping templates in 25 | the templates panel. Template-based form widgets' templates are 26 | skipped by default to avoid panel sizes going into hundreds of 27 | megabytes of HTML. 28 | 29 | Bugfixes 30 | ~~~~~~~~ 31 | 32 | * All views are now decorated with 33 | ``debug_toolbar.decorators.require_show_toolbar`` preventing unauthorized 34 | access. 35 | * The templates panel now reuses contexts' pretty printed version which 36 | makes the debug toolbar usable again with Django 1.11's template-based 37 | forms rendering. 38 | * Long SQL statements are now forcibly wrapped to fit on the screen. 39 | 40 | 1.7 41 | --- 42 | 43 | Bugfixes 44 | ~~~~~~~~ 45 | 46 | * Recursive template extension is now understood. 47 | * Deprecation warnings were fixed. 48 | * The SQL panel uses HMAC instead of simple hashes to verify that SQL 49 | statements have not been changed. Also, the handling of bytes and text 50 | for hashing has been hardened. Also, a bug with Python's division 51 | handling has been fixed for improved Python 3 support. 52 | * An error with django-jinja has been fixed. 53 | * A few CSS classes have been prefixed with ``djdt-`` to avoid 54 | conflicting class names. 55 | 56 | 1.6 57 | --- 58 | 59 | The debug toolbar was adopted by jazzband. 60 | 61 | Removed features 62 | ~~~~~~~~~~~~~~~~ 63 | 64 | * Support for automatic setup has been removed as it was frequently 65 | problematic. Installation now requires explicit setup. The 66 | ``DEBUG_TOOLBAR_PATCH_SETTINGS`` setting has also been removed as it is now 67 | unused. See the :doc:`installation documentation ` for details. 68 | 69 | Bugfixes 70 | ~~~~~~~~ 71 | 72 | * The ``DebugToolbarMiddleware`` now also supports Django 1.10's ``MIDDLEWARE`` 73 | setting. 74 | 75 | 1.5 76 | --- 77 | 78 | This version is compatible with Django 1.10 and requires Django 1.8 or later. 79 | 80 | Support for Python 3.2 is dropped. 81 | 82 | Bugfixes 83 | ~~~~~~~~ 84 | 85 | * Restore compatibility with sqlparse ≥ 0.2.0. 86 | * Add compatibility with Bootstrap 4, Pure CSS, MDL, etc. 87 | * Improve compatibility with RequireJS / AMD. 88 | * Improve the UI slightly. 89 | * Fix invalid (X)HTML. 90 | 91 | 1.4 92 | --- 93 | 94 | This version is compatible with Django 1.9 and requires Django 1.7 or later. 95 | 96 | New features 97 | ~~~~~~~~~~~~ 98 | 99 | * New panel method :meth:`debug_toolbar.panels.Panel.generate_stats` allows panels 100 | to only record stats when the toolbar is going to be inserted into the 101 | response. 102 | 103 | Bugfixes 104 | ~~~~~~~~ 105 | 106 | * Response time for requests of projects with numerous media files has 107 | been improved. 108 | 109 | 1.3 110 | --- 111 | 112 | This is the first version compatible with Django 1.8. 113 | 114 | New features 115 | ~~~~~~~~~~~~ 116 | 117 | * A new panel is available: Template Profiler. 118 | * The ``SHOW_TOOLBAR_CALLBACK`` accepts a callable. 119 | * The toolbar now provides a :ref:`javascript-api`. 120 | 121 | Bugfixes 122 | ~~~~~~~~ 123 | 124 | * The toolbar handle cannot leave the visible area anymore when the toolbar is 125 | collapsed. 126 | * The root level logger is preserved. 127 | * The ``RESULTS_CACHE_SIZE`` setting is taken into account. 128 | * CSS classes are prefixed with ``djdt-`` to prevent name conflicts. 129 | * The private copy of jQuery no longer registers as an AMD module on sites 130 | that load RequireJS. 131 | 132 | 1.2 133 | --- 134 | 135 | New features 136 | ~~~~~~~~~~~~ 137 | 138 | * The ``JQUERY_URL`` setting defines where the toolbar loads jQuery from. 139 | 140 | Bugfixes 141 | ~~~~~~~~ 142 | 143 | * The toolbar now always loads a private copy of jQuery in order to avoid 144 | using an incompatible version. It no longer attemps to integrate with AMD. 145 | 146 | This private copy is available in ``djdt.jQuery``. Third-party panels are 147 | encouraged to use it because it should be as stable as the toolbar itself. 148 | 149 | 1.1 150 | --- 151 | 152 | This is the first version compatible with Django 1.7. 153 | 154 | New features 155 | ~~~~~~~~~~~~ 156 | 157 | * The SQL panel colors queries depending on the stack level. 158 | * The Profiler panel allows configuring the maximum depth. 159 | 160 | Bugfixes 161 | ~~~~~~~~ 162 | 163 | * Support languages where lowercase and uppercase strings may have different 164 | lengths. 165 | * Allow using cursor as context managers. 166 | * Make the SQL explain more helpful on SQLite. 167 | * Various JavaScript improvements. 168 | 169 | Deprecated features 170 | ~~~~~~~~~~~~~~~~~~~ 171 | 172 | * The ``INTERCEPT_REDIRECTS`` setting is superseded by the more generic 173 | ``DISABLE_PANELS``. 174 | 175 | 1.0 176 | --- 177 | 178 | This is the first stable version of the Debug Toolbar! 179 | 180 | It includes many new features and performance improvements as well a few 181 | backwards-incompatible changes to make the toolbar easier to deploy, use, 182 | extend and maintain in the future. 183 | 184 | You're strongly encouraged to review the installation and configuration docs 185 | and redo the setup in your projects. 186 | 187 | Third-party panels will need to be updated to work with this version. -------------------------------------------------------------------------------- /docs/commands.rst: -------------------------------------------------------------------------------- 1 | Commands 2 | ======== 3 | 4 | The Django Deployment Tools avilable Command Here. 5 | 6 | ``usage`` 7 | --------- 8 | 9 | This command help to user find how to use it tools 10 | 11 | Here's an example:: 12 | 13 | $ ./deploy.sh usage 14 | $ -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 15 | $ 16 | $ Django Deployment Tool v0.1 17 | $ Munis Isazade - munisisazade@gmail.com 18 | $ -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 19 | $ 20 | $ Usage: bash ./deploy.sh 21 | $ 22 | $ Commands: 23 | $ usage - For helping available commands to use 24 | $ 25 | 26 | ``deploy`` 27 | ---------- 28 | 29 | This is the base Command of Deployment tools. Firstly on Ubuntu 16.04 installed required this packages: 30 | python-pip python-dev libpq-dev python3-pip python3-dev libpq-dev postgresql postgresql-contrib nginx python3-venv 31 | For Pillow required packages : libtiff5-dev libjpeg8-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python-tk 32 | All installation takes time about 2-3 minutes. After this installation Tool ask Linux new user name 33 | and password 34 | 35 | Here's an example 36 | 37 | ``status`` 38 | ---------- 39 | 40 | This command check deployment Status 41 | 42 | -------------------------------------------------------------------------------- /docs/contributing.rst: -------------------------------------------------------------------------------- 1 | Contributing 2 | ============ 3 | 4 | .. image:: https://www.drupal.org/files/project-images/icon-deploy.png 5 | :target: https://www.drupal.org/ 6 | :alt: Deploymet 7 | 8 | This is a `Munis Isazade `_ project. By contributing you agree 9 | to abide by the `Contributor Code of Conduct `_ 10 | and follow the `guidelines `_. 11 | 12 | Bug reports and feature requests 13 | -------------------------------- 14 | 15 | You can report bugs and request features in the `bug tracker 16 | `_. 17 | 18 | Please search the existing database for duplicates before filing an issue. -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | Django Deployment Tool 2 | ====================== 3 | 4 | .. toctree:: 5 | :maxdepth: 2 6 | 7 | installation 8 | commands 9 | contributing -------------------------------------------------------------------------------- /docs/installation.rst: -------------------------------------------------------------------------------- 1 | Installation 2 | ============ 3 | 4 | Getting the code 5 | ---------------- 6 | 7 | The recommended way to install the Python 3 is via Ubuntu 16.04 apt package 8 | If you are using Python 2, type:: 9 | 10 | $ apt apt-get update 11 | $ apt-get install python-pip python-dev git 12 | 13 | If you are using Django with Python 3, type:: 14 | 15 | $ apt-get update 16 | $ apt-get install python3-pip python3-dev git 17 | 18 | If you want to use this Tools plase make sure u have root user 19 | check u are a root user bellow command:: 20 | 21 | $ whoami 22 | 23 | if not try this:: 24 | 25 | $ sudo su - root 26 | 27 | You can install this tool via git command:: 28 | 29 | $ git clone https://github.com/munisisazade/django_deployment_tool.git 30 | 31 | Make Command Executable 32 | ----------------------- 33 | After installation you can executable command using ``chmod`` bash command:: 34 | 35 | $ cd django_deployment_tool/ 36 | $ chmod +x deploy.sh 37 | 38 | Already ready use this tool just typing:: 39 | 40 | $ ./deploy.sh usage -------------------------------------------------------------------------------- /status.txt: -------------------------------------------------------------------------------- 1 | # This is deployment status File to check your application is correctly deploy or not 2 | -------------------------------------------------------------------------------- /tlp/bitbucket-pipelines.yml: -------------------------------------------------------------------------------- 1 | # This is a sample build configuration for Python. 2 | # Check our guides at https://confluence.atlassian.com/x/x4UWN for more examples. 3 | # Only use spaces to indent your .yml configuration. 4 | # ----- 5 | # You can specify a custom docker image from Docker Hub as your build environment. 6 | image: python:3.5.1 7 | pipelines: 8 | branches: 9 | 10 | master: # for base script 11 | - step: 12 | script: # Modify the commands below to build your repository. 13 | - ssh root@#{APP_SERVER} 'bash pipeline.sh' 14 | -------------------------------------------------------------------------------- /tlp/default: -------------------------------------------------------------------------------- 1 | ## 2 | # You should look at the following URL's in order to grasp a solid understanding 3 | # of Nginx configuration files in order to fully unleash the power of Nginx. 4 | # http://wiki.nginx.org/Pitfalls 5 | # http://wiki.nginx.org/QuickStart 6 | # http://wiki.nginx.org/Configuration 7 | # 8 | # Generally, you will want to move this file somewhere, and start with a clean 9 | # file but keep this around for reference. Or just disable in sites-enabled. 10 | # 11 | # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples. 12 | ## 13 | 14 | # Default server configuration 15 | # 16 | 17 | server { 18 | client_max_body_size 20M; 19 | listen 80; 20 | server_name #{APP_SERVER}; 21 | 22 | error_page 404 /custom_404.html; 23 | location = /custom_404.html { 24 | root /usr/share/nginx/html; 25 | internal; 26 | } 27 | location /media/ { 28 | root #{APP_ROOT_DIRECTOR}; 29 | } 30 | location /static/ { 31 | root #{APP_ROOT_DIRECTOR}; 32 | } 33 | location / { 34 | include proxy_params; 35 | proxy_pass http://unix:#{APP_ROOT_DIRECTOR}/#{APP_NAME}.sock; 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /tlp/gunicorn.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=gunicorn daemon 3 | After=network.target 4 | 5 | [Service] 6 | User=#{APP_USER} 7 | Group=www-data 8 | WorkingDirectory=#{APP_ROOT_DIRECTOR} 9 | ExecStart=#{APP_ROOT_DIRECTOR}/.venv/bin/gunicorn --workers 3 --bind unix:#{APP_ROOT_DIRECTOR}/#{APP_NAME}.sock #{APP_NAME}.wsgi:application 10 | 11 | [Install] 12 | WantedBy=multi-user.target 13 | -------------------------------------------------------------------------------- /tlp/pipeline.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | echo -e "Connect To Server user #{APP_USER}" 4 | sudo su - #{APP_USER} << EOF 5 | cd #{APP_ROOT_DIRECTOR} 6 | echo -e "Activate virtualenviroment" 7 | source .venv/bin/activate 8 | echo -e "Check system issues" 9 | python manage.py check 10 | echo -e "Stage deploy to Server" 11 | git pull 12 | echo -e "Installing some packages .." 13 | pip install -r requirements.txt 14 | echo -e "Makemigrations " 15 | python manage.py migrate 16 | echo -e "Check error issues" 17 | check 18 | echo -e "Everything works fine :)" 19 | EOF 20 | 21 | systemctl restart nginx 22 | echo "Restarting nginx: [OK]" 23 | systemctl restart gunicorn 24 | echo "Restarting Gunicorn: [OK]" 25 | echo "Everything is OK :)" 26 | 27 | -------------------------------------------------------------------------------- /tlp/redis.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Redis In-Memory Data Store 3 | After=network.target 4 | 5 | [Service] 6 | User=redis 7 | Group=redis 8 | ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf 9 | ExecStop=/usr/local/bin/redis-cli shutdown 10 | Restart=always 11 | 12 | [Install] 13 | WantedBy=multi-user.target --------------------------------------------------------------------------------