diff --git a/.travis.yml b/.travis.yml index ac8e19b06..f9ef2fe97 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: python python: - - 3.6 + - 3.7 services: - postgresql diff --git a/Dockerfile b/docker/Dockerfile similarity index 82% rename from Dockerfile rename to docker/Dockerfile index 49d819847..69ef33de3 100644 --- a/Dockerfile +++ b/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 diff --git a/Dockerfile.dev b/docker/Dockerfile.dev similarity index 85% rename from Dockerfile.dev rename to docker/Dockerfile.dev index 43b636abc..8d265bf4d 100644 --- a/Dockerfile.dev +++ b/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 && \ diff --git a/busy-wait.sh b/docker/busy-wait.sh old mode 100644 new mode 100755 similarity index 100% rename from busy-wait.sh rename to docker/busy-wait.sh diff --git a/check_solr.sh b/docker/check_solr.sh similarity index 100% rename from check_solr.sh rename to docker/check_solr.sh diff --git a/config/env-sample b/docker/config/env-sample similarity index 73% rename from config/env-sample rename to docker/config/env-sample index aeb8c38c4..1763499cc 100644 --- a/config/env-sample +++ b/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 diff --git a/config/env_dockerfile b/docker/config/env_dockerfile similarity index 71% rename from config/env_dockerfile rename to docker/config/env_dockerfile index 134beb274..4b564ee6c 100644 --- a/config/env_dockerfile +++ b/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 diff --git a/docker/config/env_test b/docker/config/env_test new file mode 100644 index 000000000..ccb203867 --- /dev/null +++ b/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 = '' diff --git a/config/nginx/nginx.conf b/docker/config/nginx/nginx.conf similarity index 100% rename from config/nginx/nginx.conf rename to docker/config/nginx/nginx.conf diff --git a/config/nginx/sapl.conf b/docker/config/nginx/sapl.conf similarity index 100% rename from config/nginx/sapl.conf rename to docker/config/nginx/sapl.conf diff --git a/create_admin.py b/docker/create_admin.py similarity index 100% rename from create_admin.py rename to docker/create_admin.py diff --git a/docker-compose-dev.yml b/docker/docker-compose-dev.yml similarity index 100% rename from docker-compose-dev.yml rename to docker/docker-compose-dev.yml diff --git a/docker/docker-compose-test.yml b/docker/docker-compose-test.yml new file mode 100644 index 000000000..0bd76edf1 --- /dev/null +++ b/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: diff --git a/docker-compose.yml b/docker/docker-compose.yml similarity index 85% rename from docker-compose.yml rename to docker/docker-compose.yml index c23056b4d..0367cb1a0 100644 --- a/docker-compose.yml +++ b/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 diff --git a/docker-env.sh b/docker/docker-env.sh similarity index 100% rename from docker-env.sh rename to docker/docker-env.sh diff --git a/genkey.py b/docker/genkey.py similarity index 100% rename from genkey.py rename to docker/genkey.py diff --git a/gunicorn_start.sh b/docker/gunicorn_start.sh similarity index 100% rename from gunicorn_start.sh rename to docker/gunicorn_start.sh diff --git a/scripts_docker/remove-all-containers.sh b/docker/scripts_docker/remove-all-containers.sh similarity index 100% rename from scripts_docker/remove-all-containers.sh rename to docker/scripts_docker/remove-all-containers.sh diff --git a/scripts_docker/remove-db.sh b/docker/scripts_docker/remove-db.sh similarity index 100% rename from scripts_docker/remove-db.sh rename to docker/scripts_docker/remove-db.sh diff --git a/scripts_docker/restore-db.sh b/docker/scripts_docker/restore-db.sh similarity index 100% rename from scripts_docker/restore-db.sh rename to docker/scripts_docker/restore-db.sh diff --git a/scripts_docker/shell_sapl.sh b/docker/scripts_docker/shell_sapl.sh similarity index 100% rename from scripts_docker/shell_sapl.sh rename to docker/scripts_docker/shell_sapl.sh diff --git a/simple_gunicorn.sh b/docker/simple_gunicorn.sh similarity index 100% rename from simple_gunicorn.sh rename to docker/simple_gunicorn.sh diff --git a/solr_api.py b/docker/solr_api.py similarity index 100% rename from solr_api.py rename to docker/solr_api.py diff --git a/start.sh b/docker/start.sh similarity index 100% rename from start.sh rename to docker/start.sh diff --git a/docker/travis.yml.docker b/docker/travis.yml.docker new file mode 100644 index 000000000..9777e47a4 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/health_check.py b/health_check.py deleted file mode 100644 index 0a050f5fb..000000000 --- a/health_check.py +++ /dev/null @@ -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() \ No newline at end of file diff --git a/release.sh b/release.sh index 0be28cb1a..f22d2b19b 100755 --- a/release.sh +++ b/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 diff --git a/sapl/.env_test b/sapl/.env_test index 616909348..834c44985 100644 --- a/sapl/.env_test +++ b/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