Skip to content

Commit

Permalink
Merge pull request #20 from fhasanaj/RCB_227
Browse files Browse the repository at this point in the history
Rcb 227 - docker image to run examples, unit tests and generate gh-pages
  • Loading branch information
cp2boston committed Feb 11, 2016
2 parents 8c20256 + e2d7bfe commit 4a38e8a
Show file tree
Hide file tree
Showing 429 changed files with 107 additions and 84,507 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
0.5.1: first published version.
0.5.2: refactored code and tests.
0.5.3: change github repo for beta
0.8.0: migration to github, added docker images for testing
52 changes: 45 additions & 7 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,52 @@
FROM python:2.7.11
FROM ubuntu:14.04
MAINTAINER Fiona Hasanaj

# install necessary software
RUN apt-get -y update && apt-get install -y vim && apt-get install -y git
ENV DEBIAN_FRONTEND noninteractive
RUN locale-gen en_US.UTF-8 && /usr/sbin/update-locale LANG=en_US.UTF-8
ENV LANG en_US.UTF-8

COPY run_python.sh /python/run_python.sh
RUN chmod 755 /python/run_python.sh
WORKDIR /python
# proper init to handle signal propagation and zombie reaping
ADD https://github.com/krallin/tini/releases/download/v0.8.4/tini /tini
RUN chmod +x /tini
ENTRYPOINT ["/tini", "--"]

RUN apt-get update && \
apt-get -y install \
wget \
libssl-dev \
libffi-dev \
python-pip \
python-software-properties \
software-properties-common && \
add-apt-repository -y ppa:fkrull/deadsnakes && \
apt-get update && \
apt-get -y install \
python2.6 \
python2.7 \
python3.3 \
python3.4 \
python3.5 \
git\
pypy && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN mkdir /install && \
wget -O /install/pypy3-2.4-linux_x86_64-portable.tar.bz2 \
"https://bitbucket.org/squeaky/portable-pypy/downloads/pypy3-2.4-linux_x86_64-portable.tar.bz2" && \
tar jxf /install/pypy3-*.tar.bz2 -C /install && \
rm /install/pypy3-*.tar.bz2 && \
ln -s /install/pypy3-*/bin/pypy3 /usr/local/bin/pypy3

RUN pip install -U pip && pip install tox

# copy over the necessary files
COPY run_python.sh /python-dev/run_python.sh
RUN chmod 755 /python-dev/run_python.sh
COPY tox.ini /python-dev/tox.ini
WORKDIR /python-dev

# allow interactive bash inside docker container
CMD ./run_python.sh $API_KEY $ALT_URL
CMD ./run_python.sh $API_KEY $FILENAME $ALT_URL $GIT_USERNAME $VERSION

VOLUME ["/source"]
4 changes: 1 addition & 3 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ Build the docker image, e.g. `docker build -t basistech/python:1.1 .`

Run an example as `docker run -e API_KEY=api-key -v "path-to-local-python-dir:/source" basistech/python:1.1`

To test against a specific source file, add `-e FILENAME=filename` before the `-v`

Also, to test against an alternate url, add `-e ALT_URL=alternate_url` before the `-v`
To test against a specific source file, add `-e FILENAME=filename` before the `-v`, to test against an alternate url, add `-e ALT_URL=alternate_url`, and optionally if you would like to regenerate gh-pages from the changes made to the development source you can add `-e GIT_USERNAME=git-username -e VERSION=version` before the `-v`. In order to push the gh-pages to git remember to mount .ssh and .gitconfig to the root dir `-v path-to-.ssh-dir:/root/.ssh -v path-to-.gitconfig:/root/.gitconfig`.
47 changes: 39 additions & 8 deletions docker/run_python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
#Gets called when the user doesn't provide any args
function HELP {
echo -e "\nusage: source_file.py --key API_KEY [--url ALT_URL]"
echo " API_KEY - Rosette API key (required)"
echo " FILENAME - Python source file (optional)"
echo " ALT_URL - Alternate service URL (optional)"
echo "Compiles and runs the source file(s) using the published rosette-api"
echo " API_KEY - Rosette API key (required)"
echo " FILENAME - Python source file (optional)"
echo " ALT_URL - Alternate service URL (optional)"
echo " GIT_USERNAME - Git username where you would like to push regenerated gh-pages (optional)"
echo " VERSION - Build version (optional)"
echo "Compiles and runs the source file(s) using the local development source."
exit 1
}

