diff --git a/Dockerfile b/Dockerfile index f3e2c93..f5ed902 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,8 @@ -FROM python:3.6-slim +FROM tiangolo/meinheld-gunicorn-flask:python3.8-alpine3.11 -RUN apt update && apt install -y build-essential -RUN groupadd --gid 1000 sonar-exporter -RUN useradd --uid 1000 --gid 1000 --create-home sonar-exporter -WORKDIR /home/sonar-exporter -USER sonar-exporter COPY . . -RUN pip3.6 install -r requirements.txt +RUN pip install --no-cache-dir -r requirements.txt -EXPOSE 9119 -ENTRYPOINT [ "/bin/bash", "entrypoint.sh" ] +RUN adduser --disabled-password 1001 +RUN chown -R 1001 . +USER 1001 diff --git a/gunicorn_conf.py b/gunicorn_conf.py new file mode 100644 index 0000000..dcc4edc --- /dev/null +++ b/gunicorn_conf.py @@ -0,0 +1,6 @@ +loglevel = "info" +errorlog = "-" # stderr +accesslog = "-" # stdout +worker_tmp_dir = "/dev/shm" +graceful_timeout = 120 +timeout = 120 diff --git a/entrypoint.sh b/prestart.sh similarity index 71% rename from entrypoint.sh rename to prestart.sh index d3b8267..cb788d5 100755 --- a/entrypoint.sh +++ b/prestart.sh @@ -11,6 +11,3 @@ fi if [ $SONAR_PASSWORD ]; then sed -i "s/password/$SONAR_PASSWORD/g" config.ini fi - -# Run exporter -.local/bin/uwsgi --http 0.0.0.0:${SONAR_EXPORTER_PORT:-9119} --wsgi-file main.py --callable app diff --git a/requirements.txt b/requirements.txt index 1cfeb6b..eeff9c8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ +# Workaround this issue: https://github.com/benoitc/gunicorn/issues/2564 +gunicorn==20.0.4 prometheus-client==0.6.0 requests==2.21.0 -uwsgi==2.0.20 flask==2.0.2 \ No newline at end of file diff --git a/sonar/data/projects.py b/sonar/data/projects.py index 6367b46..ad4fb6c 100644 --- a/sonar/data/projects.py +++ b/sonar/data/projects.py @@ -121,6 +121,9 @@ def standardize_project_info(project, sonar): params = {'projectKey': project_key} response = sonar.req.do_get(url=url, params=params) + if response.status_code != 200: + print(response.text) + response.raise_for_status() raw_data = response.json() if 'errors' in raw_data: