Skip to content

Commit

Permalink
Merge pull request #137 from sympy/fix-deploy
Browse files Browse the repository at this point in the history
Fix deployment to use Cloud SDK
  • Loading branch information
aktech committed Apr 15, 2020
2 parents 200679c + 9bf801a commit 62a7658
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 173 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,3 @@ my/

# Backup files
*~

# Generated app.yaml
app.yaml
31 changes: 21 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
language: python
python:
- "2.7"
- '2.7'

env:
global:
# encrypted $OAUTH_REFRESH_TOKEN needed for deployment
secure: "RwbmRKMqzHkDB1kaurFLOVYLS2mnYp+IXHNIGvziTjl8x2ccKs568clPu/nNdlQKqbUlvPhlM/Nr7SHF/GV2SWE2unq2Bjn9/WA3dNVL/PsMmfvJbZ0pnepDKFc/YhKf37uYQQWWwzfLo11iOLkcDWFsZ15tWoMXK2VjZkPbKBw="
virtualenv:
system_site_packages: true

before_install:
- npm install -g casperjs
install: "pip install -r requirements.txt"
install: pip install -r requirements.txt

before_script:
- cd ..
- wget https://storage.googleapis.com/appengine-sdks/featured/google_appengine_1.9.90.zip -nv
- unzip -q google_appengine_1.9.90.zip
- export SDK_LOCATION="$(pwd)/google_appengine"
- cd $TRAVIS_BUILD_DIR
- git fetch --tags
- python deploy.py --generate-only --generate-test 1000
- python $SDK_LOCATION/dev_appserver.py --skip_sdk_update_check 1 . &
- sleep 10
script: python travis.py
script:
- python travis.py

after_success: python deploy.py
before_deploy:
- openssl aes-256-cbc -K $encrypted_2fd045226a67_key -iv $encrypted_2fd045226a67_iv
-in client-secret.json.enc -out ../client-secret.json -d
# Promote the deployed version if the $TRAVIS_TAG is not empty
- promote=$(if [ ! -z "$TRAVIS_TAG" ]; then echo "true"; else echo "false"; fi)
- version=$(if [ ! -z "$TRAVIS_TAG" ]; then echo "$TRAVIS_TAG"; else echo "$TRAVIS_BRANCH"; fi)
- echo "Version = $version"
- echo "promote traffic after deployment = $tag_version"
deploy:
provider: gae
keyfile: "../client-secret.json"
project: sympy-gamma-hrd
no_promote: "$promote"
version: "$version"
on:
all_branches: true
repo: sympy/sympy_gamma
88 changes: 34 additions & 54 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ Installation
Download and unpack most recent Google App Engine SDK for Python from
https://code.google.com/appengine/downloads.html, e.g.::

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

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

Generate a configuration file for App Engine (needed to run the development
web server)::

$ python deploy.py --generate-only --generate-test 1000

(the number does not matter unless you are deploying, see below). **DO not**
commit the generated ``app.yaml`` file.

Development server
------------------

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

$ git tag -a version-42

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

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

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

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

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

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

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

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

The deploy script can generate the configuration and deploy in one step if
given the App Engine SDK location::

$ SDK_LOCATION=/path/to/sdk python deploy.py --generate-production

Finally, go to https://NN.sympy-gamma-hrd.appspot.com, where ``NN`` is the
Finally, go to https://NN-dot-sympy-gamma-hrd.appspot.com, where ``NN`` is the
version you just uploaded, and make sure that it works. If it does, go to
the ``Versions`` section of the sympy_gamma dashboard, and set this as the
new default version. If there are any issues, you can roll back to the
previous version from this same screen.

Generating a Deployment Key
---------------------------
Creating Deployment Credentials
-------------------------------

Travis-CI deploys the application using service account credentials. To create a
service account for deployment with suitable permissions, follow these steps:

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

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

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

$ ../appcfg.py update --oauth2 .
travis encrypt-file client-secret.json --add

This also adds the encrypted keys in travis environment variables, which you can
check from here: https://travis-ci.org/github/aktech/sympy_gamma/settings in the
"Environment Variables" section.


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

Either way, to test, you will need to edit the ``app.yaml`` file. You should
edit the first line, ``application``, to the name of the testing application
(like ``sympy-gamma-tests``), and the second line to the version number you
want to use.
Either way, to test, you will need to edit the Project ID in the deploy command
mentioned above with your Project ID and the version you want to deploy to::

gcloud app deploy --project <your-project-name> --no-promote --version <TAGGED_VERSION>

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

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

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

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

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

The former command assures that if there were any changes to submodules
of the super-project, then those submodules will get updated to new
Expand Down
2 changes: 0 additions & 2 deletions app.yaml.template → app.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
application: {application}
version: {version}
runtime: python27
threadsafe: true
api_version: 1
Expand Down
Binary file added client-secret.json.enc
Binary file not shown.
103 changes: 0 additions & 103 deletions deploy.py

This file was deleted.

1 change: 0 additions & 1 deletion travis.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import nose
import os
import sys
import os.path
import subprocess
Expand Down

0 comments on commit 62a7658

Please sign in to comment.