-
Notifications
You must be signed in to change notification settings - Fork 6.5k
add microservices demo #509
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
Merged
theacodes
merged 12 commits into
GoogleCloudPlatform:master
from
travisoneill:microservices_example
Oct 11, 2016
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f795487
add microservices demo
travisoneill d460cc7
switch express to flask and add README
travisoneill eac614f
make suggested changes
travisoneill 8d5d4fc
make suggested changes
travisoneill 5b8c19c
add config for running locally
travisoneill 7094561
reduce to 2 services and add services config file
travisoneill d7cc056
get rid of debug mode
travisoneill 010fbcc
add argparser and update readme
travisoneill ab1c495
make changes
travisoneill e6ac821
make small changes and add licenses
travisoneill 7b8e8ab
fix typo
travisoneill 33373cf
fix typo
travisoneill File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
import os | ||
from flask import Flask | ||
|
||
#to add services insert key value pair of the name of the service and | ||
#the port you want it to run on when running locally | ||
SERVICES = { | ||
'default': 5000, | ||
'default': 8000, | ||
'static': 8001 | ||
} | ||
|
||
def make_app(name): | ||
app = Flask(name) | ||
environment = 'production' if os.environ.get('GAE_LONG_APP_ID') else 'development' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the time being, I recommend using |
||
app.config['SERVICE_MAP'] = map_services(environment) | ||
return app | ||
|
||
def map_services(environment): | ||
'''Generates a map of services to correct urls for running locally | ||
or when deployed''' | ||
url_map = {} | ||
for service, local_port in SERVICES.items(): | ||
if environment == 'production': | ||
|
@@ -17,13 +26,14 @@ def map_services(environment): | |
return url_map | ||
|
||
def production_url(service_name): | ||
project_id = os.environ.get('GAE_LONG_APP_ID') or 'flask-algo' | ||
project_url = project_id + '.appspot.com' | ||
template = 'https://{}{}' | ||
'''Generates url for a service when deployed to App Engine''' | ||
project_id = os.environ.get('GAE_LONG_APP_ID') | ||
project_url = '{}.appspot.com'.format(project_id) | ||
if service_name == 'default': | ||
return template.format('', project_url) | ||
return 'https://{}'.format(project_url) | ||
else: | ||
return template.format(service_name + '-dot-', project_url) | ||
return 'https://{}-dot-{}'.format(service_name, project_url) | ||
|
||
def local_url(port): | ||
return 'http://localhost:' + str(port) | ||
'''Generates url for a service when running locally''' | ||
return 'http://localhost:{}'.format(str(port)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,6 @@ entrypoint: gunicorn -b :$PORT static_server:app | |
|
||
runtime_config: | ||
python_version: 3 | ||
|
||
manual_scaling: | ||
instances: 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
won't this error because
PORT
is a string?