Google Cloud Platform - App Engine Basics

Google Cloud Platform - App Engine Basics

Google Cloud App Engine

Name Value
Account Used am..info@gmail.com
Date 1 June 2024
Samples URL https://github.com/GoogleCloudPlatform/golang-samples/tree/main/appengine/go11x
Local clone dir workspace/p_github/GCP/golang-samples
Samples Dir GCP/golang-samples/appengine/helloworld

Install Google Cloud SDK on macOS using homebrew

brew install --cask google-cloud-sdk

==> Caveats
To add gcloud components to your PATH, add this to your profile:

  for bash users
    source "$(brew --prefix)/share/google-cloud-sdk/path.bash.inc"

  for zsh users
    source "$(brew --prefix)/share/google-cloud-sdk/path.zsh.inc"
    source "$(brew --prefix)/share/google-cloud-sdk/completion.zsh.inc"

  for fish users
    source "$(brew --prefix)/share/google-cloud-sdk/path.fish.inc"

echo 'source "$(brew --prefix)/share/google-cloud-sdk/path.bash.inc"' >> ~/.bashrc

echo 'source "$(brew --prefix)/share/google-cloud-sdk/completion.zsh.inc"' >> ~/.zshrc

echo 'source "$(brew --prefix)/share/google-cloud-sdk/path.fish.inc"' >> ~/.config/fish/config.fish


All dependencies satisfied.
==> Installing Cask google-cloud-sdk
==> Running installer script 'google-cloud-sdk/install.sh'
Welcome to the Google Cloud CLI!

Your current Google Cloud CLI version is: 478.0.0
The latest available version is: 478.0.0

┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                                    Components                                                   │
├───────────────┬──────────────────────────────────────────────────────┬──────────────────────────────┬───────────┤
│     Status    │                         Name                         │              ID              │    Size   │
├───────────────┼──────────────────────────────────────────────────────┼──────────────────────────────┼───────────┤
│ Not Installed │ App Engine Go Extensions                             │ app-engine-go                │   4.5 MiB │
│ Not Installed │ Appctl                                               │ appctl                       │  18.5 MiB │
│ Not Installed │ Artifact Registry Go Module Package Helper           │ package-go-module            │   < 1 MiB │
│ Not Installed │ Cloud Bigtable Command Line Tool                     │ cbt                          │  17.1 MiB │
│ Not Installed │ Cloud Bigtable Emulator                              │ bigtable                     │   7.0 MiB │
│ Not Installed │ Cloud Datastore Emulator                             │ cloud-datastore-emulator     │  36.2 MiB │
│ Not Installed │ Cloud Firestore Emulator                             │ cloud-firestore-emulator     │  45.2 MiB │
│ Not Installed │ Cloud Pub/Sub Emulator                               │ pubsub-emulator              │  63.7 MiB │
│ Not Installed │ Cloud Run Proxy                                      │ cloud-run-proxy              │  11.3 MiB │
│ Not Installed │ Cloud SQL Proxy v2                                   │ cloud-sql-proxy              │  13.2 MiB │
│ Not Installed │ Google Container Registry's Docker credential helper │ docker-credential-gcr        │           │
│ Not Installed │ Kustomize                                            │ kustomize                    │   7.4 MiB │
│ Not Installed │ Log Streaming                                        │ log-streaming                │  11.9 MiB │
│ Not Installed │ Minikube                                             │ minikube                     │  34.8 MiB │
│ Not Installed │ Nomos CLI                                            │ nomos                        │  28.7 MiB │
│ Not Installed │ On-Demand Scanning API extraction helper             │ local-extract                │  13.7 MiB │
│ Not Installed │ Skaffold                                             │ skaffold                     │  22.8 MiB │
│ Not Installed │ Terraform Tools                                      │ terraform-tools              │  63.6 MiB │
│ Not Installed │ anthos-auth                                          │ anthos-auth                  │  20.9 MiB │
│ Not Installed │ config-connector                                     │ config-connector             │  88.7 MiB │
│ Not Installed │ enterprise-certificate-proxy                         │ enterprise-certificate-proxy │   8.3 MiB │
│ Not Installed │ gcloud Alpha Commands                                │ alpha                        │   < 1 MiB │
│ Not Installed │ gcloud Beta Commands                                 │ beta                         │   < 1 MiB │
│ Not Installed │ gcloud app Java Extensions                           │ app-engine-java              │ 126.9 MiB │
│ Not Installed │ gcloud app PHP Extensions                            │ app-engine-php               │  21.9 MiB │
│ Not Installed │ gcloud app Python Extensions                         │ app-engine-python            │   5.0 MiB │
│ Not Installed │ gcloud app Python Extensions (Extra Libraries)       │ app-engine-python-extras     │   < 1 MiB │
│ Not Installed │ gke-gcloud-auth-plugin                               │ gke-gcloud-auth-plugin       │   7.4 MiB │
│ Not Installed │ istioctl                                             │ istioctl                     │  24.8 MiB │
│ Not Installed │ kpt                                                  │ kpt                          │  13.8 MiB │
│ Not Installed │ kubectl                                              │ kubectl                      │   < 1 MiB │
│ Not Installed │ kubectl-oidc                                         │ kubectl-oidc                 │  20.9 MiB │
│ Not Installed │ pkg                                                  │ pkg                          │           │
│ Installed     │ BigQuery Command Line Tool                           │ bq                           │   1.7 MiB │
│ Installed     │ Cloud Storage Command Line Tool                      │ gsutil                       │  11.3 MiB │
│ Installed     │ Google Cloud CLI Core Libraries                      │ core                         │  18.6 MiB │
│ Installed     │ Google Cloud CRC32C Hash Tool                        │ gcloud-crc32c                │   1.2 MiB │
└───────────────┴──────────────────────────────────────────────────────┴──────────────────────────────┴───────────┘

