tweeeetyのぶろぐ的めも

アウトプットが少なかったダメな自分をアウトプット<br>\(^o^)/

【gulp】gulpのtaskを任意のタイミングで中断(kill)する - process.exit

はじめに

さまざまな時にgulpのタスクを終了させたい事があります。
そんなときのメモ

process.exitを使う

process.exitを使う事でgulp taskを中断できます

たとえば以下のように使います。

  • gulpfile.js
var gulp = require('gulp');

gulp.task('task', ['task1', 'task2', 'task-kill', 'task3']);

gulp.task('task1', function() {
  console.log('i am task1!!');
});

gulp.task('task2', function() {
  console.log('i am task2!!');
});

gulp.task('task-kill', function() {
  console.log("before kill task");

  process.exit(0);

  console.log("after kill task");                                                                                                                                                                                                                                          
});

gulp.task('task3', function() {
  console.log('i am task3!!');
});
  • 出力
$ gulp task
[16:42:45] Using gulpfile ~/gulp-task-kill/gulpfile.js
[16:42:45] Starting 'task1'...
i am task1!!
[16:42:45] Finished 'task1' after 147 μs
[16:42:45] Starting 'task2'...
i am task2!!
[16:42:45] Finished 'task2' after 56 μs
[16:42:45] Starting 'task-kill'...
before kill task

サンプル

https://github.com/tweeeety/gulp-task-kill

おわり

正常終了じゃないときは、exitに1を指定しましょう!\(^o^)/

【gulp】gulp taskをファイルに分割 - require-dir

はじめに

gulpは長い事つかってますが、 フロントの方が入れてくれた環境を基に使っているのでゼロから学んだ経験は乏しいです。 (自分はサーバサイド)

改めてゼロから設定していると、
gulpfile.jsのtaskが肥大化してわかりにくくなるのでファイルを分けたくなる事があります。

そんなときの自分メモ

f:id:tweeeety:20180524215025p:plain

アジェンダ

  1. ファイルに分けるには
  2. requireDirインストール
  3. requireDir使ってみる

1. ファイルに分けるには

requireDirというNode helperを使います。
https://www.npmjs.com/package/require-dir

2. requireDirインストール

# サラからならgulpも
$ npm install --save-dev gulp

# require-dirインストール
$ npm install --save-dev require-dir

3. requireDir使ってみる

構成

例ですが、以下のようなtasksディレクトリ以下に分割したtaskをおきます

$ tree
.
├── gulpfile.js
├── package.json
└── tasks
    ├── task1.js
    ├── task2.js.bk
    └── task3.js
gulpfile.js

gulpfile.jsの中身は以下のように書くだけです。

var dir = require( 'require-dir' );
dir( './tasks', { recurse: true } );

tasksディレクトリ配下に書いたtaskを実行してくれます

実行
$ gulp task1
[15:42:30] Using gulpfile ~/gulp-task-divide/gulpfile.js
[15:42:30] Starting 'task1'...
i am task1!!
[15:42:30] Finished 'task1' after 129 μs

$ gulp task2
[15:42:32] Using gulpfile ~/gulp-task-divide/gulpfile.js
[15:42:32] Starting 'task2'...
i am task2!!
[15:42:32] Finished 'task2' after 135 μs

$ gulp task3
[15:42:34] Using gulpfile ~/gulp-task-divide/gulpfile.js
[15:42:34] Starting 'task3'...
i am task3!!
[15:42:34] Finished 'task3' after 120 μs

サンプル

github.com

おわり

require-dirですっきり\(^o^)/

【git】.gitignoreで反映されないとき - git rm --cached

はじめに

.gitignoreの反映方法をいつも忘れるので自分用メモ
本当に毎回忘れる...

f:id:tweeeety:20180529162907p:plain

git rm --cachedでキャッシュを消す

# .gitignore編集
$ vi .gitignore
---- vi ----
sample.txt
------------

# キャッシュを消す
$ git rm --cached sample.txt

# pushする
$ git add .gitignore
$ git commit -m 'add .gitignore'
$ git push origin master

おわり

これ本当に毎回忘れるーーーーーーー\(^o^)/
覚えておく必要もないけど...

【gulp】サクっと3stepで覚えるgulpとは〜簡単な使い方

はじめに

gulpは長い事つかってますが、
フロントの方が入れてくれた環境を基に使っているのでゼロから学んだ経験は乏しいです。
(自分はサーバサイド)

そこでgulpの基礎をゼロからなるはやで覚えるための自分用メモです

f:id:tweeeety:20180524215025p:plain

アジェンダ

  1. gulpとは
  2. gulp環境つくる
  3. gulp使ってみる

1. gulpとは

公式リポジトリは以下です。
https://github.com/gulpjs/gulp

