Skip to content

Commit

Permalink
Merge pull request #67 from ojonathacardoso/master
Browse files Browse the repository at this point in the history
Release: 3.1.0
  • Loading branch information
ojonathacardoso authored May 18, 2022
2 parents b0fde8d + 0ae9a5c commit 8a87283
Show file tree
Hide file tree
Showing 64 changed files with 2,983 additions and 261 deletions.
12 changes: 9 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SAAP - Sistema de Apoio à Atividade Parlamentar

Esta página reúne informações úteis sobre o desenvolvimento atual do SAAP.

Isso significa que toda a informação aqui apresentada aplica-se apenas para a versão 3.0.1 e superior.
Isso significa que toda a informação aqui apresentada aplica-se apenas para a versão 3.1.0 e superior.


Desenvolvimento
Expand All @@ -17,12 +17,16 @@ Deploy
`Deploy SAAP com Nginx + Gunicorn <https://github.com/interlegis/saap/blob/master/docs/deploy.rst>`_


Docker
=========================================
`Container SAAP + Postgres <https://github.com/interlegis/saap/blob/master/docs/docker.rst>`_


Tradução
=========================================
`Instruções para Tradução <https://github.com/interlegis/saap/blob/master/docs/traducao.rst>`_



Implementação
=========================================
`Instruções para Implementação e Testes <https://github.com/interlegis/saap/blob/master/docs/implementacoes.rst>`_
Expand Down Expand Up @@ -51,4 +55,6 @@ Referências

Estes guias, o projeto e as configurações do ambiente foram desenvolvidos, corrigidos e aperfeiçoados a partir do fork de `Jonatha Cardoso <https://github.com/ojonathacardoso/saap>`_ (servidor na `Câmara Municipal de Novo Hamburgo/RS <http://portal.camaranh.rs.gov.br>`_).

O mesmo teve como ponto de partida o projeto original do SAAP, desenvolvido por `Leandro Silva <https://github.com/LeandroJatai>`_ (servidor na `Câmara Municipal de Jataí/GO <https://www.jatai.go.leg.br>`_) e `Ramiro Luz <https://github.com/ramiroluz>`_ (servidor na `Câmara Municipal de Curitiba/PR <https://www.curitiba.pr.leg.br/>`_)
O mesmo teve como ponto de partida o projeto original do SAAP, desenvolvido por `Leandro Silva <https://github.com/LeandroJatai>`_ (servidor na `Câmara Municipal de Jataí/GO <https://www.jatai.go.leg.br>`_) e `Ramiro Luz <https://github.com/ramiroluz>`_ (servidor na `Câmara Municipal de Curitiba/PR <https://www.curitiba.pr.leg.br/>`_).

Para testar o SAAP, basta acessar a `versão de demonstração <http://saap-demo.camaranh.rs.gov.br>`.
98 changes: 98 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
FROM python:3.7-slim-buster

# Define o mantenedor da imagem
LABEL maintainer="Interlegis"

ENV DEBIAN_FRONTEND noninteractive

