Skip to content

Commit

Permalink
Moving from uwsgi to gunicorn
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas-C committed Nov 9, 2021
1 parent 12a02a2 commit bfce59a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
14 changes: 5 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions gunicorn_conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
loglevel = "debug"
errorlog = "-" # stderr
accesslog = "-" # stdout
worker_tmp_dir = "/dev/shm"
graceful_timeout = 120
timeout = 120
keepalive = 5
threads = 10
3 changes: 0 additions & 3 deletions entrypoint.sh → prestart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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
9 changes: 7 additions & 2 deletions sonar/data/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def get_list_projects(sonar):

response = sonar.req.do_get(url)
if response.status_code != 200:
return projects, project_info, list_status
print(response.text)
response.raise_for_status()

raw_data = response.json()

Expand All @@ -86,7 +87,8 @@ def get_list_projects(sonar):

response = sonar.req.do_get(url, params=params)
if response.status_code != 200:
continue
print(response.text)
response.raise_for_status()

page_data = response.json()

Expand Down Expand Up @@ -121,6 +123,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:
Expand Down

0 comments on commit bfce59a

Please sign in to comment.