File tree Expand file tree Collapse file tree 3 files changed +90
-0
lines changed
Expand file tree Collapse file tree 3 files changed +90
-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
6+
7+ COPY run_python.sh /python/run_python.sh
8+ RUN chmod 755 /python/run_python.sh
9+ WORKDIR /python
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 where the examples can be tested against the development source.
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-local-python-dir:/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+ # Checks if Rosette API key is valid
32+ function checkAPI {
33+ match=$( curl " https://api.rosette.com/rest/v1/ping" -H " user_key: ${API_KEY} " | grep -o " forbidden" )
34+ if [ ! -z $match ]; then
35+ echo -e " \nInvalid Rosette API Key"
36+ exit 1
37+ fi
38+ }
39+
40+ # Copy the mounted content in /source to current WORKDIR
41+ cp -r /source/* .
42+
43+ # Run the examples
44+ if [ ! -z ${API_KEY} ]; then
45+ checkAPI
46+ # Prerequisite
47+ python /python/setup.py install
48+ cd examples
49+ if [ ! -z ${FILENAME} ]; then
50+ if [ ! -z ${ALT_URL} ]; then
51+ python ${FILENAME} --key ${API_KEY} --url ${ALT_URL}
52+ else
53+ python ${FILENAME} --key ${API_KEY}
54+ fi
55+ elif [ ! -z ${ALT_URL} ]; then
56+ find -maxdepth 1 -name ' *.py' -print -exec python {} --key ${API_KEY} --url ${ALT_URL} \;
57+ else
58+ find -maxdepth 1 -name ' *.py' -print -exec python {} --key ${API_KEY} \;
59+ fi
60+ else
61+ HELP
62+ fi
You can’t perform that action at this time.
0 commit comments