Skip to content

Commit 62a7658

Browse files
authored
Merge pull request #137 from sympy/fix-deploy
Fix deployment to use Cloud SDK
2 parents 200679c + 9bf801a commit 62a7658

File tree

7 files changed

+55
-173
lines changed

7 files changed

+55
-173
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,3 @@ my/
3030

3131
# Backup files
3232
*~
33-
34-
# Generated app.yaml
35-
app.yaml

.travis.yml

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,39 @@
11
language: python
22
python:
3-
- "2.7"
3+
- '2.7'
44

5-
env:
6-
global:
7-
# encrypted $OAUTH_REFRESH_TOKEN needed for deployment
8-
secure: "RwbmRKMqzHkDB1kaurFLOVYLS2mnYp+IXHNIGvziTjl8x2ccKs568clPu/nNdlQKqbUlvPhlM/Nr7SHF/GV2SWE2unq2Bjn9/WA3dNVL/PsMmfvJbZ0pnepDKFc/YhKf37uYQQWWwzfLo11iOLkcDWFsZ15tWoMXK2VjZkPbKBw="
95
virtualenv:
106
system_site_packages: true
117

128
before_install:
139
- npm install -g casperjs
14-
install: "pip install -r requirements.txt"
10+
install: pip install -r requirements.txt
1511

1612
before_script:
1713
- cd ..
1814
- wget https://storage.googleapis.com/appengine-sdks/featured/google_appengine_1.9.90.zip -nv
1915
- unzip -q google_appengine_1.9.90.zip
2016
- export SDK_LOCATION="$(pwd)/google_appengine"
2117
- cd $TRAVIS_BUILD_DIR
22-
- git fetch --tags
23-
- python deploy.py --generate-only --generate-test 1000
2418
- python $SDK_LOCATION/dev_appserver.py --skip_sdk_update_check 1 . &
2519
- sleep 10
26-
script: python travis.py
20+
script:
21+
- python travis.py
2722

28-
after_success: python deploy.py
23+
before_deploy:
24+
- openssl aes-256-cbc -K $encrypted_2fd045226a67_key -iv $encrypted_2fd045226a67_iv
25+
-in client-secret.json.enc -out ../client-secret.json -d
26+
# Promote the deployed version if the $TRAVIS_TAG is not empty
27+
- promote=$(if [ ! -z "$TRAVIS_TAG" ]; then echo "true"; else echo "false"; fi)
28+
- version=$(if [ ! -z "$TRAVIS_TAG" ]; then echo "$TRAVIS_TAG"; else echo "$TRAVIS_BRANCH"; fi)
29+
- echo "Version = $version"
30+
- echo "promote traffic after deployment = $tag_version"
31+
deploy:
32+
provider: gae
33+
keyfile: "../client-secret.json"
34+
project: sympy-gamma-hrd
35+
no_promote: "$promote"
36+
version: "$version"
37+
on:
38+
all_branches: true
39+
repo: sympy/sympy_gamma

README.rst

Lines changed: 34 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ Installation
2323
Download and unpack most recent Google App Engine SDK for Python from
2424
https://code.google.com/appengine/downloads.html, e.g.::
2525

26-
$ wget https://googleappengine.googlecode.com/files/google_appengine_1.5.1.zip
27-
$ unzip google_appengine_1.5.1.zip
26+
$ wget https://storage.googleapis.com/appengine-sdks/featured/google_appengine_1.9.90.zip
27+
$ unzip google_appengine_1.9.90.zip
2828

2929
On the Mac, it is a disk image with an application, which you should
3030
drag to your Applications folder. Open the program and install the
@@ -46,14 +46,6 @@ We use submodules to include external libraries in sympy_gamma::
4646
This is sufficient to clone appropriate repositories in correct versions
4747
into sympy_gamma (see git documentation on submodules for information).
4848

49-
Generate a configuration file for App Engine (needed to run the development
50-
web server)::
51-
52-
$ python deploy.py --generate-only --generate-test 1000
53-
54-
(the number does not matter unless you are deploying, see below). **DO not**
55-
commit the generated ``app.yaml`` file.
56-
5749
Development server
5850
------------------
5951

@@ -85,58 +77,51 @@ necessary unless you are deploying to the official server)::
8577

8678
$ git tag -a version-42
8779

88-
Second, you need to generate an ``app.yaml`` (App Engine configuration) file
89-
using ``deploy.py``::
9080

91-
$ python deploy.py --generate-only --generate-production
81+
Then install the Google Cloud SDK for your OS from here:
82+
https://cloud.google.com/sdk/install
9283

93-
The script will determine the version from the tag; it can also be manually
94-
specified (``--generate-production VERSION_NUMBER``). You will also want to
95-
change the application name if you are not deploying to the test
96-
application. **DO not** commit the generated ``app.yaml`` file.
84+
This will let you use the "gcloud" CLI. After this configure the CLI to access
85+
the google cloud console for the project::
9786

98-
Second, you need to go to the ``Versions`` section of the
99-
sympy_gamma dashboard at appspot.com and delete the oldest version, as we
100-
can only upload ten versions at a time.
87+
$ gcloud init
10188

102-
Assuming that sympy_gamma works properly (also across different mainstream web
103-
browsers), you can upload your changes to Google App Engine::
10489

