Browse Source

Refatora arquivos Docker (#3264)

* Refatora arquivos Docker

* Conserta runtime

* Retorna CI antigo

Co-authored-by: eribeiro <edwardr@senado.leg.br>
pull/3280/head
Edward 4 years ago
committed by GitHub
parent
commit
c5a2d97443
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      .travis.yml
  2. 18
      docker/Dockerfile
  3. 2
      docker/Dockerfile.dev
  4. 0
      docker/busy-wait.sh
  5. 0
      docker/check_solr.sh
  6. 2
      docker/config/env-sample
  7. 2
      docker/config/env_dockerfile
  8. 9
      docker/config/env_test
  9. 0
      docker/config/nginx/nginx.conf
  10. 0
      docker/config/nginx/sapl.conf
  11. 0
      docker/create_admin.py
  12. 0
      docker/docker-compose-dev.yml
  13. 75
      docker/docker-compose-test.yml
  14. 13
      docker/docker-compose.yml
  15. 0
      docker/docker-env.sh
  16. 0
      docker/genkey.py
  17. 0
      docker/gunicorn_start.sh
  18. 0
      docker/scripts_docker/remove-all-containers.sh
  19. 0
      docker/scripts_docker/remove-db.sh
  20. 0
      docker/scripts_docker/restore-db.sh
  21. 0
      docker/scripts_docker/shell_sapl.sh
  22. 0
      docker/simple_gunicorn.sh
  23. 0
      docker/solr_api.py
  24. 0
      docker/start.sh
  25. 38
      docker/travis.yml.docker
  26. 49
      health_check.py
  27. 6
      release.sh
  28. 2
      sapl/.env_test

2
.travis.yml

@ -1,7 +1,7 @@
language: python
python:
- 3.6
- 3.7
services:
- postgresql

18
Dockerfile → docker/Dockerfile

@ -33,11 +33,19 @@ RUN apt-get update && \
SUDO_FORCE_REMOVE=yes apt-get purge -y --auto-remove $BUILD_PACKAGES && \
apt-get autoremove && apt-get clean && rm -rf /var/lib/apt/lists/*
COPY start.sh /var/interlegis/sapl/
COPY config/nginx/sapl.conf /etc/nginx/conf.d
COPY config/nginx/nginx.conf /etc/nginx/nginx.conf
COPY config/env_dockerfile /var/interlegis/sapl/sapl/.env
ENV HOME=/var/interlegis/sapl
COPY docker/start.sh $HOME
COPY docker/check_solr.sh $HOME
COPY docker/solr_api.py $HOME
COPY docker/busy-wait.sh $HOME
COPY docker/create_admin.py $HOME
COPY docker/genkey.py $HOME
COPY docker/gunicorn_start.sh $HOME
COPY docker/config/nginx/sapl.conf /etc/nginx/conf.d
COPY docker/config/nginx/nginx.conf /etc/nginx/nginx.conf
COPY docker/config/env_dockerfile /var/interlegis/sapl/sapl/.env
RUN python3 manage.py collectstatic --noinput --clear

2
Dockerfile.dev → docker/Dockerfile.dev

@ -1,7 +1,7 @@
FROM python:3.6
ENV PYTHONUNBUFFERED 1
WORKDIR /sapl-dev
COPY requirements ./requirements/
COPY ../requirements ./requirements/
RUN apt update && \
apt -y install graphviz-dev && \
pip install --upgrade pip && \

0
busy-wait.sh → docker/busy-wait.sh

0
check_solr.sh → docker/check_solr.sh

2
config/env-sample → docker/config/env-sample

@ -1,5 +1,5 @@
DATABASE_URL = postgresql://postgres:@sapldb:/sapl
KEY
SECRET_KEY = 'mzp++@i1y-6y8ez_=^sfbr!dzuyry#^@v(3g^2d1k9%f=+mhlb'
DEBUG = False
EMAIL_USE_TLS = True
EMAIL_PORT = 587

2
config/env_dockerfile → docker/config/env_dockerfile

@ -1,5 +1,5 @@
DATABASE_URL = sqlite:///sapl.db
SECRET_KEY = 'Dockerfile_Key'
SECRET_KEY = 'mzp++@i1y-6y8ez_=^sfbr!dzuyry#^@v(3g^2d1k9%f=+mhlb'
DEBUG = False
EMAIL_USE_TLS = True
EMAIL_PORT = 587

9
docker/config/env_test

@ -0,0 +1,9 @@
DATABASE_URL=postgresql://sapl:sapl@sapldb:/sapl
SECRET_KEY=test++@i1y-6y8ez_=^sfbr!dzuyry#^@v(3g^2d1k9%f=+mhlb
DEBUG=False
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST = ''
EMAIL_HOST_USER = ''
EMAIL_SEND_USER = ''
EMAIL_HOST_PASSWORD = ''

0
config/nginx/nginx.conf → docker/config/nginx/nginx.conf

0
config/nginx/sapl.conf → docker/config/nginx/sapl.conf

0
create_admin.py → docker/create_admin.py

0
docker-compose-dev.yml → docker/docker-compose-dev.yml

75
docker/docker-compose-test.yml

@ -0,0 +1,75 @@
version: "3.7"
services:
sapldb:
image: postgres:10.5-alpine
restart: always
container_name: postgres
labels:
NAME: "postgres"
environment:
POSTGRES_PASSWORD: sapl
POSTGRES_USER: sapl
POSTGRES_DB: sapl
PGDATA : /var/lib/postgresql/data/
volumes:
- sapldb_data:/var/lib/postgresql/data/
ports:
- "5433:5432"
networks:
- sapl-net
saplsolr:
image: solr:8.3
restart: always
command: bin/solr start -c -f
container_name: solr
labels:
NAME: "solr"
volumes:
- solr_data:/opt/solr/server/solr
- solr_configsets:/opt/solr/server/solr/configsets
ports:
- "8983:8983"
networks:
- sapl-net
sapl:
build:
context: ../
dockerfile: ./docker/Dockerfile
container_name: sapl
labels:
NAME: "sapl"
restart: always
environment:
ADMIN_PASSWORD: interlegis
ADMIN_EMAIL: email@dominio.net
DEBUG: 'False'
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_SOLR: 'True'
SOLR_COLLECTION: sapl
SOLR_URL: http://saplsolr:8983
TZ: America/Sao_Paulo
volumes:
- sapl_data:/var/interlegis/sapl/data
- sapl_media:/var/interlegis/sapl/media
depends_on:
- sapldb
- saplsolr
ports:
- "80:80"
networks:
- sapl-net
networks:
sapl-net:
name: sapl-net
driver: bridge
volumes:
sapldb_data:
sapl_data:
sapl_media:
solr_data:
solr_configsets:

13
docker-compose.yml → docker/docker-compose.yml

@ -3,6 +3,9 @@ services:
sapldb:
image: postgres:10.5-alpine
restart: always
container_name: postgres
labels:
NAME: "postgres"
environment:
POSTGRES_PASSWORD: sapl
POSTGRES_USER: sapl
@ -18,6 +21,9 @@ services:
image: solr:8.3
restart: always
command: bin/solr start -c -f
container_name: solr
labels:
NAME: "solr"
volumes:
- solr_data:/opt/solr/server/solr
- solr_configsets:/opt/solr/server/solr/configsets
@ -27,7 +33,12 @@ services:
- sapl-net
sapl:
image: interlegis/sapl:3.1.161-RC13
#build: .
# build:
# context: ../
# dockerfile: ./docker/Dockerfile
container_name: sapl
labels:
NAME: "sapl"
restart: always
environment:
ADMIN_PASSWORD: interlegis

0
docker-env.sh → docker/docker-env.sh

0
genkey.py → docker/genkey.py

0
gunicorn_start.sh → docker/gunicorn_start.sh

0
scripts_docker/remove-all-containers.sh → docker/scripts_docker/remove-all-containers.sh

0
scripts_docker/remove-db.sh → docker/scripts_docker/remove-db.sh

0
scripts_docker/restore-db.sh → docker/scripts_docker/restore-db.sh

0
scripts_docker/shell_sapl.sh → docker/scripts_docker/shell_sapl.sh

0
simple_gunicorn.sh → docker/simple_gunicorn.sh

0
solr_api.py → docker/solr_api.py

0
start.sh → docker/start.sh

38
docker/travis.yml.docker

@ -0,0 +1,38 @@
sudo: required
services:
- docker
env:
global:
- DOCKER_COMPOSE_VERSION=1.26.2
before_install:
# Install latest versions of docker and docker-compose
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
- sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
- sudo apt-get update
- sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce
- sudo rm /usr/local/bin/docker-compose
- curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
- chmod +x docker-compose
- sudo mv docker-compose /usr/local/bin
- docker --version
- docker-compose --version
install:
- sudo service postgresql stop || true
script:
- cd $TRAVIS_BUILD_DIR/docker
# Build master images and run the webserver (tests end to end)
#- docker-compose -f docker-compose.test.yml build
#- docker-compose up -d
#- docker logs sapl
#- docker-compose rm -f -s -v
- docker-compose -f docker-compose-test.yml run --workdir="/var/interlegis/sapl" sapl bash -c "bash busy-wait.sh postgresql://sapl:sapl@sapldb:5432/sapl && cp docker/config/env_test .env && py.test --create-db"
after_script:
# Cleanup docker containers, images, and volumes
- docker-compose rm -f -s -v
- docker system prune -a -f --volumes

49
health_check.py

@ -1,49 +0,0 @@
from flask import Flask
import requests
import psycopg2
import json
from sapl.settings import DATABASES, USE_SOLR, SOLR_URL
app = Flask(__name__)
@app.route('/health')
def health():
try:
db = DATABASES['default']
conn = psycopg2.connect(host=db['HOST'],
user=db['USER'],
password=db['PASSWORD'],
database=db['NAME'],
port=db['PORT'])
cursor = conn.cursor()
cursor.execute("SELECT 1;")
resp = {'DATABASE': 'OK'}
except Exception as e:
resp = {'DATABASE': 'ERROR'}
finally:
if cursor:
cursor.close()
conn.close()
if USE_SOLR:
r = requests.get(SOLR_URL)
if r.ok:
resp.update({'SEARCH_ENGINE': 'OK'})
else:
resp.update({'SEARCH_ENGINE': 'ERROR'})
else:
resp.update({'SEARCH_ENGINE': 'NOT_ENABLED'})
return json.dumps(resp)
@app.route('/ping')
def ping():
return "pong"
if __name__ == '__main__':
app.run()

6
release.sh

@ -30,11 +30,11 @@ FINAL_VERSION=
function change_files {
OLD_VERSION=$(grep -E 'interlegis/sapl:'$VERSION_PATTERN docker-compose.yml | cut -d':' -f3)
OLD_VERSION=$(grep -E 'interlegis/sapl:'$VERSION_PATTERN docker/docker-compose.yml | cut -d':' -f3)
echo "Atualizando de "$OLD_VERSION" para "$FINAL_VERSION
sed -E -i "s|$OLD_VERSION|$FINAL_VERSION|g" docker-compose.yml
sed -E -i "s|$OLD_VERSION|$FINAL_VERSION|g" docker/docker-compose.yml
sed -E -i "s|$OLD_VERSION|$FINAL_VERSION|g" setup.py
@ -65,7 +65,7 @@ function set_rc_version {
function commit_and_push {
echo "committing..."
git add docker-compose.yml setup.py sapl/settings.py sapl/templates/base.html
git add docker/docker-compose.yml setup.py sapl/settings.py sapl/templates/base.html
git commit -m "Release: $FINAL_VERSION"
git tag $FINAL_VERSION

2
sapl/.env_test

@ -1,5 +1,5 @@
DATABASE_URL = postgresql://postgres:@sapldb:/sapl
SECRET_KEY=TravisTest
SECRET_KEY=test++@i1y-6y8ez_=^sfbr!dzuyry#^@v(3g^2d1k9%f=+mhlb
DEBUG=False
EMAIL_USE_TLS = True
EMAIL_PORT = 587

Loading…
Cancel
Save