Skip to content

Commit

Permalink
fix: Changes according to PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakirG committed Mar 11, 2019
1 parent 902396a commit fa93051
Show file tree
Hide file tree
Showing 25 changed files with 415 additions and 411 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ cache:
# install dependencies
install:
- pip install pipenv
- pipenv install --dev
- pipenv install --skip-lock --dev
- pipenv graph

# run tests
script:
- cd tests
- export MANIFEST_SERVICE_CONFIG_PATH=../config.json
- python -m pytest -v

after_script:
Expand Down
24 changes: 13 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,45 +1,47 @@
# To run: docker run -v /path/to/wsgi.py:/var/www/manifest_service/wsgi.py --name=manifest_service -p 81:80 manifest_service
# To check running container: docker exec -it manifest_service /bin/bash
# To run: docker run -v /path/to/wsgi.py:/var/www/manifestservice/wsgi.py --name=manifestservice -p 81:80 manifestservice
# To check running container: docker exec -it manifestservice /bin/bash


FROM quay.io/cdis/python-nginx:master


ENV appname=manifest_service
RUN echo "7" && ls
ENV appname=manifestservice

# number of uwsgi worker processes
ENV UWSGI_CHEAPER 2

ENV WORKON_HOME=/.venv

RUN apk update \
&& apk add postgresql-libs postgresql-dev libffi-dev libressl-dev \
&& apk add linux-headers musl-dev gcc \
&& apk add curl bash git vim

RUN echo "17" && ls
COPY . /$appname
COPY ./deployment/uwsgi/uwsgi.ini /etc/uwsgi/uwsgi.ini
COPY ./deployment/uwsgi/wsgi.py /$appname/wsgi.py
COPY ./deployment/nginx/nginx.conf /etc/nginx/
COPY ./deployment/nginx/uwsgi.conf /etc/nginx/conf.d/nginx.conf
WORKDIR /$appname
RUN echo "24" && ls

RUN python -m pip install --upgrade pip \
&& python -m pip install --upgrade setuptools \
&& pip install -r requirements.txt --src /usr/local/lib/python3.6/site-packages/
RUN python -m pip install --upgrade pip && pip install pipenv && pipenv install

RUN echo "26" && ls
RUN mkdir -p /var/www/$appname \
&& mkdir -p /var/www/.cache/Python-Eggs/ \
&& mkdir /run/nginx/ \
&& ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log \
&& chown nginx -R /var/www/.cache/Python-Eggs/ \
&& chown nginx /var/www/$appname

RUN echo "34" && ls
EXPOSE 80

RUN echo "36"
RUN COMMIT=`git rev-parse HEAD` && echo "COMMIT=\"${COMMIT}\"" >$appname/version_data.py \
&& VERSION=`git describe --always --tags` && echo "VERSION=\"${VERSION}\"" >>$appname/version_data.py \
&& python setup.py install

WORKDIR /var/www/$appname

RUN echo "42" && ls
CMD /$appname/dockerrun.bash
18 changes: 11 additions & 7 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
pytest="*"
pytest-mock = "*"
pytest-flask = "*"
codacy-coverage = "*"
pytest="~=4.3"
pytest-mock="~=1.10"
pytest-flask="~=0.14.0"

[packages]
flask = "*"
authutils = "*"
boto3 = "*"
flask="~=0.10"
authutils="~=3.0"
boto3="~=1.9"

[requires]
python_version = "3.7"
python_version = "3.6"

[pipenv]
allow_prereleases = true
43 changes: 22 additions & 21 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 20 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,35 @@
### Overview
This service handles reading from and writing to a user's s3 folder containing their manifests. A manifest is a JSON file that lists records a researcher may be interested in analyzing. This service stores a manifest to a user folder in an s3 bucket and delivers it for later use, such as when the researcher wants to mount the manifest in their workspace.

Manifest files should contain JSON of the form

[
{
"object_id": "757508f5-2697-4700-a69f-89d173a4c514",
"subject_id": "da6a14a0-6498-4941-a1b2-bbe45a2ccac2"
},
{
"object_id": "835db5c6-5cc8-4d70-a3b2-9a18ad4912cd",
"subject_id": "da6a14a0-6498-4941-a1b2-bbe45a2ccac2"
},
...
]

### Endpoints

For all endpoints, the request cookie should contain an access_token. The user needs read access and read-storage access
For all endpoints, the request must contain an Authorization header with an access_token. The user needs read access and read-storage access
on at least one project in order to use this service.

Lists a user's manifests:

GET /
Returns: { "manifests" : [ "filename-1.json", "filename-2.json", ... ] }
Returns: { "manifests" : [ { "filename" : "manifest-2019-02-27T11-44-20.548126.json", "last_modified" : "2019-02-27 17:44:21" }, ... ] }

Create a manifest file in the user's folder:

POST /
Post body: The contents of the manifest.json file to be created.
Returns: { "filename" : "the-timestamped-filename-generated-by-the-service.json" }
Returns: { "filename" : "manifest-2019-03-09T21-47-04.041499.json" }

