[ google cloud SDK ] Installation on macOS

1.download from https://cloud.google.com/sdk/docs/

2. install

$ ./install.sh
Welcome to the Google Cloud SDK!

To help improve the quality of this product, we collect anonymized usage data
and anonymized stacktraces when crashes are encountered; additional information
is available at <https://cloud.google.com/sdk/usage-statistics>. You may choose
to opt out of this collection now (by choosing 'N' at the below prompt), or at
any time in the future by running the following command:

gcloud config set disable_usage_reporting true

Do you want to help improve the Google Cloud SDK (Y/n)? n

 

Your current Cloud SDK version is: 183.0.0
The latest available version is: 183.0.0

┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Components │
├───────────────┬──────────────────────────────────────────────────────┬──────────────────────────┬───────────┤
│ Status │ Name │ ID │ Size │
├───────────────┼──────────────────────────────────────────────────────┼──────────────────────────┼───────────┤
│ Not Installed │ App Engine Go Extensions │ app-engine-go │ 97.7 MiB │
│ Not Installed │ Cloud Bigtable Command Line Tool │ cbt │ 4.0 MiB │
│ Not Installed │ Cloud Bigtable Emulator │ bigtable │ 3.5 MiB │
│ Not Installed │ Cloud Datalab Command Line Tool │ datalab │ < 1 MiB │
│ Not Installed │ Cloud Datastore Emulator │ cloud-datastore-emulator │ 17.7 MiB │
│ Not Installed │ Cloud Datastore Emulator (Legacy) │ gcd-emulator │ 38.1 MiB │
│ Not Installed │ Cloud Pub/Sub Emulator │ pubsub-emulator │ 33.2 MiB │
│ Not Installed │ Emulator Reverse Proxy │ emulator-reverse-proxy │ 14.5 MiB │
│ Not Installed │ Google Container Local Builder │ container-builder-local │ 3.7 MiB │
│ Not Installed │ Google Container Registry's Docker credential helper │ docker-credential-gcr │ 2.2 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 │ 118.4 MiB │
│ Not Installed │ gcloud app PHP Extensions │ app-engine-php │ 21.9 MiB │
│ Not Installed │ gcloud app Python Extensions │ app-engine-python │ 6.2 MiB │
│ Not Installed │ gcloud app Python Extensions (Extra Libraries) │ app-engine-python-extras │ 27.8 MiB │
│ Not Installed │ kubectl │ kubectl │ 12.2 MiB │
│ Installed │ BigQuery Command Line Tool │ bq │ < 1 MiB │
│ Installed │ Cloud SDK Core Libraries │ core │ 6.9 MiB │
│ Installed │ Cloud Storage Command Line Tool │ gsutil │ 3.3 MiB │
└───────────────┴──────────────────────────────────────────────────────┴──────────────────────────┴───────────┘
To install or remove components at your current SDK version [183.0.0], run:
$ gcloud components install COMPONENT_ID
$ gcloud components remove COMPONENT_ID

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

 

Modify profile to update your $PATH and enable shell command
completion?

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

The Google Cloud SDK installer will now prompt you to update an rc
file to bring the Google Cloud CLIs into your environment.

Enter a path to an rc file to update, or leave blank to use
[/Users/phongsathorneakamongul/.bash_profile]:
Backing up [/Users/phongsathorneakamongul/.bash_profile] to [/Users/phongsathorneakamongul/.bash_profile.backup].
[/Users/phongsathorneakamongul/.bash_profile] has been updated.

==> Start a new shell for the changes to take effect.

 

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

3. install app-engine-python

$ gcloud components install app-engine-python

 

Your current Cloud SDK version is: 183.0.0
Installing components from version: 183.0.0

┌──────────────────────────────────────────────────┐
│ These components will be installed. │
├──────────────────────────────┬─────────┬─────────┤
│ Name │ Version │ Size │
├──────────────────────────────┼─────────┼─────────┤
│ gcloud app Python Extensions │ 1.9.64 │ 6.2 MiB │
└──────────────────────────────┴─────────┴─────────┘

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

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

╔════════════════════════════════════════════════════════════╗
╠═ Creating update staging area ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Installing: gcloud app Python Extensions ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Creating backup and activating new installation ═╣
╚════════════════════════════════════════════════════════════╝

Performing post processing steps...done.

Update done!

WARNING: There are older versions of Google Cloud Platform tools on your system PATH.
Please remove the following to avoid accidentally invoking these old tools:

/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/endpointscfg.py
/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/dev_appserver.py

4. Install app-engine-python-extras

$ gcloud components install app-engine-python-extras

 

Your current Cloud SDK version is: 183.0.0
Installing components from version: 183.0.0

┌─────────────────────────────────────────────────────────────────────┐
│ These components will be installed. │
├────────────────────────────────────────────────┬─────────┬──────────┤
│ Name │ Version │ Size │
├────────────────────────────────────────────────┼─────────┼──────────┤
│ gcloud app Python Extensions (Extra Libraries) │ 1.9.63 │ 27.8 MiB │
└────────────────────────────────────────────────┴─────────┴──────────┘

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

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