#Gets API_KEY, FILENAME and ALT_URL if present
while getopts ":API_KEY:FILENAME:ALT_URL" arg; do
while getopts ":API_KEY:FILENAME:ALT_URL:GIT_USERNAME:VERSION" arg; do
case "${arg}" in
API_KEY)
API_KEY=${OPTARG}
Expand All @@ -25,6 +27,14 @@ while getopts ":API_KEY:FILENAME:ALT_URL" arg; do
FILENAME=${OPTARG}
usage
;;
GIT_USERNAME)
GIT_USERNAME=${OPTARG}
usage
;;
VERSION)
VERSION={OPTARG}
usage
;;
esac
done

Expand All @@ -38,14 +48,14 @@ function checkAPI {
}

#Copy the mounted content in /source to current WORKDIR
cp -r /source/* .
cp -r -n /source/* .

#Run the examples
if [ ! -z ${API_KEY} ]; then
checkAPI
#Prerequisite
python /python/setup.py install
cd examples
python /python-dev/setup.py install
cd /python-dev/examples
if [ ! -z ${FILENAME} ]; then
if [ ! -z ${ALT_URL} ]; then
python ${FILENAME} --key ${API_KEY} --url ${ALT_URL}
Expand All @@ -60,3 +70,24 @@ if [ ! -z ${API_KEY} ]; then
else
HELP
fi

#Run unit tests
cd /python-dev
tox

#Generate gh-pages and push them to git account (if git username is provided)
if [ ! -z ${GIT_USERNAME} ] && [ ! -z ${VERSION} ]; then
#clone python git repo
cd /
git clone [email protected]:${GIT_USERNAME}/python.git
cd python
git checkout origin/gh-pages -b gh-pages
git branch -d develop
#generate gh-pages and set ouput dir to git repo (gh-pages branch)
cd /python-dev
.tox/py27/bin/epydoc -v --no-private --no-frames --css epydoc.css -o /python rosette/*.py
cd /python
git add .
git commit -a -m "publish python apidocs ${VERSION}"
git push
fi
17 changes: 17 additions & 0 deletions docker/tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Tox (http://tox.testrun.org/) is a tool for running tests
# in multiple virtualenvs. This configuration file will run the
# test suite on all supported python versions. To use it, "pip install tox"
# and then run "tox" from this directory.

[tox]
skipsdist = True
envlist = py26, py27, py33, py34

[testenv]
commands =
py.test {toxinidir}/tests
deps =
pytest
pytest-pep8
httpretty==0.8.10
epydoc
2 changes: 1 addition & 1 deletion rosette/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
limitations under the License.
"""

__version__ = '0.7.4'
__version__ = '0.8.0'
2 changes: 1 addition & 1 deletion rosette/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from socket import gethostbyname, gaierror
from datetime import datetime

_BINDING_VERSION = "0.7"
_BINDING_VERSION = "0.8"
_GZIP_BYTEARRAY = bytearray([0x1F, 0x8b, 0x08])
N_RETRIES = 3
HTTP_CONNECTION = None
Expand Down
5 changes: 0 additions & 5 deletions tests/mock-data/request/ara-doc-categories.json

This file was deleted.

5 changes: 0 additions & 5 deletions tests/mock-data/request/ara-doc-entities.json

This file was deleted.

5 changes: 0 additions & 5 deletions tests/mock-data/request/ara-doc-entities_linked.json

This file was deleted.

5 changes: 0 additions & 5 deletions tests/mock-data/request/ara-doc-language.json

This file was deleted.

5 changes: 0 additions & 5 deletions tests/mock-data/request/ara-doc-morphology_complete.json

This file was deleted.

Loading

0 comments on commit 4a38e8a

Please sign in to comment.