参考サイトからの抜粋です。

gulpはNode.jsをベースとしたビルドシステムヘルパーです。
gulpの一番の特徴はサイトのトップページで「ストリーミングビルドシステム」と自ら名乗っているように、
ファイルの処理をストリームで行うというところです。
この特徴によって複雑なタスクも細かくカスタマイズして書くことができます。
  現場で使えるgulp入門 第1回 gulpとは何か

2. gulp環境つくる

gulp環境を作るにはシンプルに以下の3つが必要です

  • Node.jsのインストールする
    • nodeコマンドとnpmコマンドを使えるようにする
  • npmでgulpをインストールする
    • gulpコマンド使えるようにする
    • package.json作る
  • タスクを書く
    • gulpfile.js作る

Node.jsのインストールする

公式サイトからダウンロードしてinstallします。
https://nodejs.org/

f:id:tweeeety:20180524215044p:plain

とりあえず動かしてみるにしてもLTSの方を落としてみると良いでしょう。

npmでgulpをインストールする

gulpはglobalとlocalとにインストールします。
また、パッケージ管理のためにpackage.jsonを作成します。

# パッケージディレクトリに移動
$ pwd
/path/to/package dir

# package.jsonを作成
# {} だけ記載
$ vim package.json
---- vi ----
{}
------------

# gulpをグローバルにインストール
$ npm install -g gulp

# gulpをパッケージローカルにインストール
#   このタイミングでpackage.jsonに
#   インストールしたものとversionが書かれる
$ npm install --save-dev gulp

# versionが出れば成功
$ gulp -v
[19:53:54] CLI version 3.9.1
[19:53:54] Local version 3.9.1

$ cat package.json
{
  "devDependencies": {
    "gulp": "^3.9.1"
  }
}

3. gulp使ってみる

gulpタスクの作成

使ってみるといってもまずはgulpタスクを作成する必要があります。
タスクはgulpfile.jsに記載します。

  • gulpfile.js
var gulp = require('gulp');

gulp.task('hello', function() {
  console.log('say Hello!');
});

gulp.task('world', function() {
  console.log('say World!');
});

gulp.task('default', ['hello', 'world']);    

gulpタスクの実行

あとは実行するだけです

# helloタスクを実行してみる
$ gulp hello
[19:58:33] Using gulpfile ~/github/my/for_hatena/gulp-basic-sample/gulpfile.js
[19:58:33] Starting 'hello'...
say Hello!
[19:58:33] Finished 'hello' after 144 μs


# gulpとだけうってdefaultタスクを実行
# default task = hello + worldが呼ばれる
$ gulp
[19:58:48] Using gulpfile ~/github/my/for_hatena/gulp-basic-sample/gulpfile.js
[19:58:48] Starting 'hello'...
say Hello!
[19:58:48] Finished 'hello' after 145 μs
[19:58:48] Starting 'world'...
say World!
[19:58:48] Finished 'world' after 54 μs
[19:58:48] Starting 'default'...
[19:58:48] Finished 'default' after 9.73 μs

いちおうサンプル

作ったサンプルをそのままpushしたので貼っておきます。

おわり

これだけだとまだ何もできないですが、
導入して動かしてみるだけで雰囲気はわかるかと思います\(^o^)/

【git】git mergeでCONFLICTした場合のmerge取り消し - "git merge --abort"

はじめに

gitを使っていればCONFLICTはちょくちょくありますよね。

# 最初は差分がないことを確認
$ git status
On branch [ブランチ1]
nothing to commit, working directory clean

# とあるブランチをmerge
# するとCONFLICT...
$ git merge [ブランチ2]
Auto-merging package.json
CONFLICT (content): Merge conflict in package.json
Automatic merge failed; fix conflicts and then commit the result.

そんな時に通常はCONFLICTを解消しますが、
そうではなく一回なかったことにしたいこともあるわけです。
あるんですよ...

そんな場合の対処法

そこで"git merge --abort"

git merge --abortを使うとマージする前の状態に戻ります。

いちおうCONFLICTしてから取り消す一連を参考程度に。

# 最初は差分がないことを確認
$ git status
On branch [ブランチ1]
nothing to commit, working directory clean

# とあるブランチをmerge
$ git merge [ブランチ2]
Auto-merging package.json
CONFLICT (content): Merge conflict in package.json
Automatic merge failed; fix conflicts and then commit the result.

# statusを見るとCONFLICTしている
$ git status
On branch [ブランチ1]
You have unmerged paths.
  (fix conflicts and run "git commit")

Changes to be committed:

  modified:   README.md

Unmerged paths:
  (use "git add <file>..." to mark resolution)

  both modified:   package.json

