-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
we are more produciton-ready with this commit than ever
- Loading branch information
Showing
11 changed files
with
248 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# This is in .env because all the services need it. | ||
REDIS_HOST=redis | ||
REDIS_PORT=6739 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.tar.gz filter=lfs diff=lfs merge=lfs -text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
version: '3.7' | ||
|
||
services: | ||
web: | ||
image: openframing_web_image | ||
build: | ||
context: ./services/web | ||
expose: | ||
- "5000" | ||
volumes: | ||
- frontend_volume:/home/app/web/frontend/ | ||
- project_data_volume:/home/app/project_data_directory | ||
- transformers_cache_volume:/home/app/transformers_cache_directory | ||
depends_on: | ||
- redis | ||
environment: # Pass down from .env file | ||
- REDIS_HOST | ||
- REDIS_PORT | ||
nginx: | ||
build: ./services/nginx | ||
volumes: | ||
- frontend_volume:/home/app/frontend | ||
ports: | ||
- "80:80" | ||
depends_on: | ||
- web | ||
redis: | ||
image: redis:6.0.5-alpine | ||
command: "redis-server --port ${REDIS_PORT}" | ||
expose: | ||
- "${REDIS_PORT}" | ||
|
||
classifiers_worker: | ||
image: openframing_web_image | ||
command: [ "rq", "worker", "--url", "redis://${REDIS_HOST}:${REDIS_PORT}", "classifiers" ] | ||
depends_on: | ||
- redis | ||
environment: # Pass down from .env file | ||
- REDIS_HOST | ||
- REDIS_PORT | ||
# We need to pass them here, in addition to `command` above, because the | ||
# worker will import settings.py, which needs them to be set. | ||
|
||
topic_model_worker: | ||
image: openframing_web_image | ||
command: [ "rq", "worker", "--url", "redis://${REDIS_HOST}:${REDIS_PORT}", "topic_models" ] | ||
depends_on: | ||
- redis | ||
environment: | ||
- REDIS_HOST | ||
- REDIS_PORT | ||
# We need to pass them here, in addition to `command` above, because the | ||
# worker will import settings.py, which needs them to be set. | ||
|
||
|
||
|
||
volumes: | ||
frontend_volume: | ||
project_data_volume: | ||
transformers_cache_volume: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
FROM nginx:1.19.0-alpine | ||
|
||
RUN rm -f /etc/nginx/conf.d/default.conf | ||
COPY nginx.conf /etc/nginx/conf.d/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
upstream backend { | ||
server web:5000; | ||
} | ||
|
||
server { | ||
|
||
listen 80; | ||
|
||
location /api { | ||
proxy_pass http://backend; | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header Host $host; | ||
proxy_redirect off; | ||
} | ||
|
||
location / { | ||
alias /home/app/frontend/; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# For the uploaded files and model weights | ||
project_data/ | ||
transformers_cache/ | ||
|
||
# For the database | ||
sqlite.db | ||
|
||
# vim related | ||
Session.vim | ||
|
||
# related to virt env openFraming | ||
openFraming | ||
venv | ||
|
||
# py cache and swap files | ||
*.pyc | ||
*.swp | ||
|
||
# Python/mypy related | ||
__pycache__/ | ||
.mypy_cache/ | ||
.dmypy.json | ||
|
||
instance/ | ||
|
||
.pytest_cache/ | ||
.coverage | ||
htmlcov/ | ||
|
||
.idea | ||
|
||
# OSX related files | ||
.DS_Store | ||
|
||
|
||
dist/ | ||
build/ | ||
*.egg-info/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Using Multistage builds to make the final image smaller. | ||
|
||
#### Stage one ##### | ||
FROM python:3.8-slim-buster as builder | ||
|
||
# set work directory | ||
WORKDIR /usr/src/app | ||
|
||
# set environment variables | ||
ENV PYTHONDONTWRITEBYTECODE 1 | ||
ENV PYTHONUNBUFFERED 1 | ||
|
||
COPY ./backend/requirements_no_gpu.txt . | ||
RUN pip wheel \ | ||
--no-cache-dir \ | ||
--no-deps \ | ||
--wheel-dir \ | ||
/usr/src/app/wheels -r requirements_no_gpu.txt | ||
|
||
|
||
### Stage two ##### | ||
FROM python:3.8-slim-buster | ||
|
||
# create the app user | ||
RUN groupadd -r app -g 999 && useradd -r -g app -u 999 app | ||
|
||
## install dependencies | ||
COPY --from=builder /usr/src/app/wheels /wheels | ||
RUN pip install --no-cache /wheels/* | ||
|
||
# Install Gosu | ||
RUN set -eux; \ | ||
apt-get update; \ | ||
apt-get install -y gosu; \ | ||
rm -rf /var/lib/apt/lists/*; \ | ||
# verify that the binary works | ||
gosu nobody true | ||
|
||
# create directory for the app user | ||
ENV HOME=/home/app | ||
RUN mkdir -p $HOME | ||
|
||
# Prepare mallet installation | ||
ADD mallet-2.0.8.tar.gz $HOME/ | ||
ENV MALLET_BIN_DIRECTORY=$HOME/mallet-2.0.8/bin | ||
# Prepare project data directory, this is actually a volume | ||
# Handled by docker-compose.yml | ||
ENV PROJECT_DATA_DIRECTORY=$HOME/project_data_directory | ||
# This is similarly a volume. | ||
ENV TRANSFORMERS_CACHE_DIRECTORY=$HOME/transformers_cache_directory | ||
# Flask env to make sure flask doesn't serve | ||
# static files | ||
ENV FLASK_ENV=production | ||
|
||
# Setup th app directory | ||
ENV APP_HOME=/home/app/web | ||
RUN mkdir $APP_HOME | ||
# copy project | ||
COPY . $APP_HOME | ||
|
||
# Make sure the volumes are owned by the app user | ||
RUN mkdir -p $PROJECT_DATA_DIRECTORY && chown app:app $PROJECT_DATA_DIRECTORY | ||
VOLUME $PROJECT_DATA_DIRECTORY | ||
RUN mkdir -p $TRANSFORMERS_CACHE_DIRECTORY && chown app:app $TRANSFORMERS_CACHE_DIRECTORY | ||
VOLUME $TRANSFORMERS_CACHE_DIRECTORY | ||
|
||
# chown all the files to the app user | ||
RUN chown -R app:app $HOME | ||
# change to the app user | ||
USER app | ||
|
||
# Needed because all the python imports look like | ||
# from flask_app import ... | ||
# and not from backend.flask_app import ... | ||
WORKDIR $APP_HOME/backend/ | ||
|
||
CMD [ "gunicorn", "-w", "4", "-b", "0.0.0.0:5000", "flask_app.app:create_app()" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Git LFS file not shown