From 8b25c3129eb8cc19a4963e7eeb0fc9b6d27d3915 Mon Sep 17 00:00:00 2001 From: Ricardo Lima Canela Date: Thu, 30 May 2019 11:21:11 -0300 Subject: [PATCH] Criando ambiente para desenvolvimento com docker compose (#2811) * Criando app painel websocket * desfazendo painel websocket e implantando docker-compose para desenvolvimento * Inserindo desenvolvimento com docker na documentacao de instalacao --- Dockerfile.dev | 34 +++++++++++++ docker-compose.dev.yml | 43 +++++++++++++++++ docker-compose.yml | 1 - docs/instalacao31.rst | 17 +++++++ start_devel.sh | 107 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 201 insertions(+), 1 deletion(-) create mode 100755 Dockerfile.dev create mode 100644 docker-compose.dev.yml create mode 100644 start_devel.sh diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100755 index 000000000..31f90725e --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,34 @@ +FROM alpine:3.8 + +ENV BUILD_PACKAGES postgresql-dev graphviz-dev graphviz build-base git pkgconfig \ + python3-dev libxml2-dev jpeg-dev libressl-dev libffi-dev libxslt-dev \ + nodejs py3-lxml py3-magic postgresql-client poppler-utils antiword \ + curl jq openssh-client vim bash + +RUN apk update --update-cache && apk upgrade + +RUN apk --update add fontconfig ttf-dejavu && fc-cache -fv + +RUN apk add --no-cache python3 nginx tzdata && \ + python3 -m ensurepip && \ + rm -r /usr/lib/python*/ensurepip && \ + pip3 install --upgrade pip setuptools && \ + rm -r /root/.cache && \ + rm -f /etc/nginx/conf.d/* + +RUN mkdir -p /var/interlegis/sapl && \ + apk add --update --no-cache $BUILD_PACKAGES + +ADD . /var/interlegis/sapl/ + +WORKDIR /var/interlegis/sapl/ + +RUN pip install -r /var/interlegis/sapl/requirements/dev-requirements.txt --upgrade setuptools && \ + rm -r /root/.cache + +#RUN python3 manage.py collectstatic --noinput --clear + +RUN chmod +x start_devel.sh + +CMD ["/var/interlegis/sapl/start_devel.sh"] + diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 000000000..a6bc8b356 --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,43 @@ +sapldb: + image: postgres:10.5-alpine + restart: always + environment: + POSTGRES_PASSWORD: sapl + POSTGRES_USER: sapl + POSTGRES_DB: sapl + PGDATA : /var/lib/postgresql/data/ + volumes: + - sapldb_data:/var/lib/postgresql/data/ + ports: + - "5435:5432" +saplredis: + image: redis:5.0.3-stretch + restart: always + ports: + - "6379:6379" +sapl: + #image: interlegis/sapl:master + build: . + dockerfile: Dockerfile.dev + restart: always + environment: + ADMIN_PASSWORD: interlegis + ADMIN_EMAIL: email@dominio.net + DEBUG: 'True' + EMAIL_PORT: 587 + EMAIL_USE_TLS: 'False' + EMAIL_HOST: smtp.dominio.net + EMAIL_HOST_USER: usuariosmtp + EMAIL_SEND_USER: usuariosmtp + EMAIL_HOST_PASSWORD: senhasmtp + USE_CHANNEL_LAYERS: 'True' + PORT_CHANNEL_LAYERS: 6379 + HOST_CHANNEL_LAYERS: saplredis + TZ: America/Sao_Paulo + volumes: + - ./sapl:/var/interlegis/sapl/sapl + links: + - sapldb + - saplredis + ports: + - "80:80" diff --git a/docker-compose.yml b/docker-compose.yml index ecbbcad76..bdb7694a0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,6 @@ sapldb: - sapldb_data:/var/lib/postgresql/data/ ports: - "5432:5432" - saplredis: image: redis:5.0.3-stretch restart: always diff --git a/docs/instalacao31.rst b/docs/instalacao31.rst index 43a1c4de6..afc7f09a7 100644 --- a/docs/instalacao31.rst +++ b/docs/instalacao31.rst @@ -1,6 +1,23 @@ Instalação do Ambiente de Desenvolvimento ========================================= +**Opção desenvolver utilizando docker-composer:** + +* Instale docker e docker-composer + + * `Docker `_ + * `Docker-composer `_ + + +* Rode o docker-compose para desenvolvimento: + +:: + + docker-compose -f ./docker-compose.dev.yml up --build + + +**Opção desenvolver utilizando máquina local** + * Procedimento testado nos seguintes SO's: * `Ubuntu 16.04 64bits `_; diff --git a/start_devel.sh b/start_devel.sh new file mode 100644 index 000000000..07a8a1c38 --- /dev/null +++ b/start_devel.sh @@ -0,0 +1,107 @@ +#!/bin/bash + +create_env() { + echo "[ENV FILE] creating .env file..." + + KEY=`python3 genkey.py` + + FILENAME="/var/interlegis/sapl/sapl/.env" + + if [ -z "${DATABASE_URL:-}" ]; then + DATABASE_URL="postgresql://sapl:sapl@sapldb:5432/sapl" + fi + + touch $FILENAME + + + # explicitly use '>' to erase any previous content + echo "SECRET_KEY="$KEY > $FILENAME + # now only appends + echo "DATABASE_URL = "$DATABASE_URL >> $FILENAME + echo "DEBUG = ""${DEBUG-False}" >> $FILENAME + echo "EMAIL_USE_TLS = ""${USE_TLS-True}" >> $FILENAME + echo "EMAIL_PORT = ""${EMAIL_PORT-587}" >> $FILENAME + echo "EMAIL_HOST = ""${EMAIL_HOST-''}" >> $FILENAME + echo "EMAIL_HOST_USER = ""${EMAIL_HOST_USER-''}" >> $FILENAME + echo "EMAIL_HOST_PASSWORD = ""${EMAIL_HOST_PASSWORD-''}" >> $FILENAME + echo "EMAIL_SEND_USER = ""${EMAIL_HOST_USER-''}" >> $FILENAME + echo "DEFAULT_FROM_EMAIL = ""${EMAIL_HOST_USER-''}" >> $FILENAME + echo "SERVER_EMAIL = ""${EMAIL_HOST_USER-''}" >> $FILENAME + echo "USE_SOLR = ""${USE_SOLR-False}" >> $FILENAME + echo "SOLR_COLLECTION = ""${SOLR_COLLECTION-sapl}" >> $FILENAME + echo "SOLR_URL = ""${SOLR_URL-http://localhost:8983}" >> $FILENAME + echo "USE_CHANNEL_LAYERS = ""${USE_CHANNEL_LAYERS-True}" >> $FILENAME + echo "PORT_CHANNEL_LAYERS = ""${PORT_CHANNEL_LAYERS-6379}" >> $FILENAME + echo "HOST_CHANNEL_LAYERS = ""${HOST_CHANNEL_LAYERS-'saplredis'}" >> $FILENAME + echo "[ENV FILE] done." +} + +create_env +chmod 777 /var/interlegis/sapl/sapl/.env + +/bin/bash busy-wait.sh $DATABASE_URL + +yes yes | python3 manage.py migrate + + +## SOLR +USE_SOLR="${USE_SOLR:=False}" +SOLR_URL="${SOLR_URL:=http://localhost:8983}" +SOLR_COLLECTION="${SOLR_COLLECTION:=sapl}" + +NUM_SHARDS=${NUM_SHARDS:=1} +RF=${RF:=1} +MAX_SHARDS_PER_NODE=${MAX_SHARDS_PER_NODE:=1} + +if [ "${USE_SOLR-False}" == "True" ] || [ "${USE_SOLR-False}" == "true" ]; then + + echo "SOLR configurations" + echo "===================" + echo "URL: $SOLR_URL" + echo "COLLECTION: $SOLR_COLLECTION" + echo "NUM_SHARDS: $NUM_SHARDS" + echo "REPLICATION FACTOR: $RF" + echo "MAX SHARDS PER NODE: $MAX_SHARDS_PER_NODE" + echo "=========================================" + + /bin/bash check_solr.sh $SOLR_URL + + python3 solr_api.py -u $SOLR_URL -c $SOLR_COLLECTION -s $NUM_SHARDS -rf $RF -ms $MAX_SHARDS_PER_NODE & + # python3 manage.py rebuild_index --noinput & +else + echo "Suporte a SOLR não inicializado." +fi + +echo "Criando usuário admin..." + +user_created=$(python3 create_admin.py 2>&1) + +echo $user_created + +cmd=$(echo $user_created | grep 'ADMIN_USER_EXISTS') +user_exists=$? + +cmd=$(echo $user_created | grep 'MISSING_ADMIN_PASSWORD') +lack_pwd=$? + +if [ $user_exists -eq 0 ]; then + echo "[SUPERUSER CREATION] User admin already exists. Not creating" +fi + +if [ $lack_pwd -eq 0 ]; then + echo "[SUPERUSER] Environment variable $ADMIN_PASSWORD for superuser admin was not set. Leaving container" + # return -1 +fi + +echo "-------------------------------------" +echo "| ███████╗ █████╗ ██████╗ ██╗ |" +echo "| ██╔════╝██╔══██╗██╔══██╗██║ |" +echo "| ███████╗███████║██████╔╝██║ |" +echo "| ╚════██║██╔══██║██╔═══╝ ██║ |" +echo "| ███████║██║ ██║██║ ███████╗ |" +echo "| ╚══════╝╚═╝ ╚═╝╚═╝ ╚══════╝ |" +echo "-------------------------------------" + +python3 manage.py collectstatic --noinput --clear + +python3 manage.py runserver 0.0.0.0:80