# CONFLICTじゃなければ戻せるcheckoutを試しに
# 当然断られる
$ git checkout .
error: path 'package.json' is unmerged

# ここで登場
$ git merge --abort

# 無事になかったことに
$ git status
On branch [ブランチ1]
nothing to commit, working directory clean

おわり

mergeやめたい!って場合がたまーにあるたびに調べてたので自分用備忘録でした\(^o^)/

【Node.js】Node.jsのLTSやCURRENTってなんだ?

はじめに

Node.jsを改めてインストールするときに
LTSとCURRENTがありますが、それぞれなんだっけ?を忘れるので自分用メモです。

公式サイトより

https://github.com/nodejs/Release からの抜粋です

Mandate
 
The Release working group's purpose is:
 
* Management/execution of the release and support process for all releases.
 
Its responsibilities are:
 
* Define the release process.
* Define the content of releases.
* Generate and create releases.
* Test Releases
* Manage the LTS and Current branches including backporting changes to these branches.
* Define the policy for what gets backported to release streams.
 
The Release working group is structured into teams and membership in the working group does not automatically result in membership in these teams. These teams are:
 
* Releasers team
* LTS team
* CITGM team
 
The releasers team is entrusted with the secrets and CI access to be able build and sign releases. Additions to the releasers team must be approved by the TSC following the process outlined in GOVERNANCE.md.
 
The Long Term Support (LTS) team manages the process/content of LTS releases and the required backporting for these releases. Additions to the LTS team needs sign off from the rest of the LTS team.
 
The Canary in the Gold Mine (CITGM) team maintains CITGM as one of the key sanity checks for releases. This team maintains the CITGM repository and works to keep CITGM builds running and passing regularly. This also includes maintaining the CI jobs in collaboration with the Build Working Group.

関係ありそうなところだけ抜粋すると

  • リリースワーキンググループがある
  • リリースにおける管理と実行を行う
  • グループは3つのチーム構成で構成されている
    • Releasers team
    • LTS team
    • CITGM team

これを踏まえて

LTSとCURRENTってなに?

LTSとは

LTSは、Long-term Supportの略で、長期の保守運用が約束されたバージョンです

CURRENTとは

CURRENTは、最新版だけど安定性を約束しないことで機能追加を盛り込んだバージョンです

参考

おわり

ある程度安定したサービスを作る目的ならLTS、
いろいろ試してみたいときはCURRENTですかね\(^o^)/

【GAE】appengine(app-engine-go)をhomebrew経由でinstallするgo1.6.3 (appengine-1.9.48)から、cloud sdk経由でinstallするgo version 1.8.5 (appengine-1.9.68) にupdateするメモ

はじめに

GAE goな環境を使っています。

結構長いことgo1.6.3 (appengine-1.9.48)で困った事はなかったのですが、
goのversionの関係でtestingパッケージのt.Run()が使えなかったりとあったのでupdateしました。

以前は、homebrew経由でinstallおよびアップデートができたのですが、
いまはサポートされておらずcloud sdk経由に変わったとの事です。

その時の自分メモ

f:id:tweeeety:20180503231719p:plain

アジェンダ

  1. 環境確認
  2. google-cloud-sdkをUPDATE
  3. Components(app-engine-go)のインストール

1. 環境確認

あげる前に自分の環境をもろもろ確認しておきます。

gcloud周りの確認
gcloud コマンドまわりを確認
# 場所を確認
# gcloudはhomeに落としたままpathを通していた
# 
# 新しく入れる方は/usr/local/Caskroom配下において/usr/local/bin/gcloudにsymlink予定
/Users/tweeeety/google-cloud-sdk/bin/gcloud

$ ls -la /Users/tweeeety/google-cloud-sdk/bin/gcloud
-rwxr-xr-x  1 tweeeety  tweeeety Users  3089 10 10  2017 /Users/tweeeety/google-cloud-sdk/bin/gcloud

# pathを確認
$ vim ~/.bash_profile
-- vim確認 --
# The next line updates PATH for the Google Cloud SDK.
if [ -f '/Users/tweeeety/google-cloud-sdk/path.bash.inc' ]; then source '/Users/tweeeety/google-cloud-sdk/path.bash.inc'; fi

# The next line enables shell command completion for gcloud.
if [ -f '/Users/tweeeety/google-cloud-sdk/completion.bash.inc' ]; then source '/Users/tweeeety/google-cloud-sdk/completion.bash.inc'; fi
------------

# gcloudのversionを確認
$ gcloud version
Google Cloud SDK 175.0.0
app-engine-python 1.9.61
beta 2017.09.15
bq 2.0.27
core 2017.10.09
gcloud 
gsutil 4.27
Updates are available for some Cloud SDK components.  To install them,
please run:
  $ gcloud components update

