Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Google Cloud Datastore emulator for development #148

Merged
merged 3 commits into from May 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 18 additions & 3 deletions .travis.yml
Expand Up @@ -2,6 +2,10 @@ language: python
python:
- '2.7'

cache:
directories:
- "$HOME/google-cloud-sdk/"

virtualenv:
system_site_packages: true

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

before_script:
- openssl aes-256-cbc -K $encrypted_2fd045226a67_key -iv $encrypted_2fd045226a67_iv
-in client-secret.json.enc -out client-secret.json -d
- gcloud version || true
- if [ ! -d "$HOME/google-cloud-sdk/bin" ]; then rm -rf "$HOME/google-cloud-sdk"; curl https://sdk.cloud.google.com | bash > /dev/null; fi
- source /home/travis/google-cloud-sdk/path.bash.inc
- gcloud version
- cd ..
- gcloud components install cloud-datastore-emulator --quiet
- gcloud beta emulators datastore start &
- 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
- python $SDK_LOCATION/dev_appserver.py --skip_sdk_update_check 1 . &
- 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 &
- sleep 10

script:
- PYTHONPATH='.' nosetests app/test -vv
- casperjs test app/test

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

after_deploy:
- python bin/update_status_on_pr.py

env:
global:
# Do not prompt for user input when using any SDK methods.
- CLOUDSDK_CORE_DISABLE_PROMPTS=1
8 changes: 8 additions & 0 deletions README.rst
Expand Up @@ -62,6 +62,14 @@ Ref: https://cloud.google.com/appengine/docs/standard/python/tools/using-librari

pip install -r requirements/local_requirements.txt

You will need to install Datastore Emulator as well, which comes from gcloud's SDK,
install the Google Cloud SDK for your OS from here: https://cloud.google.com/sdk/install
Then run the following commands to install and run the datastore emulator in the background::

gcloud components install cloud-datastore-emulator --quiet
gcloud beta emulators datastore start &


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

Expand Down
1 change: 1 addition & 0 deletions app.yaml
Expand Up @@ -34,3 +34,4 @@ libraries:

env_variables:
GOOGLE_APPLICATION_CREDENTIALS: "client-secret.json"
PROJECT_ID: "sympy-gamma-hrd"
3 changes: 2 additions & 1 deletion app/models.py
@@ -1,10 +1,11 @@
import six
import os
# https://github.com/googleapis/python-ndb/issues/249#issuecomment-560957294
six.moves.reload_module(six)

from google.cloud import ndb

ndb_client = ndb.Client()
ndb_client = ndb.Client(project=os.environ['PROJECT_ID'])


class Query(ndb.Model):
Expand Down