diff --git a/.travis.yml b/.travis.yml index 68ce9ef15..bb9479315 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,11 +12,8 @@ env: global: - SECRET_KEY=SK - SUPPORTED_LANGUAGES="en|pt" - - DOCKER_IMAGE_NAME=ilha/bothub script: - flake8 - travis_wait coverage run manage.py test after_success: - coveralls - - export TAG=`if [ "$TRAVIS_BRANCH" == "master" ]; then echo "latest"; else echo $TRAVIS_BRANCH ; fi` - - '[[ $TRAVIS_EVENT_TYPE == "push" && $TRAVIS_BRANCH == "master" || $TRAVIS_EVENT_TYPE == "push" && $TRAVIS_BRANCH == "develop" ]] && docker login -u $DOCKER_HUB_USER -p $DOCKER_HUB_PASS && docker-compose -f docker/docker-compose.yml build && docker push $DOCKER_IMAGE_NAME:$TAG' diff --git a/docker/Dockerfile b/Dockerfile similarity index 53% rename from docker/Dockerfile rename to Dockerfile index b84e19682..5f5838b34 100644 --- a/docker/Dockerfile +++ b/Dockerfile @@ -3,8 +3,7 @@ FROM python:3.6-alpine3.7 ENV WORKDIR /home/app WORKDIR $WORKDIR -RUN apk update && apk upgrade -RUN apk add alpine-sdk postgresql-dev nodejs nginx +RUN apk update && apk add alpine-sdk postgresql-dev RUN pip install pipenv RUN pip install gunicorn @@ -16,9 +15,6 @@ COPY Pipfile.lock Pipfile.lock RUN pipenv install --system COPY . . -COPY ./docker/bothub-nginx.conf /etc/nginx/conf.d/default.conf -COPY ./docker/entrypoint.sh ./entrypoint.sh RUN chmod +x ./entrypoint.sh -EXPOSE 80 -ENTRYPOINT $WORKDIR/entrypoint.sh \ No newline at end of file +ENTRYPOINT [ "./entrypoint.sh" ] \ No newline at end of file diff --git a/README.md b/README.md index bb33a87d0..a7946dc17 100644 --- a/README.md +++ b/README.md @@ -66,12 +66,3 @@ You can set environment variables in your OS, write on ```.env``` file or pass v | BOTHUB_NLP_BASE_URL | ```string``` | ```http://localhost:2657/``` | The bothub-blp production application URL. Used to proxy requests. | CHECK_ACCESSIBLE_API_URL | ```string``` | ```http://localhost/api/repositories/``` | URL used by ```bothub.health.check.check_accessible_api``` to make a HTTP request. The response status code must be 200. | SEND_EMAILS | ```boolean``` | ```True``` | Send emails flag. - -### Docker Environment Variables - -| Variable | Type | Default | Description | -|--|--|--|--| -| BUILD_WEBAPP | ```boolean``` | ```true``` | Build webapp application in entrypoint. -| WEBAPP_REPO | ```string``` | ```https://github.com/Ilhasoft/bothub-webapp``` | bothub-webapp git repository URL. It will clone and run ```npm install && npm run build``` command on the entrypoint. This build is served by Nginx. -| WEBAPP_BRANCH | ```string``` | ```master``` | Specify the branch of the bothub-webapp Git repository. -| API_BASE_URL | ```string``` | Not defined | The bothub production application URL. Used by ```bothub-webapp``` application. diff --git a/bothub/settings.py b/bothub/settings.py index 3bb9cbeac..087eb8a6c 100644 --- a/bothub/settings.py +++ b/bothub/settings.py @@ -152,7 +152,6 @@ # cors headers CORS_ORIGIN_ALLOW_ALL = True -CORS_URLS_REGEX = r'^/api/.*$' # mail diff --git a/bothub/urls.py b/bothub/urls.py index 628f309ae..5bd685ab1 100644 --- a/bothub/urls.py +++ b/bothub/urls.py @@ -8,6 +8,7 @@ urlpatterns = [ + path('', include(bothub_api_routers.urls)), path('api/', include(bothub_api_routers.urls)), path('docs/', include_docs_urls(title='API Documentation')), path('admin/', admin.site.urls), diff --git a/docker/docker-compose.yml b/docker-compose.yml similarity index 84% rename from docker/docker-compose.yml rename to docker-compose.yml index 24bbffffe..231878261 100644 --- a/docker/docker-compose.yml +++ b/docker-compose.yml @@ -12,8 +12,8 @@ services: bothub: image: ${DOCKER_IMAGE_NAME:-ilha/bothub}:${TAG:-latest} build: - context: .. - dockerfile: docker/Dockerfile + context: . + dockerfile: Dockerfile ports: - 80:80 environment: @@ -36,10 +36,6 @@ services: - CSRF_COOKIE_SECURE=${CSRF_COOKIE_SECURE:-false} - BOTHUB_WEBAPP_BASE_URL=${BOTHUB_WEBAPP_BASE_URL:-http://localhost/} - BOTHUB_NLP_BASE_URL=${BOTHUB_NLP_BASE_URL:-http://localhost:2657/} - - BUILD_WEBAPP=${BUILD_WEBAPP:-true} - - WEBAPP_REPO=${WEBAPP_REPO:-https://github.com/Ilhasoft/bothub-webapp} - - WEBAPP_BRANCH=${WEBAPP_BRANCH:-master} - - API_BASE_URL=${API_BASE_URL:-/api} - CHECK_ACCESSIBLE_API_URL=${CHECK_ACCESSIBLE_API_URL} - SEND_EMAILS=${SEND_EMAILS:-true} - SUPPORTED_LANGUAGES=${SUPPORTED_LANGUAGES:-en|pt} diff --git a/docker/bothub-nginx.conf b/docker/bothub-nginx.conf deleted file mode 100644 index eae841f65..000000000 --- a/docker/bothub-nginx.conf +++ /dev/null @@ -1,31 +0,0 @@ -upstream bothub { - server unix:/tmp/bothub.sock; -} - -server { - listen 80 default_server; - listen [::]:80 default_server; - - root /tmp/bothub-webapp/dist; - index index.html; - - location / { - try_files $uri /index.html =404; - } - - location ~ ^/static { - try_files $uri @bothub; - } - - location ~ ^/(api|docs|admin|ping) { - proxy_redirect off; - proxy_pass $scheme://bothub; - proxy_set_header Host $http_host; - } - - location @bothub { - proxy_redirect off; - proxy_pass $scheme://bothub; - proxy_set_header Host $http_host; - } -} diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh deleted file mode 100644 index 3f3140847..000000000 --- a/docker/entrypoint.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh -if [ ${BUILD_WEBAPP} == true ]; then - git clone --branch $WEBAPP_BRANCH --depth 1 $WEBAPP_REPO /tmp/bothub-webapp/ - cd /tmp/bothub-webapp/ && npm install && npm run build -fi - -cd $WORKDIR -python manage.py migrate -python manage.py collectstatic --noinput - -GUNICORN_LOG_FILE="/var/log/gunicorn.log" -touch ${GUNICORN_LOG_FILE} -gunicorn bothub.wsgi -c docker/gunicorn.conf.py --log-file ${GUNICORN_LOG_FILE} --log-level debug --capture-output - -mkdir -p /run/nginx/ -nginx -tail -f /var/log/nginx/* ${GUNICORN_LOG_FILE} diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 000000000..fe4997e74 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,6 @@ +#!/bin/sh +cd $WORKDIR +python manage.py migrate +python manage.py collectstatic --noinput + +gunicorn bothub.wsgi -c gunicorn.conf.py diff --git a/docker/gunicorn.conf.py b/gunicorn.conf.py similarity index 73% rename from docker/gunicorn.conf.py rename to gunicorn.conf.py index 8286cfb84..36daa163d 100644 --- a/docker/gunicorn.conf.py +++ b/gunicorn.conf.py @@ -1,6 +1,5 @@ import multiprocessing -bind = 'unix:/tmp/bothub.sock' +bind = '0.0.0.0:80' workers = multiprocessing.cpu_count() * 2 + 1 raw_env = ['DJANGO_SETTINGS_MODULE=bothub.settings'] -daemon = True