Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/python3 #220

Merged
merged 19 commits into from
Jul 11, 2019
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/main.workflow
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
workflow "Run python formatter" {
on = "pull_request"
resolves = ["Run wool"]
}

action "Run wool" {
uses = "uc-cdis/wool@master"
secrets = ["GITHUB_TOKEN"]
}
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ dist: xenial
language: python

python:
- "2.7"
- "3.6"

sudo: false
Expand Down
37 changes: 25 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
# To run: docker run -v /path/to/wsgi.py:/var/www/indexd/wsgi.py --name=indexd -p 81:80 indexd
# To check running container: docker exec -it indexd /bin/bash

FROM quay.io/cdis/py27base:pybase2-1.0.2
FROM quay.io/cdis/python-nginx:pybase3-1.0.0

MAINTAINER CDIS <cdissupport@opensciencedatacloud.org>

RUN mkdir /var/www/indexd \
&& chown www-data /var/www/indexd
ENV appname=indexd

COPY . /indexd
COPY ./deployment/uwsgi/uwsgi.ini /etc/uwsgi/uwsgi.ini
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

WORKDIR /indexd
COPY . /$appname
COPY ./deployment/uwsgi/uwsgi.ini /etc/uwsgi/uwsgi.ini
COPY ./deployment/uwsgi/wsgi.py /$appname/wsgi.py
WORKDIR /$appname

RUN python -m pip install -r requirements.txt
RUN COMMIT=`git rev-parse HEAD` && echo "COMMIT=\"${COMMIT}\"" >indexd/index/version_data.py
RUN VERSION=`git describe --always --tags` && echo "VERSION=\"${VERSION}\"" >>indexd/index/version_data.py
RUN python setup.py install
RUN python -m pip install --upgrade pip \
&& python -m pip install --upgrade setuptools \
&& pip install -r requirements.txt

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

EXPOSE 80

WORKDIR /var/www/indexd
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

CMD /dockerrun.sh
49 changes: 25 additions & 24 deletions bin/index_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import sys
from cdislogging import get_logger

logger = get_logger('index_admin')
logger = get_logger("index_admin")


def main(path, action=None, username=None, password=None):
sys.path.append(path)
Expand All @@ -11,45 +12,45 @@ def main(path, action=None, username=None, password=None):
except ImportError:
logger.info("Can't import local_settings, import from default")
from indexd.default_settings import settings
driver = settings['auth']
index_driver = settings['config']['INDEX']['driver']
alias_driver = settings['config']['ALIAS']['driver']
if action == 'create':
driver = settings["auth"]
index_driver = settings["config"]["INDEX"]["driver"]
alias_driver = settings["config"]["ALIAS"]["driver"]
if action == "create":
try:
driver.add(username, password)
logger.info('User {} created'.format(username))
logger.info("User {} created".format(username))
except Exception as e:
logger.error(e.message)
logger.error(e)

elif action == 'delete':
elif action == "delete":
try:
driver.delete(username)
logger.info('User {} deleted'.format(username))
logger.info("User {} deleted".format(username))
except Exception as e:
logger.error(e.message)
logger.error(e)

elif action == 'migrate_database':
elif action == "migrate_database":
try:
logger.info('Start database migration')
logger.info("Start database migration")
alias_driver.migrate_alias_database()
index_driver.migrate_index_database()
except Exception as e:
logger.error(e.message)
if __name__ == '__main__':
logger.error(e)


if __name__ == "__main__":

parser = argparse.ArgumentParser()

parser.add_argument(
'--path',
default='/var/www/indexd/',
help='path to find local_settings.py',
"--path", default="/var/www/indexd/", help="path to find local_settings.py"
)
subparsers = parser.add_subparsers(title='action', dest='action')
create = subparsers.add_parser('create')
delete = subparsers.add_parser('delete')
migrate = subparsers.add_parser('migrate_database')
create.add_argument('--username', required=True)
create.add_argument('--password', required=True)
delete.add_argument('--username', required=True)
subparsers = parser.add_subparsers(title="action", dest="action")
create = subparsers.add_parser("create")
delete = subparsers.add_parser("delete")
migrate = subparsers.add_parser("migrate_database")
create.add_argument("--username", required=True)
create.add_argument("--password", required=True)
delete.add_argument("--username", required=True)
args = parser.parse_args()
main(**args.__dict__)
10 changes: 4 additions & 6 deletions deployment/uwsgi/uwsgi.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
protocol = uwsgi
socket = /var/run/gen3/uwsgi.sock
buffer-size = 32768
uid = nginx
gid = nginx
chown-socket = nginx:nginx
chmod-socket = 666
master = true
processes = 2
harakiri-verbose = true
# No global HARAKIRI, using only user HARAKIRI, because export overwrites it
# Cannot overwrite global HARAKIRI with user's: https://git.io/fjYuD
Expand All @@ -16,13 +18,9 @@ reload-mercy = 45
mule-reload-mercy = 45
disable-logging = true
wsgi-file=/indexd/wsgi.py
plugins = python
plugins = python3
vacuum = true
uid = www-data
gid = www-data
pythonpath = /var/www/indexd/
pythonpath = /indexd/
pythonpath = /usr/local/lib/python2.7/dist-packages/
# Initialize application in worker processes, not master. This prevents the
# workers from all trying to open the same database connections at startup.
lazy = true
Expand Down
3 changes: 2 additions & 1 deletion wsgi.py → deployment/uwsgi/wsgi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from indexd import get_app
import os
os.environ['INDEXD_SETTINGS'] = '/var/www/indexd/'

os.environ["INDEXD_SETTINGS"] = "/var/www/indexd/"
application = get_app()
2 changes: 1 addition & 1 deletion indexd/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .app import get_app
from .app import get_app
Loading