Showing posts with label Google App Engine. Show all posts
Showing posts with label Google App Engine. Show all posts

Sunday, August 21, 2016

Google App Engine Continuous Integration with GitHub and CircleCI

In this blog post, I will share how to implement continuous integration with your GitHub repository for your Google App Engine application.

First of all, what is Continuous Integration (CI)? In a normal process of a development cycle, developers will go through several steps, especially for GitHub as stated in GitHub Flow:

Without CI yet:

That sounds reasonable, right? However, it can be more perfect. With CI, developers can define test cases and run it automatically before deploying to production server. Also, CI also helps streamline the whole deployment process by triggering it automatically after code merge, instead of deploying by humans.

With CI, you can do more as follows:

Continuous Integration service providers There are several service providers of Continuous Integration, such as CircleCI, Travis CI, etc. Some of them offers free package for open source projects. If you have an open source projects, it is worth a try.

In this blog post, the main focus is on CI with CircleCI.

CI for Google App Engine I have created this GitHub repository as an working example to demonstrate how to setup CI with Google App Engine from a GitHub repo. The detailed steps are listed in the GitHub repo. Fork it to have a try!

Here are some points to note:
  • You will need to create an CircleCI account by granting access for it to retrieve all of your repos. You may wish to create a separate GitHub account to manage your repos under different organizations.
  • The example only compiles a
    webapp2
    application in GAE. If your application needs more packages installed for a test, you will need to edit the content of file circle.yml (
    dependencies
    >
    pre
    )

CircleCI Badge for your GitHub repo You can add this in the README.md of your GitHub repo:
![](https://circleci.com/gh/<owner>/<repo>.png?&style=shield&circle-token=<YOUR TOKEN HERE>)

Find more about the badges in the CircleCI documentation.
Summary After reading this blog post, you should understand the basic idea of how to setup continuous integration for your GAE application with CircleCI and your GitHub repo.

The demo repo is a very simple application without any functionality. In reality, you may need to take care of your application by defining more complex test cases to ensure it works.

Tuesday, December 8, 2015

More details on Google App Engine os.environ attributes

We can use python
os
package in Google App Engine to obtain some useful information for the request. As mentioned, we can obtain user geolocation of a user. Actually, there is a lot more we can do with it.

A LIVE DEMO is available. The demo contains a full list of
os.environ
keys and their corresponding values. Some values are not publicly disclosed, but you can try it in your own application.

The values are accessed with
os.environ[key]
with
key
value available, such as
HTTP_USER_AGENT
and
REMOTE_ADDR
. However, some of the App Engine-specific keys such as
USER_EMAIL
and
HTTP_X_APPENGINE_COUNTRY
, only exist in the GAE environment.

The following section comes with the complete source code.


Wednesday, September 9, 2015

How to obtain user geolocation with Google App Engine

Sometimes it is good to provide a better user experience by obtaining geolocation of a user. In Google App Engine, we can use the information in python
os
package to achieve this:

Get the current city of a user:

Get the current country of a user (Will return a ISO 3166-1 alpha-2 country code):

Note: If App Engine fails to supply a city name or country code, the output will be the second argument supplied to the
os.environ.get()
function call.

Update 13 Oct 2015: Added a Demo link

Update 7 Nov 2015: Added complete source code.