For more information on how to get started, please visit:
  https://cloud.google.com/sdk/docs/quickstarts


To install or remove components at your current SDK version [478.0.0], run:
  $ gcloud components install COMPONENT_ID
  $ gcloud components remove COMPONENT_ID

To update your SDK installation to the latest version [478.0.0], run:
  $ gcloud components update

==> Source [/opt/homebrew/share/google-cloud-sdk/completion.zsh.inc] in your profile to enable shell command completion for gcloud.
==> Source [/opt/homebrew/share/google-cloud-sdk/path.zsh.inc] in your profile to add the Google Cloud SDK command line tools to your $PATH.
==> Linking Binary 'gcloud' to '/opt/homebrew/bin/gcloud'
==> Linking Binary 'git-credential-gcloud.sh' to '/opt/homebrew/bin/git-credential-gcloud'
==> Linking Binary 'gsutil' to '/opt/homebrew/bin/gsutil'
==> Linking Binary 'completion.zsh.inc' to '/opt/homebrew/share/zsh/site-functions/_google_cloud_sdk'
==> Linking Binary 'completion.bash.inc' to '/opt/homebrew/etc/bash_completion.d/google-cloud-sdk'
==> Linking Binary 'bq' to '/opt/homebrew/bin/bq'
==> Linking Binary 'docker-credential-gcloud' to '/opt/homebrew/bin/docker-credential-gcloud'
🍺  google-cloud-sdk was successfully installed!

Enable App Engine in your Google Cloud Project

Initialize your gcloud CLI tool

gcloud init

gcloud init
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 passed (1/1 checks passed).

You must log in to continue. Would you like to log in (Y/n)?  Y

Your browser has been opened to visit:

    https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=<some_number>.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A8085%2F&scope=openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.admin+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fsqlservice.login+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcompute+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Faccounts.reauth&state=ASA4chZB7sDLROthN1EjlC7rvx3s4l&access_type=offline&code_challenge=RPplGrxX46IbbKSIxL5-kYSvP-dZPNbrKlPgUdnJpi4&code_challenge_method=S256

You are logged in as: [am..info@googlemail.com].

Pick cloud project to use:
 [1] <project-sting>-425120-u7
 [2] Enter a project ID
 [3] Create a new project
Please enter numeric choice or text value (must exactly match list item):  1

Your current project has been set to: [<project-sting>-425120-u7].

Do you want to configure a default Compute Region and Zone? (Y/n)?  n