# Configura o sistema para usar UTF-8
RUN apt-get update -y &&\
apt-get install -y locales &&\
rm -rf /var/lib/apt/lists/* &&\
localedef -i pt_BR -c -f UTF-8 -A /usr/share/locale/locale.alias pt_BR.UTF-8

ENV LANG pt_BR.UTF-8
ENV LC_ALL pt_BR.UTF-8

# Pacotes usados na construcao da imagem
ENV BUILD_PACKAGES apt-utils apt-file build-essential dialog graphviz-dev \
libpq-dev libxml2-dev libjpeg-dev libssl-dev libcairo2-dev \
libffi-dev libxslt1-dev libmagic-dev libfreetype6-dev \
pkg-config python3-setuptools python3-pip python3-dev software-properties-common

# Pacotes usados na execucao da imagem
ENV RUN_PACKAGES antiword bash curl default-jre fontconfig git graphviz jq \
python python3-lxml python3-magic python3-psycopg2 python3-venv \
nginx nodejs poppler-utils postgresql-client sudo ttf-dejavu tzdata vim

# Instalacao dos pacotes
RUN apt-get update -y &&\
apt-get upgrade -y && \
apt-get install -y --no-install-recommends $BUILD_PACKAGES $RUN_PACKAGES &&\
fc-cache -fv

# Instalacao do Bower e Node.js
RUN curl -fsSL https://deb.nodesource.com/setup_12.x | sudo -E bash - &&\
sudo apt-get install -y nodejs &&\
curl -L https://npmjs.org/install.sh | sudo sh &&\
sudo npm install npm -g &&\
sudo npm install bower -g

ENV SAAPDIR=/var/interlegis/saap

# Instalacao do ambiente virtual
RUN pip install virtualenvwrapper

# Clone do projeto do Github
RUN sudo mkdir -p /var/interlegis &&\
sudo git clone https://github.com/interlegis/saap $SAAPDIR

# Instalacao dos requerimentos
RUN pip install --ignore-installed --no-cache-dir -r /var/interlegis/saap/requirements/requirements.txt

# Remocao dos pacotes usados na construcao da imagem
RUN SUDO_FORCE_REMOVE=yes apt-get purge -y --auto-remove $BUILD_PACKAGES &&\
apt-get autoremove && apt-get clean && rm -rf /var/lib/apt/lists/*

WORKDIR /var/interlegis/saap
ADD . /var/interlegis/saap

# Correcao da configuracao de alguns pacotes e requerimentos
CMD rm /usr/local/lib/python*/site-packages/rest_framework/* -R
RUN cp /var/interlegis/saap/config/django_db_models/base.py /usr/local/lib/python*/site-packages/django/db/models/
RUN cp /var/interlegis/saap/config/django_core_management/base.py /usr/local/lib/python*/site-packages/django/core/management/
RUN cp /var/interlegis/saap/config/rest_framework/* /usr/local/lib/python*/site-packages/rest_framework/ -R
RUN cp /var/interlegis/saap/config/bootstrap_admin/filter.html /usr/local/lib/python*/site-packages/bootstrap_admin/templates/admin/
RUN cp /var/interlegis/saap/config/smart-selects/* /usr/local/lib/python*/site-packages/smart_selects/static/smart-selects/admin/js/
RUN cp /var/interlegis/saap/config/reportlab/* /usr/local/lib/python*/site-packages/reportlab/platypus/
RUN cp /var/interlegis/saap/config/image_cropping/* /usr/local/lib/python*/site-packages/image_cropping

# Copia de arquivos usados na criacao da imagem
COPY start.sh $SAAPDIR
RUN chmod +x /var/interlegis/saap/start.sh
COPY busy-wait.sh $SAAPDIR
COPY create_admin.py $SAAPDIR

# Copia do arquivo .env e dos arquivos do Nginx
COPY config/env_dockerfile $SAAPDIR/.env
COPY config/saap.conf /etc/nginx/conf.d
COPY config/nginx.conf /etc/nginx/nginx.conf

# Configuracao dos arquivos de log
RUN ln -sf /dev/stdout /var/log/nginx/access.log &&\
ln -sf /dev/stderr /var/log/nginx/error.log &&\
mkdir /var/log/saap/ && touch /var/interlegis/saap/saap.log &&\
ln -s /var/interlegis/saap/saap.log /var/log/saap/saap.log

# Configuracao do bower e arquivos estaticos
RUN python3 manage.py bower install &&\
python3 manage.py collectstatic --noinput --clear

ENV DEBIAN_FRONTEND teletype

EXPOSE 80 8000

VOLUME ["/var/interlegis/saap/data", "/var/interlegis/saap/media"]

# Execucao do script de inicializacao
CMD ["/var/interlegis/saap/start.sh"]
10 changes: 10 additions & 0 deletions docker/busy-wait.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

while true; do
COUNT_PG=`psql $1 -c '\l \q' | grep saap | wc -l`
if ! [ "$COUNT_PG" -eq "0" ]; then
break
fi
echo "Waiting database setup..."
sleep 10
done
21 changes: 21 additions & 0 deletions docker/config/env_dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
DATABASE_URL = sqlite:///sapl.db
SECRET_KEY = 'mzp++@i1y-6y8ez_=^sfbr!dzuyry#^@v(3g^2d1k9%f=+mhlb'
DEBUG=False
DJANGO_TOOLBAR=False
SITE_NAME='Sistema de Apoio à Atividade Parlamentar'
SITE_DOMAIN='saap.camaranh.rs.gov.br'
EMAIL_USE_TLS=True
EMAIL_PORT=25
EMAIL_HOST=
EMAIL_SEND_USER=
EMAIL_HOST_USER=
EMAIL_HOST_PASSWORD=
DADOS_NOME='Câmara Municipal do Interlegis'
DADOS_ENDERECO='Av. N2, Bloco E - Senado Federal'
DADOS_MUNICIPIO='Brasília'
DADOS_UF='DF'
DADOS_CEP='70165-900'
DADOS_EMAIL='[email protected]'
DADOS_TELEFONE='(61) 3303-3221'
DADOS_SITE='interlegis.leg.br'
BRASAO_PROPRIO=False
37 changes: 37 additions & 0 deletions docker/config/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile off;
#tcp_nopush on;