Updates are available for some Cloud SDK components.  To install them,
please run:
  $ gcloud components update

# gcoud 情報を確認
$ gcloud info
Google Cloud SDK [175.0.0]

Platform: [Mac OS X, x86_64] ('Darwin', 'tweeeety-MAC', '13.4.0', 'Darwin Kernel Version 13.4.0: Mon Jan 11 18:17:34 PST 2016; root:xnu-2422.115.15~1/RELEASE_X86_64', 'x86_64', 'i386')
Python Version: [2.7.14 (default, Feb  4 2018, 00:19:50)  [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)]]
Python Location: [/usr/local/Cellar/python/2.7.14_2/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python]
Site Packages: [Disabled]

Installation Root: [/Users/tweeeety/google-cloud-sdk]
Installed Components:
  core: [2017.10.09]
  app-engine-python: [1.9.61]
  gcloud: []
  beta: [2017.09.15]
  gsutil: [4.27]
  bq: [2.0.27]
System PATH: [/usr/local/opt/imagemagick@6/bin:/Users/tweeeety/google-cloud-sdk/bin:/Users/tweeeety/.plenv/shims:/Users/tweeeety/.plenv/bin:/Users/tweeeety/.nodebrew/current/bin:/Users/tweeeety/.mysqlenv/mysqls/5.1.69/bin:/Users/tweeeety/.mysqlenv/bin:/Users/tweeeety/.mysqlenv/shims:/Users/tweeeety/.mysqlenv/mysql-build/bin:/usr/local/sbin:/Users/tweeeety/.mysqlenv/bin:/Users/tweeeety/.mysqlenv/shims:/Users/tweeeety/.mysqlenv/mysql-build/bin:/usr/local/heroku/bin:/Users/tweeeety/.chefdk/gem/ruby/2.1.0/bin:/opt/chefdk/bin:/Users/tweeeety/.rbenv/shims:/Users/tweeeety/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/go/bin:/sbin:/usr/sbin:/Users/tweeeety/local/bin:/usr/local/opt/go/libexec/bin:/Users/tweeeety/.go/bin]
Python PATH: [/Users/tweeeety/google-cloud-sdk/lib/third_party:/Users/tweeeety/google-cloud-sdk/lib:/usr/local/Cellar/python/2.7.14_2/Frameworks/Python.framework/Versions/2.7/lib/python27.zip:/usr/local/Cellar/python/2.7.14_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7:/usr/local/Cellar/python/2.7.14_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin:/usr/local/Cellar/python/2.7.14_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac:/usr/local/Cellar/python/2.7.14_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages:/usr/local/Cellar/python/2.7.14_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk:/usr/local/Cellar/python/2.7.14_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old:/usr/local/Cellar/python/2.7.14_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload]
Cloud SDK on PATH: [True]
Kubectl on PATH: [False]

WARNING: There are old versions of the Google Cloud Platform tools on your system PATH.
  /usr/local/Cellar/app-engine-go-64/1.9.48/share/app-engine-go-64/dev_appserver.py
  /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin/bq
  /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin/gcloud
  /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin/gsutil

Installation Properties: [/Users/tweeeety/google-cloud-sdk/properties]
User Config Directory: [/Users/tweeeety/.config/gcloud]
Active Configuration Name: [sample]
Active Configuration Path: [/Users/tweeeety/.config/gcloud/configurations/config_sample]

Account: [tweeeety@hoge.jp]
Project: [hoge-fuga-gcp]

Current Properties:
  [core]
    project: [hoge-fuga-gcp]
    account: [tweeeety@hoge.jp]
    disable_usage_reporting: [False]
  [compute]
    region: [asia-east1]
    zone: [asia-east1-b]

Logs Directory: [/Users/tweeeety/.config/gcloud/logs]
Last Log File: [/Users/tweeeety/.config/gcloud/logs/2018.04.24/19.25.04.354908.log]

git: [git version 1.9.3 (Apple Git-50)]
ssh: [OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011]
gcloud以外のcommponentsを確認

ついで程度ですが、componensまわりを確認してみます

$ which gsutil
/Users/tweeeety/google-cloud-sdk/bin/gsutil

$ goapp version
go version go1.6.3 (appengine-1.9.48) darwin/amd64

# goappはhomebrewで入れた?か忘れたがCellarに入っていた
# 新しく入れる方は/usr/local/Caskroom配下になる予定
$ which goapp
/usr/local/bin/goapp

$ ls -al /usr/local/bin/goapp
lrwxr-xr-x  1 tweeeety  admin  43  1 11  2017 /usr/local/bin/goapp -> ../Cellar/app-engine-go-64/1.9.48/bin/goapp

2. google-cloud-sdkをUPDATE

