This is a Fullstack test project, and use.
git clone https://github.com/rg3915/fullstack-django-vuejs.git
cd fullstack-django-vuejs
cp backend/contrib/env_sample .env
docker-compose -f docker-compose.dev.yml up --build -d
Enter in container and create super user:
docker container exec -it \
fullstack-django-vuejs_app_1 \
python manage.py createsuperuser \
--username="admin"
Tips:
-
Dont use
postgres:12
because it does not allow Djangomigrate
to work. -
Do not set
hostname
indb
because it interferes with the comunication between Django and database. -
Do not set
container_name
in services because it interferes with the comunication betweennginx
e aapp
. -
Não use
postgres:12
porque ele não permite que o Djangomigrate
funcione. -
Não defina
hostname
emdb
porque interfere na comunicação entre o Django e o banco. -
Não defina
container_name
nos serviços porque interfere na comunicação entre onginx
e aapp
.
docker run -d \
-p 9000:9000 \
--restart always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /opt/portainer:/data \
portainer/portainer
Portainer: localhost:9000
Backend: localhost/api/users/
Flower: localhost:5555/monitor
Without queue
.
celery --app=myproject worker --loglevel=INFO
With queue
.
celery --app=myproject worker --loglevel=INFO --queue=fila1
The flower monitoring Celery in realtime.
celery -A myproject flower
If stress Celery type and see in monitor
for i in $(seq 10); do curl localhost/task/print_numbers/; sleep 1; done
https://django-celery-results.readthedocs.io/en/latest/
python manage.py migrate django_celery_results
Add hoc
docker build -f DockerfileVueJS -t vuejs-app .
docker run -it -p 8080:8080 \
--rm --name vuejs \
vuejs-app
Em produção tive que configurar algumas coisas manualmente:
- Criei banco de dados PostgreSQL na RDS.
- Configurei endpoint no VueJS manualmente.
- Liberei as portas 80, 8080 e 9000 no Security Group.
- Criar banco PostgreSQL na AWS RDS.
- Criar uma instância Ubuntu na AWS EC2.
- Conectar no servidor via ssh.
alias l='clear; ls -lF'
alias rm='rm -i'
alias h=history
alias python=python3
alias pip=pip3
# Git
alias g='git'
alias gp='git push origin HEAD'
E faça source ~/.bashrc
Se quiser configure seu ~/.vimrc
para usar 4 espaços.
Eu gosto de deixar minha configuração assim:
set encoding=utf-8
set number " show line numbers
set expandtab " use spaces instead of tabs
set autoindent " autoindent based on line above
set smartindent " smarter indent for C-like languages
set shiftwidth=4 " when using Shift + > or <
set softtabstop=4 " in insert mode
set tabstop=4 " set the space occupied by a regular tab
Eu tenho um .vimrc
mais completo em
https://gist.github.com/rg3915/57b489c1751c384b3ad614c492478df0
- Rodar o script
deploy_aws.sh
.
Antes configure corretamente a conexão com o banco de dados.
- Conectar no RDS e criar o database. O RDS já define o nome do banco, você pode editar.
Na se esqueça de definir acesso público ao banco.
psql \
--host=url \
--port=5432 \
--username=postgres \
--password \
--dbname=nomedobanco
CREATE ROLE rg3915 ENCRYPTED PASSWORD 'tistysterappikeliessemssystiflow' LOGIN;
Crie um .env
cat << EOF > .env
DEBUG=True
SECRET_KEY=YTNlZjk5OTY4YjNlOWUxZjBkYTQwNzc2ZDZiMmVhNmU2ZmZlZG
ALLOWED_HOSTS=*
DB_HOST=URL
POSTGRES_DB=dbloxodonta
POSTGRES_USER=rg3915
POSTGRES_PASSWORD=tistysterappikeliessemssystiflow
APP_ID=xyz
KEY=xyz
SECRET=xyz
CLUSTER=xyz
EOF
Finalmente rode o script:
chmod +x deploy_aws.sh
./deploy_aws.sh
- Liberar as portas de conexão no AWS security groups.
- O site já está no ar a partir do IP público.
https://stackoverflow.com/a/54162975/802542
https://mattsegal.dev/django-prod-architectures.html
https://www.youtube.com/watch?v=3lD7zdwSYaU
https://docs.ansible.com/ansible/latest/modules/docker_container_module.html#examples
https://gist.github.com/mosquito/b23e1c1e5723a7fd9e6568e5cf91180f