mirror of https://github.com/interlegis/sapl.git
Browse Source
* Adiciona dDocker baseado em Alpine-Python3 com Ngnix e Gunicorn * Atualiza docker-compose com gunicorn, ngnix e postgres * Ajusta gitignore para ignorar postgres-data * Adiciona script bash para conexao ao banco * Ajusta busy-wait.sh script para sincronizar o banco(postgres) com a aplicação django no docker * Add alias to sapldb * Refazer Dockerfile * Ajusta Dockerfile e docker-compose com entrypoint start.sh * Ajusta start.sh * Adiciona mais pontos de montagem. * Coloca start.sh como executável: chmod +x start.sh * Remove arquivo lixo * Substitui gen-env.py por shell script puro * Ajusta diretorio /var/interlegis/sapl e collect_static como volume no nginix * Simplifica criação de diretórios. * Adiciona ponto de montagem em postgres para importar dados * Adiciona mais parâmetros de ambiente UNIX para entrypoint dockerpull/802/merge
Edward
8 years ago
committed by
GitHub
16 changed files with 186 additions and 64 deletions
@ -1,53 +1,34 @@ |
|||||
FROM ubuntu:15.04 |
FROM alpine:3.5 |
||||
|
|
||||
RUN locale-gen en_US.UTF-8 |
ENV BUILD_PACKAGES postgresql-dev graphviz-dev graphviz build-base git pkgconfig \ |
||||
ENV LANG en_US.UTF-8 |
python3-dev libxml2-dev jpeg-dev libressl-dev libffi-dev libxslt-dev nodejs py3-lxml \ |
||||
ENV LANGUAGE en_US:en |
py3-magic postgresql-client vim |
||||
ENV LC_ALL en_US.UTF-8 |
|
||||
|
RUN apk add --no-cache python3 && \ |
||||
RUN mkdir /sapl |
python3 -m ensurepip && \ |
||||
|
rm -r /usr/lib/python*/ensurepip && \ |
||||
RUN echo "deb http://archive.ubuntu.com/ubuntu/ vivid universe" | tee -a "/etc/apt/sources.list" |
pip3 install --upgrade pip setuptools && \ |
||||
|
rm -r /root/.cache |
||||
RUN \ |
|
||||
apt-get update && \ |
RUN mkdir -p /var/interlegis/sapl &&\ |
||||
apt-get install -y -f \ |
apk add --update --no-cache $BUILD_PACKAGES && \ |
||||
software-properties-common \ |
npm install -g bower |
||||
libpq-dev \ |
|
||||
graphviz-dev \ |
|
||||
graphviz \ |
|
||||
build-essential \ |
|
||||
git \ |
|
||||
pkg-config \ |
|
||||
python3-dev \ |
|
||||
libxml2-dev \ |
|
||||
libjpeg-dev \ |
|
||||
libssl-dev \ |
|
||||
libffi-dev \ |
|
||||
libxslt1-dev \ |
|
||||
python3-setuptools \ |
|
||||
curl |
|
||||
|
|
||||
# use python3 in pip |
|
||||
RUN easy_install3 pip lxml |
|
||||
|
|
||||
# install nodejs |
|
||||
RUN DEBIAN_FRONTEND=noninteractive curl -sL https://deb.nodesource.com/setup_5.x | bash - |
|
||||
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y nodejs |
|
||||
|
|
||||
# install bower |
|
||||
RUN npm install -g bower |
|
||||
|
|
||||
# Bower aceitar root |
# Bower aceitar root |
||||
RUN touch /root/.bowerrc |
RUN touch /root/.bowerrc \ |
||||
RUN chmod 751 /root/.bowerrc |
&& chmod 751 /root/.bowerrc \ |
||||
RUN echo "{ \"allow_root\": true }" >> /root/.bowerrc |
&& echo "{ \"allow_root\": true }" >> /root/.bowerrc \ |
||||
|
&& npm cache clean |
||||
|
|
||||
|
WORKDIR /var/interlegis/sapl/ |
||||
|
|
||||
|
ADD . /var/interlegis/sapl/ |
||||
|
|
||||
WORKDIR /sapl |
COPY start.sh /var/interlegis/sapl/ |
||||
|
|
||||
ADD . /sapl |
RUN chmod +x /var/interlegis/sapl/start.sh |
||||
|
|
||||
RUN pip install -r requirements/dev-requirements.txt |
RUN pip install -r /var/interlegis/sapl/requirements/requirements.txt --upgrade setuptools |
||||
RUN pip install --upgrade setuptools |
|
||||
|
|
||||
# RUN python3 manage.py bower install |
VOLUME ["/var/interlegis/sapl/data", "/var/interlegis/sapl/media", "/var/interlegis/sapl/collected_static"] |
||||
|
ENTRYPOINT ["/var/interlegis/sapl/start.sh"] |
||||
|
@ -0,0 +1,10 @@ |
|||||
|
#!/bin/sh |
||||
|
|
||||
|
while true; do |
||||
|
COUNT_PG=`psql --dbname=postgresql://sapl:sapl@sapldb/sapl -c '\l \q' | grep sapl | wc -l` |
||||
|
if ! [ "$COUNT_PG" -eq "0" ]; then |
||||
|
break |
||||
|
fi |
||||
|
echo "Esperando Database Setup" |
||||
|
sleep 10 |
||||
|
done |
@ -0,0 +1,8 @@ |
|||||
|
DATABASE_URL = postgresql://postgres:@sapldb:/sapl |
||||
|
KEY |
||||
|
DEBUG = False |
||||
|
EMAIL_USE_TLS = True |
||||
|
EMAIL_PORT = 587 |
||||
|
EMAIL_HOST = '' |
||||
|
EMAIL_HOST_USER = '' |
||||
|
EMAIL_HOST_PASSWORD = '' |
@ -0,0 +1,39 @@ |
|||||
|
upstream sapl_server { |
||||
|
|
||||
|
server unix:/var/interlegis/sapl/run/gunicorn.sock fail_timeout=0; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
server { |
||||
|
|
||||
|
listen 80; |
||||
|
server_name sapl.test; |
||||
|
|
||||
|
client_max_body_size 4G; |
||||
|
|
||||
|
location /static/ { |
||||
|
alias /var/interlegis/sapl/collected_static/; |
||||
|
} |
||||
|
|
||||
|
location /media/ { |
||||
|
alias /var/interlegis/sapl/media/; |
||||
|
} |
||||
|
|
||||
|
location / { |
||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
||||
|
|
||||
|
proxy_set_header Host $http_host; |
||||
|
|
||||
|
proxy_redirect off; |
||||
|
|
||||
|
|
||||
|
if (!-f $request_filename) { |
||||
|
proxy_pass http://sapl_server; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
error_page 500 502 503 504 /500.html; |
||||
|
location = /500.html { |
||||
|
root /var/interlegis/sapl/sapl/static/; |
||||
|
} |
||||
|
} |
@ -1,17 +1,31 @@ |
|||||
localhost: |
server: |
||||
|
image: nginx:latest |
||||
|
ports: |
||||
|
- "80:80" |
||||
|
volumes: |
||||
|
- ./config/nginx:/etc/nginx/conf.d |
||||
|
- ./collected_static:/var/interlegis/sapl/collected_static |
||||
|
- ./media:/var/interlegis/sapl/media |
||||
|
volumes_from: |
||||
|
- web |
||||
|
sapldb: |
||||
image: postgres |
image: postgres |
||||
environment: |
environment: |
||||
POSTGRES_PASSWORD: sapl |
POSTGRES_PASSWORD: sapl |
||||
POSTGRES_USER: sapl |
POSTGRES_USER: sapl |
||||
POSTGRES_DB: sapl |
POSTGRES_DB: sapl |
||||
|
PGDATA : /var/lib/postgresql/data/ |
||||
|
volumes: |
||||
|
- ./postgres-data/data/:/var/lib/postgresql/data/ |
||||
|
- ./data:/data-import |
||||
ports: |
ports: |
||||
- "5532:5432" |
- "5532:5432" |
||||
web: |
web: |
||||
build: . |
build: . |
||||
command: /bin/sh -c "/bin/sh busy-wait.sh && python3 manage.py bower install && python3 manage.py migrate && /bin/sh gunicorn_start.sh /sapl" |
|
||||
volumes: |
volumes: |
||||
- .:/sapl |
- .:/var/interlegis/sapl/ |
||||
ports: |
- ./data:/var/interlegis/sapl/data |
||||
- "8000:8000" |
- ./media:/var/interlegis/sapl/media |
||||
|
- ./collected_static:/var/interlegis/sapl/collected_static |
||||
links: |
links: |
||||
- localhost |
- sapldb |
||||
|
@ -0,0 +1,6 @@ |
|||||
|
#/bin/bash |
||||
|
|
||||
|
KEY=`python gen-key.py` |
||||
|
echo $KEY |
||||
|
|
||||
|
sed -e "s/SECRET_KEY = None/SECRET_KEY = $KEY/g" config/env-sample |
@ -0,0 +1 @@ |
|||||
|
EMAIL_HOST_USER=foo |
@ -0,0 +1,7 @@ |
|||||
|
import random |
||||
|
|
||||
|
def generate_secret(): |
||||
|
return ''.join([random.SystemRandom().choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)]) |
||||
|
|
||||
|
if __name__ == '__main__': |
||||
|
print(generate_secret()) |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,2 +1,3 @@ |
|||||
#!/bin/bash |
#!/bin/bash |
||||
docker run -ti sapl_web /bin/bash |
|
||||
|
docker run --rm -ti sapl_web /bin/sh |
||||
|
@ -0,0 +1,53 @@ |
|||||
|
#!/bin/sh |
||||
|
|
||||
|
|
||||
|
create_env() { |
||||
|
# check if file exists |
||||
|
if [ -f "/var/interlegis/sapl/data/secret.key" ]; then |
||||
|
KEY=`cat /var/interlegis/sapl/data/secret.key` |
||||
|
else |
||||
|
KEY=`python3 genkey.py` |
||||
|
echo $KEY > data/secret.key |
||||
|
fi |
||||
|
|
||||
|
# TODO: rename env-test-bash to .env |
||||
|
FILENAME="/var/interlegis/sapl/sapl/.env" |
||||
|
|
||||
|
if [ -z "${DATABASE_URL:-}" ]; then |
||||
|
DATABASE_URL="postgresql://sapl:sapl@sapldb:5432/sapl" |
||||
|
fi |
||||
|
|
||||
|
# ALWAYS replace the content of .env variable |
||||
|
# If want to conditionally create only if absent then use IF below |
||||
|
# if [ ! -f $FILENAME ]; then |
||||
|
|
||||
|
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 "creating .env file..." |
||||
|
create_env |
||||
|
echo "done." |
||||
|
|
||||
|
# # python3 gen-env.py |
||||
|
|
||||
|
python3 manage.py bower install |
||||
|
|
||||
|
/bin/sh busy-wait.sh |
||||
|
|
||||
|
python3 manage.py migrate |
||||
|
python3 manage.py collectstatic --no-input |
||||
|
python3 manage.py rebuild_index --noinput |
||||
|
|
||||
|
/bin/sh gunicorn_start.sh |
Loading…
Reference in new issue