Skip to content

Commit a103bb1

Browse files
authored
Merge pull request #149 from sympy/dockerize
Dockerize the project for development
2 parents ce3f91d + 2431b7d commit a103bb1

File tree

8 files changed

+138
-93
lines changed

8 files changed

+138
-93
lines changed

.travis.yml

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,23 @@ language: python
22
python:
33
- '2.7'
44

5-
cache:
6-
directories:
7-
- "$HOME/google-cloud-sdk/"
8-
9-
virtualenv:
10-
system_site_packages: true
5+
services:
6+
- docker
117

128
before_install:
13-
- npm install -g casperjs
9+
- ls
1410
install:
15-
- pip install -r requirements/requirements.txt -t lib/
16-
- pip install -r requirements/local_requirements.txt
17-
11+
- ls
1812
before_script:
19-
- gcloud version || true
20-
- if [ ! -d "$HOME/google-cloud-sdk/bin" ]; then rm -rf "$HOME/google-cloud-sdk"; curl https://sdk.cloud.google.com | bash > /dev/null; fi
21-
- source /home/travis/google-cloud-sdk/path.bash.inc
22-
- gcloud version
23-
- cd ..
24-
- gcloud components install cloud-datastore-emulator --quiet
25-
- gcloud beta emulators datastore start &
26-
- wget https://storage.googleapis.com/appengine-sdks/featured/google_appengine_1.9.90.zip -nv
27-
- unzip -q google_appengine_1.9.90.zip
28-
- export SDK_LOCATION="$(pwd)/google_appengine"
29-
- cd $TRAVIS_BUILD_DIR
30-
- python $SDK_LOCATION/dev_appserver.py --skip_sdk_update_check 1 . --env_var DATASTORE_EMULATOR_HOST=localhost:8081 --env_var DATASTORE_USE_PROJECT_ID_AS_APP_ID=true &
31-
- sleep 10
13+
- docker-compose up -d
3214

3315
script:
34-
- PYTHONPATH='.' nosetests app/test -vv
35-
- casperjs test app/test
16+
- sleep 2 # Wait for api to be up
17+
- docker-compose exec app nosetests app/test -vv
18+
- docker-compose exec app casperjs test app/test
3619

3720
before_deploy:
21+
- docker cp gamma_app:/usr/src/app/lib lib
3822
- openssl aes-256-cbc -K $encrypted_2fd045226a67_key -iv $encrypted_2fd045226a67_iv
3923
-in client-secret.json.enc -out client-secret.json -d
4024
- version=$(if [ ! -z "$TRAVIS_TAG" ]; then echo $(cut -d'-' -f2 <<<"$TRAVIS_TAG"); else echo "$TRAVIS_BRANCH"; fi)
@@ -51,9 +35,5 @@ deploy:
5135
repo: sympy/sympy_gamma
5236

5337
after_deploy:
38+
- pip install requests
5439
- python bin/update_status_on_pr.py
55-
56-
env:
57-
global:
58-
# Do not prompt for user input when using any SDK methods.
59-
- CLOUDSDK_CORE_DISABLE_PROMPTS=1

README.rst

Lines changed: 30 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
SymPy Gamma
22
===========
33

4+
.. image:: https://travis-ci.org/sympy/sympy_gamma.svg?branch=master
5+
:target: https://travis-ci.org/sympy/sympy_gamma
6+
47
`SymPy Gamma <https://www.sympygamma.com>`_ is a simple web application based
58
on Google App Engine that executes and displays the results of SymPy
69
expressions as well as additional related computations, in a fashion similar
@@ -20,20 +23,7 @@ information from loading.
2023
Installation
2124
------------
2225

23-
Download and unpack most recent Google App Engine SDK for Python from
24-
https://code.google.com/appengine/downloads.html, e.g.::
25-
26-
$ wget https://storage.googleapis.com/appengine-sdks/featured/google_appengine_1.9.90.zip
27-
$ unzip google_appengine_1.9.90.zip
28-
29-
On the Mac, it is a disk image with an application, which you should
30-
drag to your Applications folder. Open the program and install the
31-
symlinks (it should ask you the first time you open the application, but
32-
if it doesn't, choose "Make Symlinks..." from the
33-
GoogleAppEngineLauncher menu). Note that you will have to do this again
34-
each time you update the AppEngine program.
35-
36-
Then clone sympy_gamma repository::
26+
Clone sympy_gamma repository::
3727