╔════════════════════════════════════════════════════════════╗
╠═ Creating update staging area ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Installing: gcloud app Python Extensions (Extra Libra... ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Creating backup and activating new installation ═╣
╚════════════════════════════════════════════════════════════╝

Performing post processing steps...done.

Update done!

WARNING: There are older versions of Google Cloud Platform tools on your system PATH.
Please remove the following to avoid accidentally invoking these old tools:

/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/endpointscfg.py
/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/dev_appserver.py

Running application

Switch to env

$ source env/bin/activate

Install dependency from pip

$ pip install -t lib -r requirements.txt

Test local script including the lib

PYTHONPATH=./lib python db/connection.py

Run local server

$ dev_appserver.py app.yaml

http://localhost:8080

Deploy

$ gcloud auth login

$ gcloud app deploy --project mp3songsearch

ref : https://cloud.google.com/appengine/docs/standard/python/download

https://cloud.google.com/appengine/docs/standard/python/getting-started/python-standard-env

Advertisements

[ django 2.0 ] 101

Prerequisite

  • python3

Installation on macOS

$ brew install python3

ref : http://docs.python-guide.org/en/latest/starting/install3/osx/

Testing the python3 installation

We will use python3 command to execute python3.

$ python3 --version
Python 3.6.4
$ python --version
Python 2.7.10

Download django 2.1 from source

$ git clone https://github.com/django/django.git

Testing

$ python3 -m django --version
2.1

 

ref : https://docs.djangoproject.com/en/2.0/topics/install/

[ openshift v3 ] deploy the images to private docker repository

Openshift’s container registry is free for 30 days, so I move to docker hub registry ( that provide 1 private repository for free )

Before

image_configuration_before

After

image_registry_after.png

NOTE : checkout from openshift/nodejs:latest

and push to dsin/nodejs-mongo-persistent ( see more at Builds > Images )

 

 

Example of ~/.docker/config.json file

NOTE : On windows, make sure to run docker login command from the “Docker Quickstart Terminal” ( ref : https://dsin.wordpress.com/2017/12/14/docker-docker-for-windows-installer-error-on-windows-7/ )

{ "auths": {</pre>
"https://index.docker.io/v1/": {

"auth": "WhatEverGeneratedRandomValue=="

}

},

"HttpHeaders": {

"User-Agent": "Docker-Client/17.10.0-ce (windows)"

}

}

 

Build Error#1 

An error occurred connecting to the server.
Failed to list imagestreams/v1 (status 504)

openshift_server_error

Cause 

Example : starter-us-west-1 experience elevated api errors

ref : https://status.starter.openshift.com/

 

Build Error#2

Pulling image "whatever/whatever" ...
pulling image error : unauthorized: authentication required
error: build error: unable to get whatever/whatever:latest

Cause

`Docker Image` may not be at `hub.docker.com`.

It may link to `registry.access.redhat.com`.

ref : https://stackoverflow.com/questions/46574214/docker-push-got-error-parsing-http-405-post-not-allowed

 

Using command line

$ ./oc get build
NAME TYPE FROM STATUS STARTED DURATION
nodejs-mongo-persistent-5 Source Git@3dc71ee Failed (PushImageToRegistryFailed) 2 hours ago 4m20s
nodejs-mongo-persistent-6 Source Git@3dc71ee Failed (PullBuilderImageFailed) About an hour ago 35s

Phongsathorn.E@THRYWKS0008 MINGW64 ~/Downloads/openshift-origin-client-tools-v3.7.0-7ed6862-windows
$ ./oc logs build/nodejs-mongo-persistent-6
Cloning "git@bitbucket.org:dsin/openshift-nodejs-v3.git" ...
Commit: 3dc71ee9644c189ec3e1fe551c116cce7ad1db02 (initial commit)
Author: Phongsathorn Eakamongul <phongsathorn.eakamongul@whatever.com>
Date: Fri Dec 29 13:34:15 2017 +0700
Pulling image "dsin/openshift-docker-nodejs" ...
pulling image error : unauthorized: authentication required
error: build error: unable to get dsin/openshift-docker-nodejs:latest

[ openshift v3 ] build private repository bitbucket using web console ( without oc client )

1.generate openshift-bitbucket-key and openshift-bitbucket-key.pub on local machine.

2.adding Public key to bitbucket.

bitbucket_access_key

3. adding Private key to openshift

openshift_secret

openshift_secret_setup

NOTE : choose Service Account : builder

This should be the same as the following oc command ( ref : https://blog.openshift.com/private-git-repositories-part-5-hosting-repositories-bitbucket/ )

$ ls
LICENSE openshift-bitbucket-key README.md
oc.exe* openshift-bitbucket-key.pub

$ oc secrets new-sshauth openshift-bitbucket-key --ssh-privatekey=openshift-bitbucket-key

$ oc secrets link builder openshift-bitbucket-key

4. Change Git repository to bitbucket

Before

openshift_setting_up_private_git_repository_before

After

openshift_setting_up_private_git_repository_after

5.Click Start build

start_build.png

[ sql ] exact word match using RLIKE

SELECT * FROM products WHERE product_name RLIKE "[[:<:]]foo[[:>:]]";
([[:blank:][:punct:]]|^)foo([[:blank:][:punct:]]|$)

NOTE :

  • `[:blank:]` : Space and tab
  • `[:punct:]` : Punctuation and symbols

This matches foo when preceeded by:

  • a blank (space, tab etc)
  • punctuation (comma, bracket etc)
  • nothing (ie at start of line)

and followed by:

  • a blank (space, tab etc)
  • punctuation (comma, bracket etc)
  • nothing (ie at end of line)

ref : https://stackoverflow.com/questions/5743177/mysql-how-to-search-for-exact-word-match-using-like

https://stackoverflow.com/questions/18153898/whole-word-matching-with-dot-characters-in-mysql