Skip to content

Commit 7dad94f

Browse files
committed
Revert "Revert "OpenConceptLab/ocl_issues#897 Run OCL API using gunicorn""
This reverts commit a7e9392.
1 parent f974543 commit 7dad94f

3 files changed

Lines changed: 40 additions & 8 deletions

File tree

Dockerfile

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,37 @@
1-
FROM python:3.8.3
1+
FROM python:3.9.6-alpine as builder
22
ENV PYTHONUNBUFFERED 1
3+
ENV PYTHONDONTWRITEBYTECODE 1
34
ARG SOURCE_COMMIT
5+
6+
RUN apk update && apk upgrade && \
7+
apk add --no-cache bash git gcc openssl-dev libffi-dev postgresql-dev python3-dev musl-dev cargo
8+
9+
RUN pip install --upgrade pip
10+
411
RUN mkdir /code
5-
ADD requirements.txt /code/
612
WORKDIR /code
7-
RUN pip install packaging
8-
RUN pip install -r requirements.txt
9-
ADD . /code/
13+
ADD requirements.txt /code/
14+
15+
RUN pip wheel --no-cache-dir --wheel-dir /code/wheels -r requirements.txt
16+
17+
FROM python:3.9.6-alpine
18+
19+
RUN addgroup -S ocl && adduser -S ocl -G ocl
20+
21+
ENV APP_HOME=/home/ocl/code
22+
23+
RUN mkdir -p $APP_HOME
24+
WORKDIR $APP_HOME
25+
26+
RUN apk update && apk add --no-cache libpq bash
27+
COPY --from=builder /code/wheels /wheels
28+
COPY --from=builder /code/requirements.txt .
29+
RUN pip install --no-cache /wheels/*
30+
RUN rm -rf /wheels
31+
32+
ADD --chown=ocl:ocl . $APP_HOME
33+
34+
USER ocl
1035

1136
RUN chmod +x set_build_version.sh
1237
RUN ["bash", "-c", "./set_build_version.sh"]
@@ -17,4 +42,5 @@ RUN chmod +x start_celery_worker.sh
1742
RUN chmod +x ping_celery_worker.sh
1843
RUN chmod +x start_flower.sh
1944
EXPOSE 8000
45+
2046
CMD ["bash", "-c", "./startup.sh"]

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Django==3.1.12
22
psycopg2==2.8.5
3+
gunicorn==20.1.0
34
djangorestframework==3.11.2
45
pylint==2.5.3
56
pydash==4.8.0
@@ -17,7 +18,7 @@ celery[redis]==4.4.7
1718
celery_once==3.0.1
1819
flower==0.9.5
1920
redis==3.5.3
20-
kombu==4.5.0
21+
kombu==4.6.11
2122
django-elasticsearch-dsl==7.1.4
2223
drf-yasg==1.17.1
2324
git+https://github.com/snyaggarwal/django-queryset-csv

startup.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,10 @@ python manage.py import_lookup_values
2121
echo "Populating text from extras.about"
2222
python manage.py populate_text_from_extras_about
2323

24-
echo "Starting up the server"
25-
python manage.py runserver 0.0.0.0:${API_PORT:-8000}
24+
if [[ "$ENVIRONMENT" = "development" ]]; then
25+
echo "Starting up the development server"
26+
python manage.py runserver 0.0.0.0:${API_PORT:-8000}
27+
else
28+
echo "Starting up the production server"
29+
gunicorn core.wsgi:application --bind 0.0.0.0:${API_PORT:-8000}
30+
fi

0 commit comments

Comments
 (0)