3828
$ git clone git://github.com/sympy/sympy_gamma.git
3929
$ cd sympy_gamma
@@ -46,50 +36,26 @@ We use submodules to include external libraries in sympy_gamma::
4636
This is sufficient to clone appropriate repositories in correct versions
4737
into sympy_gamma (see git documentation on submodules for information).
4838

49-
Install Dependencies
50-
--------------------
51-
52-
The project depends on some third-party libraries that are not on the list
53-
of built-in libraries (in app.yaml) bundled with the runtime, to install them
54-
run the following command.::
55-
56-
pip install -r requirements/requirements.txt -t lib/
57-
58-
Some libraries although available on app engine runtime, but needs to be
59-
installed locally for development.
60-
61-
Ref: https://cloud.google.com/appengine/docs/standard/python/tools/using-libraries-python-27#local_development ::
62-
63-
pip install -r requirements/local_requirements.txt
64-
65-
You will need to install Datastore Emulator as well, which comes from gcloud's SDK,
66-
install the Google Cloud SDK for your OS from here: https://cloud.google.com/sdk/install
67-
Then run the following commands to install and run the datastore emulator in the background::
68-
69-
gcloud components install cloud-datastore-emulator --quiet
70-
gcloud beta emulators datastore start &
71-
7239

73-
Development server
40+
Development Server
7441
------------------
7542

76-
Now you are ready to run development web server::
43+
To setup the development environment and run the app locally, you
44+
need ``docker`` and ``docker-compose``:
7745

78-
$ ../google_appengine/dev_appserver.py .
46+
* https://docs.docker.com/get-docker/
47+
* https://docs.docker.com/compose/install/
7948

80-
On the Mac, just run::
49+
Now you are ready to run development web server::
8150

82-
$ dev_appserver.py .
51+
$ docker-compose up
8352

84-
(make sure you installed the symlinks as described above).
53+
This will build and run the image for app and datastore emulator.
8554

86-
I couldn't figure out how to make it work in the GUI (it won't find the
87-
sympy git submodule). If you figure out how to do it, please update
88-
this file and send a patch describing how to do it.
55+
This will spin up a local server that runs on port ``8080``.
56+
Open a web browser and go to http://localhost:8080.
57+
You should see GUI of SymPy Gamma
8958

90-
This is a local server that runs on port 8080 (use ``--port`` option to
91-
change this). Open a web browser and go to http://localhost:8080. You
92-
should see GUI of SymPy Gamma.
9359

9460
Deploying to GAE
9561
----------------
@@ -114,6 +80,11 @@ the google cloud console for the project::
11480

11581
$ gcloud init
11682

83+
You need to to create ``lib`` (libraries) before deploying, make sure the development
84+
server is up and running via ``docker-compose``, as mentioned above and create
85+
libraries folder to package with the following command::
86+
87+
$ docker cp gamma_app:/usr/src/app/lib lib
11788

11889
Assuming that sympy_gamma works properly (also across different mainstream web
11990
browsers), you can upload your changes to Google App Engine, replacing the
@@ -161,6 +132,12 @@ Currently, there is no testing server set up as there is for SymPy
161132
Live. However, you can set up your own testing server (it's free, though it
162133
requires a cell phone to set up).
163134

135+
You need to to create ``lib`` (libraries) before deploying, make sure the development
136+
server is up and running via ``docker-compose``, as mentioned above and create
137+
libraries folder to package with the following command::
138+
139+
$ docker cp gamma_app:/usr/src/app/lib lib
140+
164141
Either way, to test, you will need to edit the Project ID in the deploy command
165142
mentioned above with your Project ID and the version you want to deploy to::
166143

@@ -206,21 +183,11 @@ versions automatically.
206183
Running Tests
207184
-------------
208185

209-
To be able to run tests, make sure you have testing libraries installed::
210-
211-
npm install -g casperjs
212-
pip install nose
213-
214-
Install phantomjs for your system from: https://phantomjs.org/download.html
215-
216-
To run unit tests::
217-
218-
PYTHONPATH='.' nosetests app/test -vv
219-
220-
To run PhantomJS Tests::
221-
222-
casperjs test app/test
186+
To run tests you need to spinup the container as mentioned above
187+
via ``docker-compose`` and run the following command::
223188

189+
$ docker-compose exec app nosetests app/test -vv
190+
$ docker-compose exec app casperjs test app/test
224191

