analitics

Pages

Friday, August 18, 2017

The Google Cloud SDK - part 002 .

The next part of my tutorials about the Google Cloud SDK comes with some info about the project.
As you know I used the default sample app engine hello word standard application.
The goal is to understand how it works by working with Google's documentation and examples.
Into this project folder we have this files:
08/17/2017  11:12 PM                98 app.yaml
08/17/2017  11:12 PM               854 main.py
08/17/2017  11:12 PM               817 main_test.py
Let's see what these files contain:
First is app.yaml and come with:
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /.*
  script: main.app
The next is main.py file:
# Copyright 2016 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import webapp2


class MainPage(webapp2.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.write('Hello, World!')


app = webapp2.WSGIApplication([
    ('/', MainPage),
], debug=True)
The last from this folder is main_test.py :
# Copyright 2016 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import webtest

import main


def test_get():
    app = webtest.TestApp(main.app)

    response = app.get('/')

    assert response.status_int == 200
    assert response.body == 'Hello, World!'
The app.yaml file is used to configure your App Engine application's settings of the project.
You can have many application-level configuration files (dispatch.yaml, cron.yaml, index.yaml, and queue.yaml).
This all type of configuration files are included in the top level app directory ( in this case: hello_world).
Let's see some common gcloud commands:
  • gcloud app deploy  --project XXXXXX - deploy your project;
  • gcloud app browse - show your project running into your browser;
  • gcloud components list - show all available components;
  • gcloud components update - update all gcloud components;
  • gcloud projects list --limit=10 - show all projects with a limit number;
Let's test some changes:
First, change the text from main.py file with something else:
self.response.write('Hello, World!')
Now use this commands:
C:\Python27\python-docs-samples\appengine\standard\hello_world>gcloud app deploy
C:\Python27\python-docs-samples\appengine\standard\hello_world>gcloud app browse
The result is shown in your browser.
You can read about this files into google documentation page - here.
Also some gcloud commands and reference you can read here.

Thursday, August 17, 2017

The Google Cloud SDK - part 001 .

This tutorial will cover this steps into development with Google Cloud SDK and Python version 2.7:

  • install the Google Cloud SDK on the computer;
  • make settings online for your Google project to use Google Cloud SDK;
  • run the online project of Google Cloud SDK;
  • make setting into your computer to run the local project ;

First, you need to download the Google Cloud SDK and run it.


After GUI install a window command will ask you to set the default project for your work.
Welcome to the Google Cloud SDK! Run "gcloud -h" to get the list of available commands.
---
Welcome! This command will take you through the configuration of gcloud.

Your current configuration has been set to: [default]

You can skip diagnostics next time by using the following flag:
  gcloud init --skip-diagnostics

Network diagnostic detects and fixes local network connection issues.
Checking network connection...done.
Reachability Check passed.
Network diagnostic (1/1 checks) passed.

You must log in to continue. Would you like to log in (Y/n)?  Y
...
The next step is to start online to deploying a Hello World app with: Deploy a Hello World app:

This will start an online tutorial into the right area of the screen with all commands and steps for your Google Cloud SDK online project.
Follow this steps and in the end will see how the online Google Cloud SDK project will show: Hello, World! into your browser.
The next step is to make a local project and run it.
You can use the python docs sample from GoogleCloudPlatform but is not the same with the online example.
To download the GoogleCloudPlatform sample use git command:
C:\Python27>git clone https://github.com/GoogleCloudPlatform/python-docs-samples
Cloning into 'python-docs-samples'...
remote: Counting objects: 12126, done.
remote: Compressing objects: 100% (16/16), done.
remote: Total 12126 (delta 1), reused 10 (delta 1), pack-reused 12106
Receiving objects: 100% (12126/12126), 3.37 MiB | 359.00 KiB/s, done.
Resolving deltas: 100% (6408/6408), done.

C:\Python27>cd python-docs-samples/appengine/standard/hello_world
To start this sample into your google project you need to use this:
C:\Python27\python-docs-samples\appengine\standard\hello_world>gcloud app deploy app.yaml --project encoded-metrics-147522
Services to deploy:

descriptor:      [C:\Python27\python-docs-samples\appengine\standard\hello_world\app.yaml]
source:          [C:\Python27\python-docs-samples\appengine\standard\hello_world]
target project:  [encoded-metrics-147522]
target service:  [default]
target version:  [20170817t234925]
target url:      [https://encoded-metrics-147522.appspot.com]


Do you want to continue (Y/n)?  Y

Beginning deployment of service [default]...
#============================================================#
#= Uploading 5 files to Google Cloud Storage                =#
#============================================================#
File upload done.
Updating service [default]...done.
Waiting for operation [apps/encoded-metrics-147522/operations/XXXXXX] to complete...done.
Updating service [default]...done.
Deployed service [default] to [https://XXXXXX.appspot.com]

You can stream logs from the command line by running:
  $ gcloud app logs tail -s default

To view your application in the web browser run:
  $ gcloud app browse

C:\Python27\python-docs-samples\appengine\standard\hello_world>gcloud app browse
Opening [https://XXXXXX.appspot.com] in a new tab in your default browser.

C:\Python27\python-docs-samples\appengine\standard\hello_world>
This will start your application with the text - Hello, World! into your browser address bar with this web address: XXXXXX.appspot.com.