まず、以前にgoogle-cloud-sdkbrew caskにて入れていたようなのでその辺の確認から行います。

gcloudの再インストール

# versionを確認
$ brew cask --version
Homebrew-Cask 1.6.1
caskroom/homebrew-cask (git revision 385494; last commit 2018-04-23)

# caskで入れたlistを確認
$ brew cask list
google-cloud-sdk
vagrant

# そのままinstallしてみるが
# re-installしてねと言われる...まぁそうだね
$ brew cask install google-cloud-sdk
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 3 taps (caskroom/cask, homebrew/core, phinze/cask).
==> Updated Formulae
ruby-build ✔     bettercap        cayley           dcd              emscripten       folly            heroku           ice              juju             knot-resolver    meson            r                silk             telegraf         watson
vim ✔            bluepill         cockroach        dscanner         fobis            gollum           hugo             jruby            jvgrep           libsass          pqiv             rocksdb          skaffold         tokei            xonsh

Warning: Cask 'google-cloud-sdk' is already installed.

To re-install google-cloud-sdk, run:

# すなおにreinstall
$ brew cask reinstall google-cloud-sdk
==> Caveats
google-cloud-sdk is installed at /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk. Add your profile:

  for bash users
    source '/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.bash.inc'
    source '/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.bash.inc'

  for zsh users
    source '/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.zsh.inc'
    source '/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.zsh.inc'

~ 省略 ~ 

==> Your current Cloud SDK version is: 198.0.0
==> Installing components from version: 198.0.0
==> 
==> +----------------------------------------------------------------------------+
==> |                    These components will be installed.                     |
==> +-----------------------------------------------------+------------+---------+
==> |                         Name                        |  Version   |   Size  |
==> +-----------------------------------------------------+------------+---------+
==> | BigQuery Command Line Tool                          |     2.0.32 | < 1 MiB |
==> | BigQuery Command Line Tool (Platform Specific)      |     2.0.26 | < 1 MiB |
==> | Cloud SDK Core Libraries (Platform Specific)        | 2018.03.16 | < 1 MiB |
==> | Cloud Storage Command Line Tool                     |       4.30 | 3.4 MiB |
==> | Cloud Storage Command Line Tool (Platform Specific) |       4.27 | < 1 MiB |
==> | Default set of gcloud commands                      |            |         |
==> | gcloud cli dependencies                             | 2017.10.20 | 1.4 MiB |
==> +-----------------------------------------------------+------------+---------+

~ 省略 ~ 

==> For the latest full release notes, please visit:
==>   https://cloud.google.com/sdk/release_notes
🍺  google-cloud-sdk was successfully installed!

最後にビールの絵とともにgoogle-cloud-sdk was successfully installed!と言われます

gcloudコマンドの初期化(ログイン)

公式を参考に行いました
* Cloud SDK の初期化

公式には以下のように記載されています

通常、Cloud SDK をインストールした後、gcloud init コマンドを実行して初期設定を行います。
後で gcloud init を実行して設定を変更したり、新しい設定を作成したりすることもできます。
 

  • Cloud SDK ツールを承認して、現在のユーザー アカウントの認証情報を使用して Google Cloud Platform にアクセスできるようにします。すでにアクセスが承認されている場合はアカウントを選択できます。
  • Cloud SDK 構成をセットアップし、一連の基本プロパティを設定します。たとえば、上記のステップで設定した有効なアカウント、現在のプロジェクト、Google Compute Engine のデフォルトのリージョンとゾーン(該当する場合)などです。
gcloud init

初回の場合は、gcloud initを打ってセットアップします。
自分は既にセットアップ済みの内容を変えたくなかったのでloginのみにしました。

# そのまま打つだけ
$ gcloud init

# この後いろいろ聞かれるので設定に合わせて答える
gcloud auth login

セットアプップ構成を変えたくなかったので、
ユーザー アカウントを使用して承認だけをおこないました

# ブラウザが起動して認証を行う
$ gcloud auth login

3. Components(app-engine-go)のインストール

goappコマンドが使いたいので
app-engine-goというComponentsをインストールします。

以前にbrewで入れたものとバッティングしてうまくいかなかった編

Componentsのインストール状況を確認

念のためインストール状況を確認します

$ gcloud components list

Your current Cloud SDK version is: 175.0.0
The latest available version is: 198.0.0

┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                                   Components                                                   │
├──────────────────┬──────────────────────────────────────────────────────┬──────────────────────────┬───────────┤
│      Status      │                         Name                         │            ID            │    Size   │
├──────────────────┼──────────────────────────────────────────────────────┼──────────────────────────┼───────────┤
│ Update Available │ BigQuery Command Line Tool                           │ bq                       │   < 1 MiB │
│ Update Available │ Cloud SDK Core Libraries                             │ core                     │   7.6 MiB │
│ Update Available │ Cloud Storage Command Line Tool                      │ gsutil                   │   3.4 MiB │
│ Update Available │ gcloud app Python Extensions                         │ app-engine-python        │   6.1 MiB │
│ Not Installed    │ App Engine Go Extensions                             │ app-engine-go            │ 151.3 MiB │
│ Not Installed    │ Cloud Bigtable Command Line Tool                     │ cbt                      │   4.7 MiB │
│ Not Installed    │ Cloud Bigtable Emulator                              │ bigtable                 │   3.8 MiB │
│ Not Installed    │ Cloud Datalab Command Line Tool                      │ datalab                  │   < 1 MiB │
│ Not Installed    │ Cloud Datastore Emulator                             │ cloud-datastore-emulator │  17.9 MiB │
│ Not Installed    │ Cloud Datastore Emulator (Legacy)                    │ gcd-emulator             │  38.1 MiB │
│ Not Installed    │ Cloud Pub/Sub Emulator                               │ pubsub-emulator          │  33.4 MiB │
│ Not Installed    │ Emulator Reverse Proxy                               │ emulator-reverse-proxy   │  14.5 MiB │
│ Not Installed    │ Google Container Local Builder                       │ container-builder-local  │   4.3 MiB │
│ Not Installed    │ Google Container Registry's Docker credential helper │ docker-credential-gcr    │   2.5 MiB │
│ Not Installed    │ gcloud Alpha Commands                                │ alpha                    │   < 1 MiB │
│ Not Installed    │ gcloud app Java Extensions                           │ app-engine-java          │ 118.9 MiB │
│ Not Installed    │ gcloud app PHP Extensions                            │ app-engine-php           │  21.9 MiB │
│ Not Installed    │ gcloud app Python Extensions (Extra Libraries)       │ app-engine-python-extras │  28.5 MiB │
│ Not Installed    │ kubectl                                              │ kubectl                  │  12.2 MiB │
│ Installed        │ gcloud Beta Commands                                 │ beta                     │   < 1 MiB │
└──────────────────┴──────────────────────────────────────────────────────┴──────────────────────────┴───────────┘
To install or remove components at your current SDK version [175.0.0], run:
  $ gcloud components install COMPONENT_ID
  $ gcloud components remove COMPONENT_ID

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

Update Available のものをUpdateしろよなと言われています。

Componentsのupdates

素直にupdateも行います

$ gcloud components update

Your current Cloud SDK version is: 175.0.0
You will be upgraded to version: 198.0.0

┌─────────────────────────────────────────────────────────────────────┐
│                  These components will be updated.                  │
├──────────────────────────────────────────────┬────────────┬─────────┤
│                     Name                     │  Version   │   Size  │
├──────────────────────────────────────────────┼────────────┼─────────┤
│ BigQuery Command Line Tool                   │     2.0.32 │ < 1 MiB │
│ Cloud SDK Core Libraries                     │ 2018.04.13 │ 7.6 MiB │
│ Cloud SDK Core Libraries (Platform Specific) │ 2018.03.16 │ < 1 MiB │
│ Cloud Storage Command Line Tool              │       4.30 │ 3.4 MiB │
│ gcloud app Python Extensions                 │     1.9.69 │ 6.1 MiB │
│ gcloud cli dependencies                      │ 2018.04.06 │ 1.6 MiB │
│ gcloud cli dependencies                      │ 2017.10.20 │ 1.4 MiB │
└──────────────────────────────────────────────┴────────────┴─────────┘
┌─────────────────────────────────────────────────────────────────────────────┐
│                     These components will be installed.                     │
├─────────────────────────────────┬─────────────────────┬─────────────────────┤
│               Name              │       Version       │         Size        │
├─────────────────────────────────┼─────────────────────┼─────────────────────┤
│ gRPC python library             │               1.9.1 │             7.6 MiB │
│ gRPC python library             │                     │                     │
└─────────────────────────────────┴─────────────────────┴─────────────────────┘