105-
$ ../appcfg.py update .
90+
Assuming that sympy_gamma works properly (also across different mainstream web
91+
browsers), you can upload your changes to Google App Engine, replacing the
92+
<TAGGED_VERSION> with actual version we tagged with::
10693

107-
Or, in Mac OS X, just open the GoogleAppEngineLauncher program, add the
108-
project if you haven't already, and click "Deploy" in the toolbar. And then
109-
it should just work (follow the log that comes up to see.
94+
$ gcloud app deploy --project sympy-gamma-hrd --no-promote --version <TAGGED_VERSION>
11095

11196
This requires admin privileges to https://sympy-gamma-hrd.appspot.com. If you
11297
don't have access to this App Engine application, but want to test it, see
11398
the instructions in the `Testing on the App Engine`_ section below.
11499

115-
The deploy script can generate the configuration and deploy in one step if
116-
given the App Engine SDK location::
117-
118-
$ SDK_LOCATION=/path/to/sdk python deploy.py --generate-production
119-
120-
Finally, go to https://NN.sympy-gamma-hrd.appspot.com, where ``NN`` is the
100+
Finally, go to https://NN-dot-sympy-gamma-hrd.appspot.com, where ``NN`` is the
121101
version you just uploaded, and make sure that it works. If it does, go to
122102
the ``Versions`` section of the sympy_gamma dashboard, and set this as the
123103
new default version. If there are any issues, you can roll back to the
124104
previous version from this same screen.
125105

126-
Generating a Deployment Key
127-
---------------------------
106+
Creating Deployment Credentials
107+
-------------------------------
108+
109+
Travis-CI deploys the application using service account credentials. To create a
110+
service account for deployment with suitable permissions, follow these steps:
128111

129-
Travis-CI deploys the application using OAuth credentials. These are stored
130-
encrypted in the ``env`` section of ``.travis.yml``, and are generated using
131-
the Travis command-line tools::
112+
https://cloud.google.com/solutions/continuous-delivery-with-travis-ci#creating_credentials
132113

133-
travis encrypt 'OAUTH_REFRESH_TOKEN=TOKEN' -r sympy/sympy_gamma
114+
These are stored encrypted in the ``client-secret.json.enc`` file in the repository, and are generated
115+
using the Travis command-line tools (client-secret.json is the credentials file for the service account
116+
created int the step above) ::
134117

135-
The token is found in the JSON file ``$HOME/.appcfg_oauth2_tokens`` under
136-
the key ``"refresh_token"``. This file is created after manually deploying
137-
(or running any other command) using OAuth authorization::
138118

139-
$ ../appcfg.py update --oauth2 .
119+
travis encrypt-file client-secret.json --add
120+
121+
This also adds the encrypted keys in travis environment variables, which you can
122+
check from here: https://travis-ci.org/github/aktech/sympy_gamma/settings in the
123+
"Environment Variables" section.
124+
140125

141126
Testing on the App Engine
142127
-------------------------
@@ -147,23 +132,19 @@ Currently, there is no testing server set up as there is for SymPy
147132
Live. However, you can set up your own testing server (it's free, though it
148133
requires a cell phone to set up).
149134

150-
Either way, to test, you will need to edit the ``app.yaml`` file. You should
151-
edit the first line, ``application``, to the name of the testing application
152-
(like ``sympy-gamma-tests``), and the second line to the version number you
153-
want to use.
135+
Either way, to test, you will need to edit the Project ID in the deploy command
136+
mentioned above with your Project ID and the version you want to deploy to::
137+
138+
gcloud app deploy --project <your-project-name> --no-promote --version <TAGGED_VERSION>
154139

155-
You should not actually commit ``app.yaml``, as it is generated by the
156-
deploy script. If you later want to commit an actual change to the
157-
generated ``app.yaml`` (e.g., to modify some metadata), you should edit and
158-
commit changes to ``app.yaml.template``.
159140

160141
If you have a test app online, remember to update it every time you update a
161142
pull request, so that others can easily review your work, without even having
162143
to use ``dev_appserver.py``.
163144

164-
Pull requests are automatically deployed by Travis to
165-
`https://N-dot-sympy-gamma-tests.appspot.com/`, where `N` is the pull request
166-
number. Note that the pull request has to from a branch on this repository, as
145+
Branch builds are automatically deployed by Travis to
146+
`https://N-dot-sympy-gamma-tests.appspot.com/`, where `N` is the branch name.
147+
Note that the pull request has to from a branch on this repository, as
167148
forks do not have access to the key to deploy to the app engine.
168149

169150
Development notes
@@ -202,7 +183,6 @@ In projects that don't use submodules, pulling changes boils down to::
202183
in the simplest case. SymPy Gamma, however, requires additional effort::
203184

204185
$ git submodule update
205-
$ python deploy.py --generate-only --generate-test 1000
206186

207187
The former command assures that if there were any changes to submodules
208188
of the super-project, then those submodules will get updated to new

app.yaml.template renamed to app.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
application: {application}
2-
version: {version}
31
runtime: python27
42
threadsafe: true
53
api_version: 1

client-secret.json.enc

2.27 KB
Binary file not shown.

deploy.py

Lines changed: 0 additions & 103 deletions
This file was deleted.

travis.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import nose
2-
import os
32
import sys
43
import os.path
54
import subprocess

0 commit comments

Comments
 (0)