Read the contents of a manifest file in the user's folder:

Expand All @@ -28,11 +42,10 @@ On failure, the above endpoints all return JSON in the form
{ "error" : "error-message" }

### Running the service locally
If you want to run this service locally, fill out manifest_service/dev_settings.py with the correct values and then run:
If you want to run this service locally, fill out the config.json file with the correct values and then run:

virtualenv -p python3 ~/manifest_service_env
source ~/manifest_service_env/bin/activate
pip3 install -r requirements.txt
pipenv shell --python 3.6
pipenv install --skip-lock --dev
python3 run.py

And then GET and POST to http://localhost:5000/
Expand Down
2 changes: 1 addition & 1 deletion build_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from flasgger import Swagger, Flasgger
from yaml.representer import Representer

from manifest_service.api import app
from manifestservice.api import app
from openapi.app_info import app_info


Expand Down
6 changes: 6 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"aws_access_key_id": "",
"aws_secret_access_key": "",
"manifest_bucket_name" : "",
"hostname": ""
}
19 changes: 12 additions & 7 deletions deployment/nginx/uwsgi.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,30 @@ server {
uwsgi_param REMOTE_ADDR $http_x_forwarded_for if_not_empty;
uwsgi_param REMOTE_USER $http_x_userid if_not_empty;

## GEN3_REQUEST_TIMESTAMP and GEN3_TIMEOUT_SECONDS
# These two together aligns the HARAKIRI timeout in uWSGI with NGINX
# See also https://github.com/uc-cdis/cdis-python-utils#uwsgi
uwsgi_param GEN3_REQUEST_TIMESTAMP $msec;
uwsgi_param GEN3_TIMEOUT_SECONDS '20';

include uwsgi_params;
uwsgi_pass unix:/var/www/manifest_service/uwsgi.sock;
uwsgi_pass unix:/var/www/manifestservice/uwsgi.sock;
uwsgi_read_timeout 20s;
uwsgi_send_timeout 20s;
}

location /_status {
uwsgi_param REMOTE_ADDR $http_x_forwarded_for if_not_empty;
uwsgi_param REMOTE_USER $http_x_userid if_not_empty;

include uwsgi_params;
uwsgi_pass unix:/var/www/manifest_service/uwsgi.sock;
uwsgi_pass unix:/var/www/manifestservice/uwsgi.sock;
uwsgi_read_timeout 20s;
uwsgi_send_timeout 20s;
uwsgi_param GEN3_REQUEST_TIMESTAMP $msec;
uwsgi_param GEN3_TIMEOUT_SECONDS $arg_timeout;
uwsgi_ignore_client_abort on;
access_log off;
}

error_page 504 /504.html;
location /504.html {
return 504 '{"error": {"Request Timeout"}}';
}
}
}
26 changes: 23 additions & 3 deletions deployment/uwsgi/uwsgi.ini
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
[uwsgi]
protocol = uwsgi
socket = /var/www/manifest_service/uwsgi.sock
socket = /var/www/manifestservice/uwsgi.sock
buffer-size = 32768
chmod-socket = 666
master = true
harakiri-verbose = 20
disable-logging = true
wsgi-file=/manifest_service/wsgi.py
wsgi-file=/manifestservice/wsgi.py
plugins = python3
vacuum = true
chdir = /manifest_service/
chdir = /manifestservice/
uid = nginx
gid = nginx
# pythonpath = /usr/local/lib/site-packages/
virtualenv = $(VENV)
pythonpath = /usr/local/lib/python3.6/site-packages/


# [uwsgi]
# protocol = uwsgi
# socket = /var/www/wts/uwsgi.sock
# buffer-size = 32768
# chmod-socket = 666
# master = true
# harakiri-verbose = 20
# disable-logging = true
# wsgi-file=/wts/wsgi.py
# plugins = python3
# vacuum = true
# chdir = /wts/
# uid = nginx
# gid = nginx
# virtualenv = $(VENV)
# pythonpath = /usr/local/lib/python3.6/site-packages/


# Use this to initialize application in worker processes, not master. This
# prevents the workers from all trying to open the same database
# connections at startup:
Expand Down
2 changes: 1 addition & 1 deletion deployment/uwsgi/wsgi.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from manifest_service.api import app
from manifestservice.api import app
application = app
4 changes: 3 additions & 1 deletion dockerrun.bash
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/bash

cd /$appname
export VENV=$(pipenv --venv)
cd /var/www/$appname

#
# Update certificate authority index -
# environment may have mounted more authorities
Expand All @@ -10,6 +11,7 @@ update-ca-certificates
#
# Enable debug flag based on GEN3_DEBUG environment
#

if [[ -f ./wsgi.py && "$GEN3_DEBUG" == "True" ]]; then
echo -e "\napplication.debug=True\n" >> ./wsgi.py
fi
Expand Down
Loading

0 comments on commit fa93051

Please sign in to comment.