Skip to content

Commit ce3f91d

Browse files
authored
Merge pull request #148 from sympy/cloud-emulator
Use Google Cloud Datastore emulator for development
2 parents fb23e25 + b87b16c commit ce3f91d

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

.travis.yml

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

5+
cache:
6+
directories:
7+
- "$HOME/google-cloud-sdk/"
8+
59
virtualenv:
610
system_site_packages: true
711

@@ -12,21 +16,27 @@ install:
1216
- pip install -r requirements/local_requirements.txt
1317

1418
before_script:
15-
- openssl aes-256-cbc -K $encrypted_2fd045226a67_key -iv $encrypted_2fd045226a67_iv
16-
-in client-secret.json.enc -out client-secret.json -d
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
1723
- cd ..
24+
- gcloud components install cloud-datastore-emulator --quiet
25+
- gcloud beta emulators datastore start &
1826
- wget https://storage.googleapis.com/appengine-sdks/featured/google_appengine_1.9.90.zip -nv
1927
- unzip -q google_appengine_1.9.90.zip
2028
- export SDK_LOCATION="$(pwd)/google_appengine"
2129
- cd $TRAVIS_BUILD_DIR
22-
- python $SDK_LOCATION/dev_appserver.py --skip_sdk_update_check 1 . &
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 &
2331
- sleep 10
2432

2533
script:
2634
- PYTHONPATH='.' nosetests app/test -vv
2735
- casperjs test app/test
2836

2937
before_deploy:
38+
- openssl aes-256-cbc -K $encrypted_2fd045226a67_key -iv $encrypted_2fd045226a67_iv
39+
-in client-secret.json.enc -out client-secret.json -d
3040
- version=$(if [ ! -z "$TRAVIS_TAG" ]; then echo $(cut -d'-' -f2 <<<"$TRAVIS_TAG"); else echo "$TRAVIS_BRANCH"; fi)
3141
- echo "Version = $version"
3242
deploy:
@@ -42,3 +52,8 @@ deploy:
4252

4353
after_deploy:
4454
- 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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ Ref: https://cloud.google.com/appengine/docs/standard/python/tools/using-librari
6262

6363
pip install -r requirements/local_requirements.txt
6464

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+
72+
6573
Development server
6674
------------------
6775

app.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ libraries:
3434

3535
env_variables:
3636
GOOGLE_APPLICATION_CREDENTIALS: "client-secret.json"
37+
PROJECT_ID: "sympy-gamma-hrd"

app/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import six
2+
import os
23
# https://github.com/googleapis/python-ndb/issues/249#issuecomment-560957294
34
six.moves.reload_module(six)
45

56
from google.cloud import ndb
67

7-
ndb_client = ndb.Client()
8+
ndb_client = ndb.Client(project=os.environ['PROJECT_ID'])
89

910

1011
class Query(ndb.Model):

0 commit comments

Comments
 (0)