A lot has changed since your last upgrade.  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                             ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Uninstalling: BigQuery Command Line Tool                 ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Uninstalling: Cloud SDK Core Libraries                   ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Uninstalling: Cloud SDK Core Libraries (Platform Spec... ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Uninstalling: Cloud Storage Command Line Tool            ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Uninstalling: gcloud app Python Extensions               ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Uninstalling: gcloud cli dependencies                    ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Uninstalling: gcloud cli dependencies                    ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Installing: BigQuery Command Line Tool                   ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Installing: Cloud SDK Core Libraries                     ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Installing: Cloud SDK Core Libraries (Platform Specific) ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Installing: Cloud Storage Command Line Tool              ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Installing: gRPC python library                          ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Installing: gRPC python library                          ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Installing: gcloud app Python Extensions                 ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Installing: gcloud cli dependencies                      ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Installing: gcloud cli dependencies                      ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Creating backup and activating new installation          ═╣
╚════════════════════════════════════════════════════════════╝

Performing post processing steps...done.                                                                                                                                                                                                                       

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


Update done!

To revert your SDK to the previously installed version, you may run:
  $ gcloud components update --version 175.0.0

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:

/usr/local/Cellar/app-engine-go-64/1.9.48/share/app-engine-go-64/dev_appserver.py
/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin/bq
/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin/gcloud
/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin/gsutil

と、warningが...
以前、別の方法で入れたヤツがいるぞ と教えてくれてます....

Componentsのupdates後の確認

念のためgcloud components list で確認すると
StatusはInstalledに変わっているのでupdateはされたようです。

$ gcloud components list

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

┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                                  Components                                                 │
├───────────────┬──────────────────────────────────────────────────────┬──────────────────────────┬───────────┤
│     Status    │                         Name                         │            ID            │    Size   │
├───────────────┼──────────────────────────────────────────────────────┼──────────────────────────┼───────────┤
│ Not Installed │ App Engine Go Extensions                             │ app-engine-go            │ 151.3 MiB │
│ Not Installed │ Cloud Bigtable Command Line Tool                     │ cbt                      │   4.7 MiB │
│ Not Installed │ Cloud Bigtable Emulator                              │ bigtable                 │   3.8 MiB │
│ Not Installed │ Cloud Datalab Command Line Tool                      │ datalab                  │   < 1 MiB │
│ Not Installed │ Cloud Datastore Emulator                             │ cloud-datastore-emulator │  17.9 MiB │
│ Not Installed │ Cloud Datastore Emulator (Legacy)                    │ gcd-emulator             │  38.1 MiB │
│ Not Installed │ Cloud Pub/Sub Emulator                               │ pubsub-emulator          │  33.4 MiB │
│ Not Installed │ Emulator Reverse Proxy                               │ emulator-reverse-proxy   │  14.5 MiB │
│ Not Installed │ Google Container Local Builder                       │ container-builder-local  │   4.3 MiB │
│ Not Installed │ Google Container Registry's Docker credential helper │ docker-credential-gcr    │   2.5 MiB │
│ Not Installed │ gcloud Alpha Commands                                │ alpha                    │   < 1 MiB │
│ Not Installed │ gcloud app Java Extensions                           │ app-engine-java          │ 118.9 MiB │
│ Not Installed │ gcloud app PHP Extensions                            │ app-engine-php           │  21.9 MiB │
│ Not Installed │ gcloud app Python Extensions (Extra Libraries)       │ app-engine-python-extras │  28.5 MiB │
│ Not Installed │ kubectl                                              │ kubectl                  │  12.2 MiB │
│ Installed     │ BigQuery Command Line Tool                           │ bq                       │   < 1 MiB │
│ Installed     │ Cloud SDK Core Libraries                             │ core                     │   7.6 MiB │
│ Installed     │ Cloud Storage Command Line Tool                      │ gsutil                   │   3.4 MiB │
│ Installed     │ gcloud Beta Commands                                 │ beta                     │   < 1 MiB │
│ Installed     │ gcloud app Python Extensions                         │ app-engine-python        │   6.1 MiB │
└───────────────┴──────────────────────────────────────────────────────┴──────────────────────────┴───────────┘
To install or remove components at your current SDK version [198.0.0], run:
  $ gcloud components install COMPONENT_ID
  $ gcloud components remove COMPONENT_ID

To update your SDK installation to the latest version [198.0.0], run:
  $ gcloud components update
app-engine-goを入れたい
app-engine-goが以前のものとバッティング
# 念のため確認
# brewで入れたやつがいるけど...
$ goapp version
go version go1.6.3 (appengine-1.9.48) darwin/amd64

# gcloudコマンドでインストール
$ gcloud components install app-engine-go


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

┌────────────────────────────────────────────────┐
│      These components will be installed.       │
├──────────────────────────┬─────────┬───────────┤
│           Name           │ Version │    Size   │
├──────────────────────────┼─────────┼───────────┤
│ App Engine Go Extensions │         │           │
│ App Engine Go Extensions │  1.9.64 │ 151.3 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: App Engine Go Extensions                     ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Installing: App Engine Go 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:

/usr/local/Cellar/app-engine-go-64/1.9.48/share/app-engine-go-64/dev_appserver.py
/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin/bq
/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin/gcloud
/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin/gsutil

# ↑この変にolderなやつがいるぞと教えてくれる
# さらにはremoveしろと...

# 当然goappも以前のまま
$ goapp version
go version go1.6.3 (appengine-1.9.48) darwin/amd64
brewで入れた方を消す

最初から消せば良かったのですが、ここでようやく消します。

# brewで入れか確認
$ brew list | grep app-engine
app-engine-go-64

# appengine系のコマンドも、きっとbrew経由のままだろうな、を確認
$ ls -al /usr/local/bin/appcfg.py
lrwxr-xr-x  1 tweeeety  admin  47  1 11  2017 /usr/local/bin/appcfg.py -> ../Cellar/app-engine-go-64/1.9.48/bin/appcfg.py

# 一応unlinkだけしてみる
$ brew unlink app-engine-go-64
Unlinking /usr/local/Cellar/app-engine-go-64/1.9.48... 7 symlinks removed

# リンクは外れた
$ goapp version
-bash: /usr/local/bin/goapp: No such file or directory

# 思い切ってremove
$ brew remove app-engine-go-64
Uninstalling /usr/local/Cellar/app-engine-go-64/1.9.48... (9,842 files, 247.8MB)
app-engine-go-64 1.9.38 1 is still installed.
Remove all versions with `brew uninstall --force app-engine-go-64`.

# ↑でRemove allしてよね、と言われてるが再度確認
# やっぱりまだいる
$ brew list | grep app-engine-
app-engine-go-64

# 再度消す
$ brew remove app-engine-go-64
Uninstalling /usr/local/Cellar/app-engine-go-64/1.9.38... (6,634 files, 225.0MB)

# gcloudコマンドもhomeに置いたままなので、この辺も消す
$ which gcloud
/Users/tweeeety/google-cloud-sdk/bin/gcloud

# 消す(いったん移動...)
$ mv ~/google-cloud-sdk .google-cloud-sdk

# 再度確認すると、Caskroomの方に切り替わってくれた模様
$ which gcloud 
/usr/local/bin/gcloud

$ ls -al /usr/local/bin/gcloud
lrwxr-xr-x  1 tweeeety  admin  71  4 24 22:10 /usr/local/bin/gcloud -> /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin/gcloud

# 以前入れた方のpathをコメントアウト
$ vim ~/.bash_profile
-- vi編集 --
# The next line updates PATH for the Google Cloud SDK.
#if [ -f '/Users/tweeeety/google-cloud-sdk/path.bash.inc' ]; then source '/Users/tweeeety/google-cloud-sdk/path.bash.inc'; fi

# The next line enables shell command completion for gcloud.
#if [ -f '/Users/tweeeety/google-cloud-sdk/completion.bash.inc' ]; then source '/Users/tweeeety/google-cloud-sdk/completion.bash.inc'; fi
------------

再度、app-engine-goをインストールでうまくいった編

$ gcloud components install app-engine-go


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

┌────────────────────────────────────────────────────┐
│        These components will be installed.         │
├──────────────────────────────┬─────────┬───────────┤
│             Name             │ Version │    Size   │
├──────────────────────────────┼─────────┼───────────┤
│ App Engine Go Extensions     │         │           │
│ App Engine Go Extensions     │  1.9.64 │ 151.3 MiB │
│ gRPC python library          │   1.9.1 │   7.6 MiB │
│ gRPC python library          │         │           │
│ gcloud app Python Extensions │  1.9.69 │   6.1 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: App Engine Go Extensions                     ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Installing: App Engine Go Extensions                     ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Installing: gRPC python library                          ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Installing: gRPC python library                          ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Installing: gcloud app Python Extensions                 ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Creating backup and activating new installation          ═╣
╚════════════════════════════════════════════════════════════╝

Performing post processing steps...done.                                                                                                                                                                                                                       

Update done!

# パスを通して反映
vim ~/.bash_profile
-- vim追記 --
export PATH=$PATH:/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/google_appengine
-------------

$ source ~/.bash_profile

# そのままだと実行権限がついてないので実行権限をつける
$ chmod +x /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/google_appengine/goapp

# 無事、versionが上がりました!
$ goapp version
go version 1.8.5 (appengine-1.9.68) darwin/amd64

さらに

実行権限をつけましたが、以下も必要に応じてつけると良いです

$ chmod +x /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/google_appengine/goapp
$ chmod +x /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/google_appengine/appcfg.py
$ chmod +x /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/google_appengine/dev_appserver.py
$ chmod +x /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/google_appengine/backends_conversion.py
$ chmod +x /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/google_appengine/bulkload_client.py
$ chmod +x /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/google_appengine/bulkloader.py
$ chmod +x /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/google_appengine/download_appstats.py
$ chmod +x /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/google_appengine/endpointscfg.py

補足

以下もご参考ください

おわり

cloud sdk便利!enjoy!\(^o^)/