Initial
This commit is contained in:
parent
fa34d894b5
commit
6026829ca0
5 changed files with 97 additions and 14 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,3 +1,3 @@
|
||||||
centos_django.step
|
centos_django.step
|
||||||
.vscode
|
.vscode
|
||||||
teste*
|
test_.*
|
||||||
80
README.md
80
README.md
|
|
@ -1,2 +1,80 @@
|
||||||
# django_centos_deploy
|

|
||||||
|
# Django to CentOS
|
||||||
|
|
||||||
|
[](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
|
||||||
|
```
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
USERNAME="centos"
|
USERNAME="centos"
|
||||||
|
|
||||||
# Nome do App no repositório
|
# Nome do App no repositório
|
||||||
# App name on repo
|
# Application name in repository
|
||||||
APP="app"
|
APP="app"
|
||||||
|
|
||||||
# Nome do ambiente virtual python
|
# Nome do ambiente virtual python
|
||||||
|
|
@ -21,8 +21,8 @@ GIT_USER="username"
|
||||||
# Git project url
|
# Git project url
|
||||||
GITURL="https://repo.com/$GIT_USER/$APP.git"
|
GITURL="https://repo.com/$GIT_USER/$APP.git"
|
||||||
|
|
||||||
# IP público ou domínio
|
# 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
|
# Public IP address or domain. If you leave it blank, the script'll catch the IP address with hostname command
|
||||||
PUB_IP=""
|
PUB_IP=""
|
||||||
|
|
||||||
# Nome da pasta que está no mesmo nível do arquivo wsgi.py
|
# Nome da pasta que está no mesmo nível do arquivo wsgi.py
|
||||||
|
|
|
||||||
BIN
django-centos.png
Normal file
BIN
django-centos.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.2 KiB |
15
run.sh
15
run.sh
|
|
@ -18,7 +18,7 @@ ARQ_CONF="centos.conf"
|
||||||
USERNAME="centos"
|
USERNAME="centos"
|
||||||
|
|
||||||
# Nome do App no repositório
|
# Nome do App no repositório
|
||||||
# App name on repo
|
# Application name in repository
|
||||||
APP="appname"
|
APP="appname"
|
||||||
|
|
||||||
# Nome do ambiente virtual python
|
# Nome do ambiente virtual python
|
||||||
|
|
@ -33,8 +33,8 @@ GIT_USER="username"
|
||||||
# Git project url
|
# Git project url
|
||||||
GITURL="https://repo.com/$GIT_USER/$APP.git"
|
GITURL="https://repo.com/$GIT_USER/$APP.git"
|
||||||
|
|
||||||
# IP público ou domínio
|
# 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
|
# Public IP address or domain. If you leave it blank, the script'll catch the IP address with hostname command
|
||||||
PUB_IP=""
|
PUB_IP=""
|
||||||
|
|
||||||
# Nome da pasta que está no mesmo nível do arquivo wsgi.py
|
# Nome da pasta que está no mesmo nível do arquivo wsgi.py
|
||||||
|
|
@ -130,7 +130,7 @@ fi
|
||||||
if [[ -f "$SCRIPT_STEP_FILE" ]]; then
|
if [[ -f "$SCRIPT_STEP_FILE" ]]; then
|
||||||
. "$SCRIPT_STEP_FILE"
|
. "$SCRIPT_STEP_FILE"
|
||||||
fi
|
fi
|
||||||
echo "step>$STEP"
|
|
||||||
# Verifica se deve exibir as mensagens em português do Brasil
|
# Verifica se deve exibir as mensagens em português do Brasil
|
||||||
# Check if the language pt_br has been chosen
|
# Check if the language pt_br has been chosen
|
||||||
if [[ ${PTBR,,} == "yes" ]] || [[ ${PTBR,,} == "sim" ]]; then
|
if [[ ${PTBR,,} == "yes" ]] || [[ ${PTBR,,} == "sim" ]]; then
|
||||||
|
|
@ -166,11 +166,13 @@ fi
|
||||||
|
|
||||||
# Obtém o IP
|
# Obtém o IP
|
||||||
# Get IP address
|
# Get IP address
|
||||||
|
if [[ ! -n $PUB_IP ]]; then
|
||||||
if [[ -n $(man hostname | awk '{RS="";FS="\n"} /-i,/ {print}') ]]; then
|
if [[ -n $(man hostname | awk '{RS="";FS="\n"} /-i,/ {print}') ]]; then
|
||||||
PUB_IP=$(hostname -i | cut -d" " -f1)
|
PUB_IP=$(hostname -i | cut -d" " -f1)
|
||||||
else
|
else
|
||||||
PUB_IP=$(hostname -I | cut -d" " -f1)
|
PUB_IP=$(hostname -I | cut -d" " -f1)
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
update_step_error() {
|
update_step_error() {
|
||||||
STEP="$x"
|
STEP="$x"
|
||||||
|
|
@ -292,6 +294,7 @@ install_packages() {
|
||||||
yum -y install python3-devel &&
|
yum -y install python3-devel &&
|
||||||
yum -y install gcc &&
|
yum -y install gcc &&
|
||||||
yum -y install nginx &&
|
yum -y install nginx &&
|
||||||
|
yum -y install net-tools &&
|
||||||
yum -y install policycoreutils-python-utils.noarch &&
|
yum -y install policycoreutils-python-utils.noarch &&
|
||||||
dnf update
|
dnf update
|
||||||
if [[ $? -ge 1 ]]; then
|
if [[ $? -ge 1 ]]; then
|
||||||
|
|
@ -325,7 +328,7 @@ execute_collec_mig_createsup() {
|
||||||
if [[ -d /home/$USERNAME/$APP/staticfiles ]]; then
|
if [[ -d /home/$USERNAME/$APP/staticfiles ]]; then
|
||||||
mkdir -p /home/$USERNAME/$APP/staticfiles
|
mkdir -p /home/$USERNAME/$APP/staticfiles
|
||||||
fi
|
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 migrate &&
|
||||||
/home/$USERNAME/$APP/$VENV/bin/python3 /manage.py createsuperuser
|
/home/$USERNAME/$APP/$VENV/bin/python3 /manage.py createsuperuser
|
||||||
}
|
}
|
||||||
|
|
@ -502,6 +505,7 @@ fi
|
||||||
# Start service
|
# Start service
|
||||||
run_service() {
|
run_service() {
|
||||||
chmod -R 751 /home/$USERNAME
|
chmod -R 751 /home/$USERNAME
|
||||||
|
chmod -R 755 /home/$USERNAME/$APP
|
||||||
chmod 664 /etc/systemd/system/$SERVICE &&
|
chmod 664 /etc/systemd/system/$SERVICE &&
|
||||||
chown -R $USERNAME:$USERNAME /home/$USERNAME &&
|
chown -R $USERNAME:$USERNAME /home/$USERNAME &&
|
||||||
systemctl daemon-reload &&
|
systemctl daemon-reload &&
|
||||||
|
|
@ -571,6 +575,7 @@ else
|
||||||
echo "${commands[$x]}_$x"
|
echo "${commands[$x]}_$x"
|
||||||
${commands[$x]} $x
|
${commands[$x]} $x
|
||||||
done
|
done
|
||||||
|
echo "\033[32m${MSGS[done]}\033[0m"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue