From 6026829ca081f72bca06382b595cac101db11c95 Mon Sep 17 00:00:00 2001 From: Lucas F Date: Thu, 20 Jan 2022 17:18:22 -0300 Subject: [PATCH] Initial --- .gitignore | 2 +- README.md | 80 +++++++++++++++++++++++++++++++++++++++++++++- centos.conf | 6 ++-- django-centos.png | Bin 0 -> 7353 bytes run.sh | 23 +++++++------ 5 files changed, 97 insertions(+), 14 deletions(-) create mode 100644 django-centos.png diff --git a/.gitignore b/.gitignore index 36e073a..b16ace6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ centos_django.step .vscode -teste* \ No newline at end of file +test_.* \ No newline at end of file diff --git a/README.md b/README.md index 3c11fc4..338e0ad 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,80 @@ -# django_centos_deploy +![image](./django-centos.png) +# Django to CentOS +[![The MIT License](https://img.shields.io/badge/license-MIT-orange.svg?style=flat-square)](https://git.lucasf.dev/publico/django-to-centos/-/blob/main/LICENSE) + + +Centos to Django is a bash script for deploy your django applications on CentOS servers. + +## How to use + +1. Clone this project into your server: + + ```shell + https://git.lucasf.dev/public/django-to-centos.git + ``` + +2. Fill in the variables from centos.conf file. + + ```bash + # ATENÇÃO, NÃO DEVE HAVER SEPARAÇÃO ENTRE O NOME DA VARIÁVEL E O VALOR DA VARIÁVEL APÓS O SINAL DE IGUALDADE + # ATTENTION, NO SPACES BETWEEN VAR NAME AND VAR CONTENT + + # Nome do usuário no sistema + # Sistem's username + USERNAME="centos" + + # Nome do App no repositório + # Application name in repository + APP="app" + + # Nome do ambiente virtual python + # Virtual environment name + VENV=".venv" + + # Nome de usuário do repositório ou grupo + # Git username or group + GIT_USER="username" + + # Endereço do projeto no repositório + # Git project url + GITURL="https://repo.com/$GIT_USER/$APP.git" + + # IP público ou domínio. Se deixar em branco o script vai capturar o endereço de IP com o comando hostname + # Public IP address or domain. If you leave it blank, the script'll catch the IP address with hostname command + PUB_IP="" + + # Nome da pasta que está no mesmo nível do arquivo wsgi.py + # Folder name that is at the same level as wsgi.py file + WSGI_FOLDER_NAME="appdirname" + + # Nome desejado para o serviço no Systemctl + # Systemctl desirable name + SERVICE="app.service" + + # Descrição do serviço no Systemctl + # Systemctl service description + DESCRIPTION="Django VPS uWSGI Emperor" + + # Adicionar o certificado digital na aplicação com Certbot. Escreva sim, se já possuir um domínio na internet + # Apply certbot ssl certificate, hit yes if you already have a domain + CERTBOT="no" + + # Adicionar renovação do certbot no crontab. Escreva sim, apenas se já possuir um domínio na internet + # Create a renew certbot cron job, hit yes if you already have a domain + CRON_CERTBOT="no" + + # Incrementar IP em ALLOWED_HOSTS no arquivo .env caso não tenha incrementado + # Increase ALLOWED_HOSTS IP on .env file + IP_INCRE="yes" + + # Mensagens em Português Brasil + # PT_BR messages + PTBR="no" + ``` + +3. Execute script: + + ```shell + sh run.sh + ``` diff --git a/centos.conf b/centos.conf index 09eb297..602685b 100755 --- a/centos.conf +++ b/centos.conf @@ -6,7 +6,7 @@ USERNAME="centos" # Nome do App no repositório -# App name on repo +# Application name in repository APP="app" # Nome do ambiente virtual python @@ -21,8 +21,8 @@ GIT_USER="username" # Git project url GITURL="https://repo.com/$GIT_USER/$APP.git" -# IP público ou domínio -# Public IP address or domain +# IP público ou domínio. Se deixar em branco o script vai capturar o endereço de IP com o comando hostname +# Public IP address or domain. If you leave it blank, the script'll catch the IP address with hostname command PUB_IP="" # Nome da pasta que está no mesmo nível do arquivo wsgi.py diff --git a/django-centos.png b/django-centos.png new file mode 100644 index 0000000000000000000000000000000000000000..40162c6edd181aed8bad24a729ab28b7acba3dae GIT binary patch literal 7353 zcmV;q97f}bP)pF8FWQhbW?9;ba!ELWdL_~cP?peYja~^aAhuUa%Y?FJQ@H197ah* zK~#90?VWj8lvUryKlcm_%rL_y5|X%pJEi8n<%au~nVOWQS?2m?W2!Iac>1w z_*q9d{!m;?x7}S8wW-GYNJ1*ovY5b9NL5s(8t)?@%<;RQuL^m1@GzokMwUoB@%I`2 zyKM^qT8)N@qaJa(Z{v<_{B`<-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_s{!Yw8+6p1{a-I=)pH zIFZ(uS6sM-1un!2uzmY6X3p&AB(g8Wbx>ZB9pYLt4K~UG_&(W>)h4?o6T09eDX7=E|f31 zzANPIckcDv)&fK2id@;^Lbbp^<%nDr;=*kb=txX#?{aQ&adz)ML+zMwX3p$K=WbE_ zaqy^9p3-(IFf|^I&FnnmGB7kAP3`-!<)vai|0Al{2i&T+Bvsu0ZVQ2D&+&XwTZc9+ z>Cncr$)yoZW|Vqep^ZV^Vzwubtgr`mbFEeJ5FvyPD9_4ie}QF{gkR5t=_@#T>EBKn z%r-q{tG$`^Q>alXor|d(+LMm8pF?0iq>ute0_8bxM=wc|%Q;tNaZ3wa5rhybt1xX) zN~-?*F1*db^pzgn9~(A+?)Bzj6{aLVg}O&YhWsi*wUgxnNs>%TNj20eOdH!o&!9!r z<8I%3qlgRD7F;HUmb_jmsRp=X$v2X?P;J3wQfSHdTdeutmu1N}nz&GH!EPgjP+6?` zU;8No`^j1IjVNw49wLNLnQg{RLI|<<{6euZshL=r)J$wU^Ng_BEW&Ix>?`!#tGQXZ zUgT$STEP" + # Verifica se deve exibir as mensagens em português do Brasil # Check if the language pt_br has been chosen if [[ ${PTBR,,} == "yes" ]] || [[ ${PTBR,,} == "sim" ]]; then @@ -166,10 +166,12 @@ fi # Obtém o IP # Get IP address -if [[ -n $(man hostname | awk '{RS="";FS="\n"} /-i,/ {print}') ]];then - PUB_IP=$(hostname -i | cut -d" " -f1) -else - PUB_IP=$(hostname -I | cut -d" " -f1) +if [[ ! -n $PUB_IP ]]; then + if [[ -n $(man hostname | awk '{RS="";FS="\n"} /-i,/ {print}') ]]; then + PUB_IP=$(hostname -i | cut -d" " -f1) + else + PUB_IP=$(hostname -I | cut -d" " -f1) + fi fi update_step_error() { @@ -292,6 +294,7 @@ install_packages() { yum -y install python3-devel && yum -y install gcc && yum -y install nginx && + yum -y install net-tools && yum -y install policycoreutils-python-utils.noarch && dnf update if [[ $? -ge 1 ]]; then @@ -325,7 +328,7 @@ execute_collec_mig_createsup() { if [[ -d /home/$USERNAME/$APP/staticfiles ]]; then mkdir -p /home/$USERNAME/$APP/staticfiles fi - /home/$USERNAME/$APP/$VENV/bin/python3 /manage.py collectstatic && + /home/$USERNAME/$APP/$VENV/bin/python3 /manage.py collectstatic --noinput && /home/$USERNAME/$APP/$VENV/bin/python3 /manage.py migrate && /home/$USERNAME/$APP/$VENV/bin/python3 /manage.py createsuperuser } @@ -502,6 +505,7 @@ fi # Start service run_service() { chmod -R 751 /home/$USERNAME + chmod -R 755 /home/$USERNAME/$APP chmod 664 /etc/systemd/system/$SERVICE && chown -R $USERNAME:$USERNAME /home/$USERNAME && systemctl daemon-reload && @@ -571,6 +575,7 @@ else echo "${commands[$x]}_$x" ${commands[$x]} $x done + echo "\033[32m${MSGS[done]}\033[0m" fi fi fi