Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions optional-kubernetes-engine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
FROM gcr.io/google-appengine/python

# Create a virtualenv for the application dependencies.
# If you want to use Python 2, add the -p python2.7 flag.
RUN virtualenv -p python3.4 /env
RUN virtualenv -p python3.14 /env

# Set virtualenv environment variables. This is equivalent to running
# source /env/bin/activate. This ensures the application is executed within
Expand Down
2 changes: 1 addition & 1 deletion optional-kubernetes-engine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Alternatively, you can use make:

## Update config.py

Modify config.py and enter your Cloud Project ID into the `PROJECT_ID` and `CLOUD_STORAGE_BUCKET` field. The remaining configuration values are only needed if you wish to use a different database or if you wish to enable log-in via oauth2, which requires a domain name.
Take a look at config.py and set your Cloud Project ID `PROJECT_ID` and `CLOUD_STORAGE_BUCKET` environment variables using `export GOOGLE_CLOUD_PROJECT='your-project-id'`. The remaining configuration values are only needed if you wish to use a different database or if you wish to enable log-in via oauth2, which requires a domain name.

## Build the bookshelf container

Expand Down
34 changes: 15 additions & 19 deletions optional-kubernetes-engine/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,29 @@
import os

# The secret key is used by Flask to encrypt session cookies.
SECRET_KEY = 'secret'
SECRET_KEY = os.getenv('SECRET_KEY')

# There are three different ways to store the data in the application.
# You can choose 'datastore', 'cloudsql', or 'mongodb'. Be sure to
# configure the respective settings for the one you choose below.
# You do not have to configure the other data backends. If unsure, choose
# 'datastore' as it does not require any additional configuration.
DATA_BACKEND = 'datastore'
DATA_BACKEND = os.getenv('DATA_BACKEND','datastore')

# Google Cloud Project ID. This can be found on the 'Overview' page at
# https://console.developers.google.com
PROJECT_ID = 'your-project-id'
PROJECT_ID = os.getenv('GOOGLE_CLOUD_PROJECT')

# CloudSQL & SQLAlchemy configuration
# Replace the following values the respective values of your Cloud SQL
# instance.
CLOUDSQL_USER = 'root'
CLOUDSQL_PASSWORD = 'your-cloudsql-password'
CLOUDSQL_DATABASE = 'bookshelf'
CLOUDSQL_USER = os.getenv('CLOUDSQL_USER')
CLOUDSQL_PASSWORD = os.getenv('CLOUDSQL_PASSWORD')
CLOUDSQL_DATABASE = os.getenv('CLOUDSQL_DATABASE')
# Set this value to the Cloud SQL connection name, e.g.
# "project:region:cloudsql-instance".
# You must also update the value in app.yaml.
CLOUDSQL_CONNECTION_NAME = 'your-cloudsql-connection-name'
CLOUDSQL_CONNECTION_NAME = os.getenv('CLOUDSQL_CONNECTION_NAME')

# The CloudSQL proxy is used locally to connect to the cloudsql instance.
# To start the proxy, use:
Expand All @@ -52,17 +52,13 @@
#
# Alternatively, you could use a local MySQL instance for testing.
LOCAL_SQLALCHEMY_DATABASE_URI = (
'mysql+pymysql://{user}:{password}@localhost/{database}').format(
user=CLOUDSQL_USER, password=CLOUDSQL_PASSWORD,
database=CLOUDSQL_DATABASE)
f'mysql+pymysql://{CLOUDSQL_USER}:{CLOUDSQL_PASSWORD}@localhost/{CLOUDSQL_DATABASE}')

# When running on App Engine a unix socket is used to connect to the cloudsql
# instance.
LIVE_SQLALCHEMY_DATABASE_URI = (
'mysql+pymysql://{user}:{password}@localhost/{database}'
'?unix_socket=/cloudsql/{connection_name}').format(
user=CLOUDSQL_USER, password=CLOUDSQL_PASSWORD,
database=CLOUDSQL_DATABASE, connection_name=CLOUDSQL_CONNECTION_NAME)
f'mysql+pymysql://{CLOUDSQL_USER}:{CLOUDSQL_PASSWORD}@localhost/{CLOUDSQL_DATABASE}'
f'?unix_socket=/cloudsql/{CLOUDSQL_CONNECTION_NAME}')

if os.environ.get('GAE_INSTANCE'):
SQLALCHEMY_DATABASE_URI = LIVE_SQLALCHEMY_DATABASE_URI
Expand All @@ -72,7 +68,8 @@
# Mongo configuration
# If using mongolab, the connection URI is available from the mongolab control
# panel. If self-hosting on compute engine, replace the values below.
MONGO_URI = 'mongodb://user:password@host:27017/database'
# format: mongodb://user:password@host:27017/database
MONGO_URI = os.getenv('MONGO_URI')

# Google Cloud Storage and upload settings.
# Typically, you'll name your bucket the same as your project. To create a
Expand All @@ -87,7 +84,7 @@
#
# You can adjust the max content length and allow extensions settings to allow
# larger or more varied file types if desired.
CLOUD_STORAGE_BUCKET = 'your-bucket-name'
CLOUD_STORAGE_BUCKET = os.getenv('CLOUD_STORAGE_BUCKET')
MAX_CONTENT_LENGTH = 8 * 1024 * 1024
ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg', 'gif'])

Expand All @@ -102,6 +99,5 @@
#
# If you receive a invalid redirect URI error review you settings to ensure
# that the current URI is allowed.
GOOGLE_OAUTH2_CLIENT_ID = \
'your-client-id'
GOOGLE_OAUTH2_CLIENT_SECRET = 'your-client-secret'
GOOGLE_OAUTH2_CLIENT_ID = os.getenv('GOOGLE_OAUTH2_CLIENT_ID')
GOOGLE_OAUTH2_CLIENT_SECRET = os.getenv('GOOGLE_OAUTH2_CLIENT_SECRET')