File tree Expand file tree Collapse file tree 3 files changed +80
-0
lines changed
Expand file tree Collapse file tree 3 files changed +80
-0
lines changed Original file line number Diff line number Diff line change 1+ FROM python:2.7.11
2+ MAINTAINER Fiona Hasanaj
3+
4+ # install necessary software
5+ RUN apt-get -y update && apt-get install -y vim && apt-get install -y git && pip install tox
6+
7+ COPY run_python.sh /python/examples/run_python.sh
8+ RUN chmod 755 /python/examples/run_python.sh
9+ WORKDIR /python/examples
10+
11+ # allow interactive bash inside docker container
12+ CMD ./run_python.sh $API_KEY $ALT_URL
13+
14+ VOLUME ["/source" ]
Original file line number Diff line number Diff line change 1+ ---
2+ # Docker Image for Python Examples
3+ ---
4+ ### Summary
5+ To simplify the running of the Python examples, the Dockerfile will build an image and install the latest rosette-api library.
6+
7+ ### Basic Usage
8+ Build the docker image, e.g. ` docker build -t basistech/python:1.1 . `
9+
10+ Run an example as ` docker run -e API_KEY=api-key -v "path-to-example-source:/source" basistech/python:1.1 `
11+
12+ To test against a specific source file, add ` -e FILENAME=filename ` before the ` -v `
13+
14+ Also, to test against an alternate url, add ` -e ALT_URL=alternate_url ` before the ` -v `
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ # Gets called when the user doesn't provide any args
4+ function HELP {
5+ echo -e " \nusage: source_file.py --key API_KEY [--url ALT_URL]"
6+ echo " API_KEY - Rosette API key (required)"
7+ echo " FILENAME - Python source file (optional)"
8+ echo " ALT_URL - Alternate service URL (optional)"
9+ echo " Compiles and runs the source file(s) using the published rosette-api"
10+ exit 1
11+ }
12+
13+ # Gets API_KEY, FILENAME and ALT_URL if present
14+ while getopts " :API_KEY:FILENAME:ALT_URL" arg; do
15+ case " ${arg} " in
16+ API_KEY)
17+ API_KEY=${OPTARG}
18+ usage
19+ ;;
20+ ALT_URL)
21+ ALT_URL=${OPTARG}
22+ usage
23+ ;;
24+ FILENAME)
25+ FILENAME=${OPTARG}
26+ usage
27+ ;;
28+ esac
29+ done
30+
31+ # reference the API
32+ curl " https://api.rosette.com/rest/v1/ping" -H " user_key: $1 "
33+
34+ # Copy the mounted content in /source to current WORKDIR
35+ cp /source/* .* .
36+
37+ # Run the examples
38+ if [ ! -z ${API_KEY} ]; then
39+ if [ ! -z ${FILENAME} ]; then
40+ if [ ! -z ${ALT_URL} ]; then
41+ tox -- ${FILENAME} --key ${API_KEY} --url ${ALT_URL}
42+ else
43+ tox -- ${FILENAME} --key ${API_KEY}
44+ fi
45+ elif [ ! -z ${ALT_URL} ]; then
46+ find -maxdepth 1 -name ' *.py' -print -exec tox -- {} --key ${API_KEY} --url ${ALT_URL} \;
47+ else
48+ find -maxdepth 1 -name ' *.py' -print -exec tox -- {} --key ${API_KEY} \;
49+ fi
50+ else
51+ HELP
52+ fi
You can’t perform that action at this time.
0 commit comments