From 20080ec9bfa007521249a73cfbe299714f7223fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Cantu=C3=A1ria?= Date: Mon, 16 Nov 2020 15:17:18 -0300 Subject: [PATCH] Tutorial ambiente dev (#3319) * Adiciona docker com container postgresql * Adiciona tutorial para configurar e rodar o docker --- docker/docker-compose-dev-db.yml | 38 +++++++++++++++++++++++++++++ docs/ambiente-dev.md | 41 ++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 docker/docker-compose-dev-db.yml create mode 100644 docs/ambiente-dev.md diff --git a/docker/docker-compose-dev-db.yml b/docker/docker-compose-dev-db.yml new file mode 100644 index 000000000..15eb735fe --- /dev/null +++ b/docker/docker-compose-dev-db.yml @@ -0,0 +1,38 @@ +version: '3.7' + +services: + sapldb-dev: + container_name: sapldb-dev + image: postgres:10.5-alpine + environment: + POSTGRES_PASSWORD: sapl + POSTGRES_USER: sapl + POSTGRES_DB: sapl + ports: + - "5433:5432" + networks: + - sapl-net-dev + + sapl-dev: + container_name: sapl-dev + image: sapl:dev + build: + context: ../ + dockerfile: ./docker/Dockerfile.dev + command: python3 manage.py runserver 0:8000 + volumes: + - ..:/sapl-dev + ports: + - "8000:8000" + environment: + SECRET_KEY: '$dkhxm-$zvxdox$g2-&w^1i!_z1juq0xwox6e3#gy6w_88!3t^' + DEBUG: 'True' + DATABASE_URL: postgresql://sapl:sapl@sapldb-dev:5432/sapl + TZ: America/Sao_Paulo + networks: + - sapl-net-dev + +networks: + sapl-net-dev: + name: sapl-net-dev + driver: bridge \ No newline at end of file diff --git a/docs/ambiente-dev.md b/docs/ambiente-dev.md new file mode 100644 index 000000000..7b6cee424 --- /dev/null +++ b/docs/ambiente-dev.md @@ -0,0 +1,41 @@ +# Ambiente de Desenvolvimento + +### Tópicos + +* [Rodar Docker Compose](#Rodar-Docker-Compose) +* [Configurar Banco de Dados PostgreSQL instalado na máquina](#Configurar-Banco-de-Dados-PostgreSQL-instalado-na-máquina) +* [Restaurar uma Base de Dados](#Restaurar-Base-de-Dados) + +##### A configuração do banco de dados e restauração da base de dados só devem ser feitas na primeira vez. + + +## Rodar Docker Compose +Para rodar o docker compose sem o conteiner postgresql, vá ao terminal e execute o comando: +```shell +docker-compose -f docker/docker-compose-dev.yml up +``` +Se quiser com o conteiner postgresql, execute o comando: +```shell +docker-compose -f docker/docker-compose-dev-db.yml up +``` + +## Configurar Banco de Dados PostgreSQL instalado na máquina +A configuração do banco de dados só é necessário com o postgresql na máquina local. Para configurá-lo, vá ao terminal e execute os comandos a seguir para criar o usuário "sapl", senha "sapl" e a base de dados "sapl": +```shell +sudo -u postgres psql -c "CREATE ROLE sapl LOGIN ENCRYPTED PASSWORD 'sapl' NOSUPERUSER INHERIT CREATEDB NOCREATEROLE NOREPLICATION;" + +sudo -u postgres psql -c "ALTER ROLE sapl VALID UNTIL 'infinity';" + +sudo -u postgres psql -c "CREATE DATABASE sapl WITH OWNER = sapl ENCODING = 'UTF8' TABLESPACE = pg_default LC_COLLATE = 'pt_BR.UTF-8' LC_CTYPE = 'pt_BR.UTF-8' CONNECTION LIMIT = -1 TEMPLATE template0;" +``` +Depois do banco de dados ter sido configurado, [restaure alguma base de dados](#Restaurar-Base-de-Dados). + +## Restaurar Base de Dados +No termianal, rode o comando no diretório raiz do projeto passando como parâmetro o caminho do backup: +```shell +./scripts/restore_db.sh -f +``` +Se o postgres estiver rodando no container, adicione a _flag_ "-p 5433": +```shell +./scripts/restore_db.sh -f -f 5433 +```