2018/08/15

GCP: gcloud のバージョンアップ時のエラーと解消方法 on Windows Subsystem for Linux


  • GAEのFlexible environmentを利用するにあたり、コンソール画面でデプロイしたソースを見れるようにするには、gcloudを195以上にしないと駄目らしい。
  • 188から最新版にUPDATEしようとしたら、エラーが出たので経緯と対応手順メモ
  • 開発環境は、Windows10+Bash on windows(Ubuntu 16.04.3)

以下、ログ

~#
gcloud components update
# 普通にアップデートしようとしたら以下のエラー
ERROR: (gcloud.components.update)
You cannot perform this action because the Cloud SDK component manager is disabled for this installation. You can run the following command to achieve the same result for this installation:
sudo apt-get update && sudo apt-get --only-upgrade install kubectl google-cloud-sdk google-cloud-sdk-datastore-emulator google-cloud-sdk-pubsub-emulator google-cloud-sdk-app-engine-go google-cloud-sdk-app-engine-java google-cloud-sdk-app-engine-python google-cloud-sdk-cbt google-cloud-sdk-bigtable-emulator google-cloud-sdk-app-engine-python-extras google-cloud-sdk-datalab

~# sudo -E apt-get update
# 私の環境では −E が必要
Hit:1 http://archive.ubuntu.com/ubuntu xenial InRelease
Get:2 http://packages.cloud.google.com/apt cloud-sdk-xenial InRelease [6,372 B]
Err:2 http://packages.cloud.google.com/apt cloud-sdk-xenial InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 6A030B21BA07F4FB
(省略)
Reading package lists... Done
W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://packages.cloud.google.com/apt cloud-sdk-xenial InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 6A030B21BA07F4FB
(省略)
# よくわからないけど、Public Key が使えないとかなんとか。。。
# Google Groupsのトピによると、以下でKeyを追加せよとのこと

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1326  100  1326    0     0   2062      0 --:--:-- --:--:-- --:--:--  2062
OK

# 再トライ 
~# sudo -E apt-get update
Get:1 http://packages.cloud.google.com/apt cloud-sdk-xenial InRelease [6,372 B]
Hit:2 http://archive.ubuntu.com/ubuntu xenial InRelease
Get:3 http://packages.cloud.google.com/apt cloud-sdk-xenial/main amd64 Packages [45.3 kB]
Hit:4 http://archive.ubuntu.com/ubuntu xenial-updates InRelease
Get:5 http://security.ubuntu.com/ubuntu xenial-security InRelease [107 kB]
Fetched 158 kB in 1s (84.8 kB/s)
Reading package lists... Done

# うまくいった
# つづいて、SDKのUPDATE 余計なパッケージ名もあるけど、そのまま実行

~# sudo -E apt-get --only-upgrade install kubectl google-cloud-sdk google-cloud-sdk-datastore-emulat
or google-cloud-sdk-pubsub-emulator google-cloud-sdk-app-engine-go google-cloud-sdk-app-engine-java google-cloud-sdk-app
-engine-python google-cloud-sdk-cbt google-cloud-sdk-bigtable-emulator google-cloud-sdk-app-engine-python-extras google-
cloud-sdk-datalab
Reading package lists... Done
Building dependency tree
Reading state information... Done
Skipping google-cloud-sdk-app-engine-go, it is not installed and only upgrades are requested.
Skipping google-cloud-sdk-app-engine-java, it is not installed and only upgrades are requested.
Skipping google-cloud-sdk-app-engine-python, it is not installed and only upgrades are requested.
Skipping google-cloud-sdk-app-engine-python-extras, it is not installed and only upgrades are requested.
Skipping google-cloud-sdk-bigtable-emulator, it is not installed and only upgrades are requested.
Skipping google-cloud-sdk-cbt, it is not installed and only upgrades are requested.
Skipping google-cloud-sdk-datalab, it is not installed and only upgrades are requested.
Skipping google-cloud-sdk-datastore-emulator, it is not installed and only upgrades are requested.
Skipping google-cloud-sdk-pubsub-emulator, it is not installed and only upgrades are requested.
Skipping kubectl, it is not installed and only upgrades are requested.
The following package was automatically installed and is no longer required:
  snap-confine
