Pages

Sunday, March 16, 2014

Google App Engine Hello World using Push to Deploy

Ever wished you could deploy to Google App Engine with the same standard tools you use to version your code? Now you can. With the Push-to-Deploy feature you can get your code onto App Engine using git and bypassing the SDK. Here is a quick example on how to clone a sample app from an existing public repository and deploy it as your own App Engine application.



Prerequisites: If you don’t have the git tool installed, get it here.



Setting up your Push-to-Deploy repository:



1. Go to the Google Cloud Console and create a project (this also creates an App Engine app) or use an existing one



2. In the App Engine Admin Console for your app (App Engine, select app, then click Application Settings on left nav bar), enable Source Push-to-deploy



3. Obtain and copy both the auth token by clicking on the link, and the repo URL that is displayed in the box:



4. In order to avoid having to type the password on each deployment, you can store the credentials locally. For this, locate your netrc file:



On Windows

Make sure there is a file named _netrc in your home directory. Also check that the HOME environment variable exists and that it points to your home directory:



$ setx HOME %USERPROFILE%


On Mac or Linux

Make sure there is a file named .netrc in your home directory.



5. Set the contents of the netrc file:

Use the auth token from step 3 (shown as <auth-token> below) and the email address from your Google account. The file should contain one line that looks like this:



machine code.google.com login <email-address> password <auth-token>


Creating/cloning an app and deploying:



6. Clone an App Engine project (example from Github)



Get to the OS prompt (Terminal on Mac, cmd on Windows), navigate to a directory where you would like to store the sample app’s source code (e.g. cd ~/Desktop), and clone the App Engine Guestbook app repository:



$ git clone https://github.com/GoogleCloudPlatform/appengine-helloworld-python.git




7. Edit the app.yaml file with the new application id

The previous step downloaded the source code for the sample Hello World app. Navigate to that folder.



$ cd appengine-helloworld-python


Open the app.yaml file and change the “application” field to the project name or app id from step 1



8. Initialize local git repo, and set up remote repo (<repo-url> obtained in step 3). In the same directory that contains the source code, and on the terminal prompt type:



$ git remote add appengine <repo-url>


The steps above initialize your local repo, add all the files to it, commit them, and set up an alias to the remote repo we will be pushing to



9. Deploy your app:

$ git push appengine master


And that’s it! The sample app is ready to serve at http://<your-app-id>.appspot.com.



Using this feature simplifies the deployment process by allowing you to use the standard git tool instead of our SDK. We hope you find this functionality useful and look forward to your comments and feedback.



-Posted by Sachin Kotwani, Product Manager

Related Post:

0 comments:

Post a Comment