225192
Pulling changes
226193
---------------

__init__.py

Whitespace-only changes.

docker-compose.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
version: '3'
2+
3+
services:
4+
app:
5+
build:
6+
context: .
7+
dockerfile: ./docker/app/Dockerfile
8+
image: app
9+
container_name: gamma_app
10+
depends_on:
11+
- datastore
12+
volumes:
13+
- ./app/:/usr/src/app/app/
14+
ports:
15+
- "8080:8080"
16+
- "8082:8082"
17+
- "8083:8083"
18+
command: /run.sh
19+
20+
datastore:
21+
build:
22+
context: .
23+
dockerfile: ./docker/datastore/Dockerfile
24+
image: datastore
25+
container_name: gamma_datastore
26+
ports:
27+
- "8081:8081"

docker/app/Dockerfile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
FROM python:2-slim
2+
3+
RUN apt-get update \
4+
# dependencies for building Python packages
5+
&& apt-get install -y build-essential \
6+
&& apt-get install -y python-dev \
7+
&& apt-get install -y wget \
8+
&& apt-get install -y zip unzip
9+
10+
WORKDIR /usr/src/app
11+
12+
COPY requirements ./requirements
13+
COPY ./docker/app/run.sh /run.sh
14+
15+
RUN pip install -r requirements/requirements.txt -t lib/
16+
RUN pip install -r requirements/local_requirements.txt
17+
18+
# Install App engine SDK
19+
RUN wget https://storage.googleapis.com/appengine-sdks/featured/google_appengine_1.9.90.zip -nv -P /usr/src/
20+
RUN unzip -q /usr/src/google_appengine_1.9.90.zip -d /usr/src/
21+
ENV SDK_LOCATION="/usr/src/google_appengine"
22+
23+
# Install PhantomJs and Casperjs for Testing
24+
ENV PHANTOM_JS="phantomjs-1.9.8-linux-x86_64"
25+
RUN apt-get install -y chrpath libssl-dev libxft-dev \
26+
&& apt-get install -y libfreetype6 libfreetype6-dev \
27+
&& apt-get install -y libfontconfig1 libfontconfig1-dev \
28+
&& apt-get install -y git
29+
30+
RUN cd ../ && wget https://bitbucket.org/ariya/phantomjs/downloads/$PHANTOM_JS.tar.bz2
31+
RUN mv ../$PHANTOM_JS.tar.bz2 /usr/local/share/
32+
RUN cd /usr/local/share/ && tar xvjf $PHANTOM_JS.tar.bz2
33+
RUN ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/share/phantomjs
34+
RUN ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/bin/phantomjs
35+
RUN ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/bin/phantomjs
36+
RUN rm -rf /usr/local/share/$PHANTOM_JS.tar.bz2
37+
38+
RUN cd ../ && git clone git://github.com/casperjs/casperjs.git \
39+
&& cd casperjs && ln -sf `pwd`/bin/casperjs /usr/local/bin/casperjs
40+
41+
ENV PYTHONPATH="/usr/src/app"
42+
43+
COPY . .
44+
45+
ENTRYPOINT [ "/run.sh" ]

docker/app/run.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
3+
HOST="0.0.0.0"
4+
API_PORT="8082"
5+
ADMIN_PORT="8083"
6+
DATASTORE_EMULATOR_HOST_PORT=datastore:8081
7+
8+
python $SDK_LOCATION/dev_appserver.py --api_host 0.0.0.0 \
9+
--api_port "$API_PORT" \
10+
--admin_host "$HOST" \
11+
--admin_port "$ADMIN_PORT" \
12+
--host "$HOST" \
13+
--skip_sdk_update_check 1 . \
14+
--env_var DATASTORE_EMULATOR_HOST="$DATASTORE_EMULATOR_HOST_PORT" \
15+
--env_var DATASTORE_USE_PROJECT_ID_AS_APP_ID=true

docker/datastore/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM google/cloud-sdk:latest
2+
3+
WORKDIR /usr/src/app
4+
COPY ./docker/datastore/run.sh ./run.sh
5+
6+
ENV CLOUDSDK_CORE_PROJECT=sympy-live-hrd
7+
8+
ENTRYPOINT [ "./run.sh" ]

docker/datastore/run.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
gcloud beta emulators datastore start --host-port=0.0.0.0:8081

0 commit comments

Comments
 (0)