Use 'sudo apt autoremove' to remove it.
Suggested packages:
  google-cloud-sdk-app-engine-java google-cloud-sdk-app-engine-python google-cloud-sdk-pubsub-emulator
  google-cloud-sdk-bigtable-emulator google-cloud-sdk-datastore-emulator kubectl
The following packages will be upgraded:
  google-cloud-sdk
1 upgraded, 0 newly installed, 0 to remove and 155 not upgraded.
Need to get 19.2 MB of archives.
After this operation, 28.8 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://packages.cloud.google.com/apt cloud-sdk-xenial/main amd64 google-cloud-sdk all 212.0.0-0 [19.2 MB]
Fetched 19.2 MB in 11s (1,652 kB/s)
(Reading database ... 50185 files and directories currently installed.)
Preparing to unpack .../google-cloud-sdk_212.0.0-0_all.deb ...
Unpacking google-cloud-sdk (212.0.0-0) over (188.0.1-0) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up google-cloud-sdk (212.0.0-0) ...

# 完了 
~# gcloud --version
Google Cloud SDK 212.0.0
alpha 2018.08.13
beta 2018.08.13
bq 2.0.34
core 2018.08.13
gsutil 4.33

2018/07/29

リストの要素の重複排除とNone(空要素)の排除 − Python

  • Goal
    リスト型の要素の中の重複排除とNone(空要素)を排除する。
    集合型(set)なら、重複排除は自動でできて、.discardでNoneは排除可能だが、リスト型で行いたい。理由は、リスト内の順番をキープしたいから。
  • How
    if で要素があるかどうか?と長さが0より大きいかを確認する。
    ※filterを使うとか、内包表記を使うとか色々載っていたが、これが一番分かりやすかった。。。
  • Result

    ~$ python eliminating_duplication.py
    === inputtext
    Aaa
    bBbb

    CCddff

    Aaa


    === after normalize
    AAA
    BBBB

    CCDDFF

    AAA


    === normal list splitted by \n
    [u'AAA', u'BBBB', u'', u'CCDDFF', u'', u'AAA', u'', u'']
    === normal list with splitlines
    [u'AAA', u'BBBB', u'', u'CCDDFF', u'', u'AAA', u'']
    === eliminating duplication and None
    [u'AAA', u'BBBB', u'CCDDFF']

2018/07/01

GCP: gcloud コマンドで GAEのログを取る方法

備忘録
GAE アプリのログ解析をする場合、Stackdriver logging からログを取り出す必要あり。gcloud コマンドで簡単にできる。





2018/05/27

GCP: GAE appcfg.py の使い方

GAEの appcfg.py の使い方。Deploy以外にも使うことがあり、備忘録



2018/02/25

GCP: GAE上にAPI(POST)を作成ーDatastoreの操作(Create) ー Python



  • Goal
    GAE(Google App Engine)上にREST API(メソッドはPOST)を作成する。
    APIが呼び出されたら、GCP(Google Cloud Platform)のDatastoreに新規Entity(レコード)を追加する。言語・環境はPython+flask。
  • case
    名前、点数、教科名をjsonでPOSTしたら、GCPのDatastoreに書き込みして、Keyを返信する。
  • How
    1:開発環境は、以下でセットアップ
      Ubuntu16.4 + Pyenv:Python2.7.13 on GCE
      GCP: Google App Engine上にPython(Flask)アプリを立ち上げる手順

    2:ライブラリのセットアップ
      app.yaml に、flaskの記述を追加
      - name: flask
        version: 0.12

    3:mainプログラム と curl 結果


    4:Datastoreの結果

  • Thanks!

2018/02/24

Docker CE のディレクトリを引っ越しする方法

AWSのEC2 RHEL7.4 にDocker CEをセットアップする手順 の後に、Rootディレクトリを引っ越しする方法


・システム領域のハードディスクを大量に消費するので、別ディレクトリへ引っ越しする
以下の例は、/var/lib/docker から /xxx/mnt/docker/ へ引越し
0.初期設定確認
1.ServiceSTOP
2.ディレクトリを作ってコピー
3.設定変更
4.ServiceStart



2018/02/11

GCP: GAE(Google App Engine)のバージョン別のURL

GAEは、バージョン別に個別のURLをもっている。
なので、同時に複数バージョンを公開してテストできる。
知らなかった。。。

サンプル

https://"バージョン名"-dot-"プロジェクト名".appspot.com/