keepalive_timeout 300;

proxy_connect_timeout 75s;
proxy_read_timeout 300s;

gzip on;
gzip_disable "MSIE [1-6]\\.(?!.*SV1)";
gzip_proxied any;
gzip_comp_level 5;
gzip_types text/plain text/css text/javascript application/javascript application/x-javascript text/xml application/xml application/rss+xml image/gif image/png image/x-icon image/jpeg image/svg+xml;
gzip_vary on;

include /etc/nginx/conf.d/*.conf;
}
22 changes: 22 additions & 0 deletions docker/config/saap.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
upstream saap {
server unix:/var/interlegis/saap/run/gunicorn.sock fail_timeout=0;
}

server {
listen 80;
server_name saap;

client_max_body_size 4G;

location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
}

location /static {
alias /var/interlegis/saap/collected_static/;
}

}
42 changes: 42 additions & 0 deletions docker/create_admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python
import os
import sys

import django

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "saap.settings")

def get_enviroment_admin_password(username):
password = os.environ.get('ADMIN_PASSWORD')
if not password:
#print(
# "[CREATE_SUPERUSER] Environment variable $ADMIN_PASSWORD"
# " for user %s was not set. Leaving...\n" % username)
sys.exit('MISSING_ADMIN_PASSWORD')
return password

def create_superuser():
from saap.core.models import User

email = os.environ.get('ADMIN_EMAIL', '')

if User.objects.filter(email=email).exists():
#print("[CREATE_SUPERUSER] User %s already exists."
# " Exiting without change.\n" % email)
sys.exit('ADMIN_USER_EXISTS')
else:
password = get_enviroment_admin_password(email)

print("[CREATE_SUPERUSER] Creating superuser...\n")

u = User.objects.create_superuser(
email=email, password=password)
u.save()

print("[CREATE_SUPERUSE] Done.\n")

sys.exit(0)

if __name__ == '__main__':
django.setup()
create_superuser()
66 changes: 66 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
version: "3.3"
services:
saapdb:
image: postgres:10.5-alpine
restart: always
container_name: postgres
labels:
NAME: "saapdb"
environment:
POSTGRES_PASSWORD: saap
POSTGRES_USER: saap
POSTGRES_DB: saap
PGDATA : /var/lib/postgresql/data/
volumes:
- saapdb_data:/var/lib/postgresql/data/
ports:
- "5433:5432"
networks:
- saap-net
saap:
image: interlegis/saap:latest
# build:
# context: .
# dockerfile: Dockerfile
container_name: saap
labels:
NAME: "saap"
restart: always
environment:
SITE_NAME: 'Sistema de Apoio à Atividade Parlamentar'
SITE_DOMAIN: 'saap.camaranh.rs.gov.br'
DEBUG: 'False'
DJANGO_TOOLBAR: 'False'
EMAIL_USE_TLS: 'True'
EMAIL_PORT: 25
EMAIL_HOST: ''
EMAIL_SEND_USER: ''
EMAIL_HOST_USER: ''
EMAIL_HOST_PASSWORD: ''
DADOS_NOME: 'Câmara Municipal de Saapópolis'
DADOS_ENDERECO: 'Av. XV de Novembro, 555'
DADOS_MUNICIPIO: 'Brasília'
DADOS_UF: 'DF'
DADOS_CEP: '70165-900'
DADOS_EMAIL: '[email protected]'
DADOS_TELEFONE: '(61) 3303-3221'
DADOS_SITE: 'https://www12.senado.leg.br/interlegis'
BRASAO_PROPRIO: 'True'
ADMIN_PASSWORD: saap_interlegis
ADMIN_EMAIL: [email protected]
volumes:
- saap_data:/var/interlegis/saap/data
- saap_media:/var/interlegis/saap/media
depends_on:
- saapdb
ports:
- "80:80"
networks:
- saap-net
networks:
saap-net:
driver: bridge
volumes:
saapdb_data:
saap_data:
saap_media:
Loading

0 comments on commit 8a87283

Please sign in to comment.