Created a default .boto configuration file at [$HOME/.boto]. See this file and
[https://cloud.google.com/storage/docs/gsutil/commands/config] for more
information about configuring Google Cloud Storage.
Your Google Cloud SDK is configured and ready to use!

* Commands that require authentication will use am..info@googlemail.com by default
* Commands will reference project `<project-sting>-425120-u7` by default
Run `gcloud help config` to learn how to change individual settings

This gcloud configuration is called [default]. You can create additional configurations if you work with multiple accounts and/or projects.
Run `gcloud topic configurations` to learn more.

Some things to try next:

* Run `gcloud --help` to see the Cloud Platform services you can interact with. And run `gcloud help COMMAND` to get help on any gcloud command.
* Run `gcloud topic --help` to learn about advanced features of the SDK like arg files and output formatting
* Run `gcloud cheat-sheet` to see a roster of go-to `gcloud` commands.


gcloud config set accessibility/screen_reader true

gcloud auth list
Credentialed Accounts

ACTIVE: *
ACCOUNT: am..info@googlemail.com

To set the active account, run:
    $ gcloud config set account `ACCOUNT`

gcloud config list

[accessibility]
screen_reader = true
[core]
account = am..info@googlemail.com
disable_usage_reporting = True
project = <project-sting>-425120-u7

Your active configuration is: [default]


gcloud info

Google Cloud SDK [478.0.0]

Platform: [Mac OS X, arm] uname_result(system='Darwin', node='D4PY4HKFH6', release='23.4.0', version='Darwin Kernel Version 23.4.0: Fri Mar 15 00:10:42 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6000', machine='arm64')
Locale: ('en_US', 'UTF-8')
Python Version: [3.10.13 (main, May 24 2024, 12:52:59) [Clang 15.0.0 (clang-1500.3.9.4)]]
Python Location: [$HOME/.pyenv/versions/3.10.13/bin/python3]
OpenSSL: [OpenSSL 3.3.0 9 Apr 2024]
Requests Version: [2.25.1]
urllib3 Version: [1.26.9]
Default CA certs file: [/opt/homebrew/Caskroom/google-cloud-sdk/478.0.0/google-cloud-sdk/lib/third_party/certifi/cacert.pem]
Site Packages: [Disabled]

Installation Root: [/opt/homebrew/share/google-cloud-sdk]
Installed Components:
  gsutil: [5.29]
  core: [2024.05.24]
  bq: [2.1.5]
  gcloud-crc32c: [1.0.0]
System PATH: [$HOME/.pyenv/versions/3.10.13/bin:/opt/homebrew/Cellar/pyenv/2.3.31/libexec:/opt/homebrew/Cellar/pyenv/2.3.31/plugins/python-build/bin:$HOME/.krew/bin:$HOME/.pyenv/shims:$HOME/.pyenv/bin:/opt/homebrew/bin:$HOME/workspace/go/bin:/usr/local/bin:$HOME/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:$HOME/bin:/Applications/Visual Studio Code.app/Contents/Resources/app/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/opt/homebrew/opt/postgresql@12/bin]
Python PATH: [/opt/homebrew/Caskroom/google-cloud-sdk/478.0.0/google-cloud-sdk/lib/third_party:/opt/homebrew/Caskroom/google-cloud-sdk/478.0.0/google-cloud-sdk/lib:/opt/homebrew/share/google-cloud-sdk/lib:$HOME/.pyenv/versions/3.10.13/lib/python310.zip:$HOME/.pyenv/versions/3.10.13/lib/python3.10:$HOME/.pyenv/versions/3.10.13/lib/python3.10/lib-dynload]
Cloud SDK on PATH: [False]
Kubectl on PATH: [/opt/homebrew/bin/kubectl]

Installation Properties: [/opt/homebrew/share/google-cloud-sdk/properties]
User Config Directory: [$HOME/.config/gcloud]
Active Configuration Name: [default]
Active Configuration Path: [$HOME/.config/gcloud/configurations/config_default]

Account: [am..info@googlemail.com]
Project: [<project-sting>-425120-u7]
Universe Domain: [googleapis.com]

Current Properties:
  [accessibility]
    screen_reader: [true] (property file)
  [core]
    account: [am..info@googlemail.com] (property file)
    disable_usage_reporting: [True] (property file)
    project: [<project-sting>-425120-u7] (property file)

Logs Directory: [$HOME/.config/gcloud/logs]
Last Log File: [$HOME/.config/gcloud/logs/2024.06.02/00.05.30.362628.log]

git: [git version 2.39.3 (Apple Git-146)]
ssh: [OpenSSH_9.6p1, LibreSSL 3.3.6]


gcloud app deploy
ERROR: An app.yaml (or appengine-web.xml) file is required to deploy this directory as an App Engine application. Create an app.yaml file using the directions at https://cloud.google.com/appengine/docs/flexible/reference/app-yaml (App Engine flexible environment) or https://cloud.google.com/appengine/docs/standard/reference/app-yaml (App Engine standard environment) under the tab for your language.
ERROR: (gcloud.app.deploy) [$HOME/workspace/p_github/sirajudheenam] could not be identified as a valid source directory or file.

Use this URL get more samples and how to deploy to Google Application Engine.

Clone this project and try one by one.

git clone git@github.com:GoogleCloudPlatform/golang-samples.git

git clone git@github.com:GoogleCloudPlatform/golang-samples.git
Cloning into 'golang-samples'...
remote: Enumerating objects: 32098, done.
remote: Counting objects: 100% (1535/1535), done.
remote: Compressing objects: 100% (741/741), done.
remote: Total 32098 (delta 967), reused 1262 (delta 765), pack-reused 30563
Receiving objects: 100% (32098/32098), 53.18 MiB | 13.51 MiB/s, done.
Resolving deltas: 100% (21145/21145), done.

cd golang-samples
ls

CODE_OF_CONDUCT.md badfiles_test.go   dialogflow         healthcare         opencensus         storage
CONTRIBUTING.md    batch              discoveryengine    iam                opentelemetry      storagetransfer
LICENSE            bigquery           dlp                iap                privateca          tasks
Makefile           bigtable           docs               internal           profiler           testing
README.md          cdn                documentai         iotkit             pubsub             texttospeech
SECURITY.md        cloudsql           endpoints          jobs               pubsublite         trace
Taskfile.yaml      compute            errorreporting     kms                regiontag_test.go  translate
aiplatform         container          eventarc           language           run                vertexai
appengine          container_registry firestore          logging            secretmanager      videointelligence
appengine_flexible datacatalog        functions          media              securitycenter     vision
asset              dataflow           getting-started    mediacdn           servicedirectory
auth               dataproc           go.mod             memorystore        spanner
automl             datastore          go.sum             monitoring         speech

cd appengine
ls
go.mod go.sum go11x
cd go11x
ls
cloudsql   helloworld pubsub     tasks      warmup
cd helloworld
ls
app.yaml           go.mod             go.sum             helloworld.go      helloworld_test.go

gcloud app deploy
The component [app-engine-go] is required for staging this
application.

Your current Google Cloud CLI version is: 478.0.0
Installing components from version: 478.0.0

These components will be installed.

Name: App Engine Go Extensions
Version: 1.9.76
Size: 4.5 MiB

Name: Cloud Datastore Emulator
Version: 2.3.1
Size: 36.2 MiB

Name: gRPC Python library
Version: 1.20.0
Size: 1.9 MiB

Name: gcloud app Python Extensions
Version: 1.9.113
Size: 5.0 MiB

Name: gcloud cli dependencies
Version: 2021.04.16
Size: < 1 MiB

For the latest full release notes, please visit:
  https://cloud.google.com/sdk/release_notes

Once started, canceling this operation may leave your SDK installation in an inconsistent state.

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

Performing in place update...
Installing: App Engine Go Extensions
100%
Installing: App Engine Go Extensions
100%
Installing: Cloud Datastore Emulator
100%
100%
Installing: gRPC Python library
100%
Installing: gRPC Python library
100%
Installing: gcloud app Python Extensions
100%
Installing: gcloud cli dependencies
100%

Performing post processing steps...done.

Update done!

Restarting command:
  $ gcloud app deploy

Services to deploy:

descriptor:                  [$HOME/workspace/p_github/sirajudheenam/GCP/golang-samples/appengine/go11x/helloworld/app.yaml]
source:                      [$HOME/workspace/p_github/sirajudheenam/GCP/golang-samples/appengine/go11x/helloworld]
target project:              [<project-sting>-425120-u7]
target service:              [default]
target version:              [20240602t001655]
target url:                  [https://<project-sting>-425120-u7.uc.r.appspot.com]
target service account:      [777632820833-compute@developer.gserviceaccount.com]


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

Beginning deployment of service [default]...
Created .gcloudignore file. See `gcloud topic gcloudignore` for details.
Uploading 6 files to Google Cloud Storage
100%
File upload done.

Updating service [default]...done.
Setting traffic split for service [default]...done.
Deployed service [default] to [https://<project-sting>-425120-u7.uc.r.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

# Test if everything works fine
curl -k https://<project-sting>-425120-u7.uc.r.appspot.com/

# this takes you to the currently deployed app on default browser of your OS.

gcloud app browse

gcloud app operations list

ID: 1dae156f-c1c0-4f5d-8a7d-47efc6bff58a
START_TIME: 2024-06-01T22:19:14.289Z
STATUS: COMPLETED

ID: 3cfaaa84-72b7-40a6-8a4b-adbf887c9f77
START_TIME: 2024-06-01T22:17:04.148Z
STATUS: COMPLETED

ID: operation-1717278622566-619db16474806-e12d3884-f06f6d9b
START_TIME: 2024-06-01T21:50:22.566434151Z
STATUS: COMPLETED

# delete this deployment
gcloud app
instances delete
ERROR: (gcloud.app.instances.delete) argument INSTANCE --service --version: Must be specified.
Usage: gcloud app instances delete INSTANCE --service=SERVICE, -s SERVICE --version=VERSION, -v VERSION [optional flags]
  optional flags may be  --help

For detailed information on this command and its flags, run:
  gcloud app instances delete --help


gcloud app delete
ERROR: (gcloud.app) Invalid choice: 'delete'.
Maybe you meant:
  gcloud apphub applications delete
  gcloud apphub applications remove-iam-policy-binding
  gcloud app instances delete
  gcloud apphub applications services delete
  gcloud apphub applications workloads delete
  gcloud app domain-mappings delete
  gcloud apphub applications add-iam-policy-binding
  gcloud apphub applications create
  gcloud apphub applications describe
  gcloud apphub applications get-iam-policy

To search the help text of gcloud commands, run:
  gcloud help -- SEARCH_TERMS


gcloud apphub applications list --location us-central
API [apphub.googleapis.com] not enabled on project [<project-sting>-425120-u7]. Would you like to enable and retry (this will take a few minutes)? (y/N)?  y

Enabling service [apphub.googleapis.com] on project [<project-sting>-425120-u7]...
Operation "operations/acat.p2-777632820833-ff6e066a-630a-4d67-bc4f-a458aa45cca0" finished successfully.
ERROR: (gcloud.apphub.applications.list) PERMISSION_DENIED: Location us-central is not found or access is unauthorized. This command is authenticated as am..info@googlemail.com which is the active account specified by the [core/account] property.

https://console.cloud.google.com/appengine/instances?serviceId=default&hl=en&project=<project-sting>-425120-u7&versionId=20240602t001655


# Deleted Project on GCP Console

# Do it again.

gcloud app deploy

Services to deploy:

descriptor:                  [$HOME/workspace/p_github/sirajudheenam/GCP/golang-samples/appengine/go11x/helloworld/app.yaml]
source:                      [$HOME/workspace/p_github/sirajudheenam/GCP/golang-samples/appengine/go11x/helloworld]
target project:              [<project-sting>-425120-u7]
target service:              [default]
target version:              [20240602tXXXXXX]
target url:                  [https://<project-sting>-425120-u7.uc.r.appspot.com]
target service account:      [XXXXXXXXXXXX-compute@developer.gserviceaccount.com]

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

Beginning deployment of service [default]...
Uploading 0 files to Google Cloud Storage
100%
File upload done.

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

Beginning deployment of service [default]...
Uploading 0 files to Google Cloud Storage
100%
File upload done.
Updating service [default]...done.
Setting traffic split for service [default]...done.
Deployed service [default] to [https://<project-sting>-425120-u7.uc.r.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