カタログジェネレータを試してみた

f:id:yassan0627:20171202155827p:plain Rancher Advent Calendar 2017 の 12日目の記事です。

20日目に「 redashのプライベートカタログ化」を紹介するのですが、あれこれ欲張りすぎて記事が長くなったのと、まだ、カレンダーが埋まってないので埋めてみました。

Racnher JPコミュニティのコアスタップとして活動している @yassan168 です。 毎月な頻度でイベントをやってますので、興味のある方は Rancher JP まで~。

では、改めて。本題。

Rancherでは、Yeoman と言うジェネレータを利用して、空のカタログを作成することが出来ます。
どんなものかは、 generator-rancher-catalog を見ると分かります。
ジェネレータを使う事でファイル名やディレクトリ構成を自動生成するので、うっかりを防止(template「s」とか)出来るので利用すると不幸を回避できます。

cf. CATALOG GENERATOR BASED ON YEOMAN

プライベートカタログジェネレータのセットアップ

Yeomanに必要なものを用意します。
これは、カタログを作成する作業用端末に用意します(ホストには不要です)。

npmのVer.管理ツール nvm のインストール

$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
 :
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

=> Compressing and cleaning up git repository

=> Appending nvm source string to /home/yassan/.bashrc
=> Appending bash_completion source string to /home/yassan/.bashrc
=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

npmのインストール

インストール可能な安定Ver.を探す

$ nvm ls-remote 
 :
         v8.9.1   (LTS: Carbon)
         v8.9.2   (LTS: Carbon)
         v8.9.3   (Latest LTS: Carbon)   # ← これに決定
         v9.0.0
         v9.1.0
  :

安定Ver.のnpmをインストール

$ nvm install 8.9.3
Downloading and installing node v8.9.3...
Downloading https://nodejs.org/dist/v8.9.3/node-v8.9.3-linux-x64.tar.xz...
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v8.9.3 (npm v5.5.1)
Creating default alias: default -> 8.9.3 (-> v8.9.3)

Yeomanのインストール

npmを使ってYeomanをインストール

$ npm install -g yo
/home/yassan/.nvm/versions/node/v8.9.3/bin/yo -> /home/yassan/.nvm/versions/node/v8.9.3/lib/node_modules/yo/lib/cli.js
/home/yassan/.nvm/versions/node/v8.9.3/bin/yo-complete -> /home/yassan/.nvm/versions/node/v8.9.3/lib/node_modules/yo/lib/completion/index.js

> spawn-sync@1.0.15 postinstall /home/yassan/.nvm/versions/node/v8.9.3/lib/node_modules/yo/node_modules/spawn-sync
> node postinstall


> yo@2.0.0 postinstall /home/yassan/.nvm/versions/node/v8.9.3/lib/node_modules/yo
> yodoctor
 
 :
 :

Yeoman Doctor
Running sanity checks on your system

✔ Global configuration file is valid
✔ NODE_PATH matches the npm root
✔ Node.js version
✔ No .bowerrc file in home directory
✔ No .yo-rc.json file in home directory
✔ npm version

Everything looks all right!
+ yo@2.0.0
added 385 packages in 27.778s

Rancherカタログジェネレータ generator-rancher-catalog をインストール

$ npm install -g generator-rancher-catalog

> spawn-sync@1.0.15 postinstall /home/yassan/.nvm/versions/node/v8.9.3/lib/node_modules/generator-rancher-catalog/node_modules/spawn-sync
> node postinstall

+ generator-rancher-catalog@1.1.2
added 328 packages in 18.166s

空のカタログを生成

プライベートカタログを作成するディレクトリを作成して移動

$ mkdir mycatalog
$ cd mycatalog

ジェネレータ起動して、空のredashカタログを追加する。

$ yo rancher-catalog

     _-----_     ╭──────────────────────────╮
    |       |    │    Welcome to the good   │
    |--(o)--|    │ generator-rancher-catalo │
   `---------´   │       g generator!       │
    ( _´U`_ )    ╰──────────────────────────╯
    /___A___\   /
     |  ~  |     
   __'.___.'__   
 ´   `  |° ´ Y ` 

? What is the name of the catalog entry? redash
? What are the cluster management types? Cattle
Initialized empty Git repository in /home/yassan/dev/rancher/mycatalog/.git/
   create templates/redash/0/docker-compose.yml
   create templates/redash/0/rancher-compose.yml
   create templates/redash/config.yml
   create templates/redash/README.md
   create templates/redash/catalogIcon-redash.svg

ジェネレータ起動時に下記の通り、 Cattleだけでなく、それ以外にも対応しているので色々使い勝手が良さそうです。

? What is the name of the catalog entry? hoge
? What are the cluster management types? (Press <space> to select, <a> to toggle all, <i> to inverse selection)
❯◉ Cattle
 ◯ Swarm
 ◯ Kubernetes
 ◯ Mesos

新しいカタログを追加したい場合、カタログのルートで再度コマンド実効すれば良いです。
試しに空のsupersetのカタログを追加してみます。

$ cd (mycatalogのルート)
$ yo rancher-catalog
? 'Allo yassan! What would you like to do? Rancher Catalog

Make sure you are in the directory you want to scaffold into.
This generator can also be run with: yo rancher-catalog


     _-----_     ╭──────────────────────────╮
    |       |    │    Welcome to the good   │
    |--(o)--|    │ generator-rancher-catalo │
   `---------´   │       g generator!       │
    ( _´U`_ )    ╰──────────────────────────╯
    /___A___\   /
     |  ~  |     
   __'.___.'__   
 ´   `  |° ´ Y ` 

? What is the name of the catalog entry? superset
? What are the cluster management types? Cattle
Reinitialized existing Git repository in /home/yassan/dev/rancher/mycatalog/.git/
   create templates/superset/0/docker-compose.yml
   create templates/superset/0/rancher-compose.yml
   create templates/superset/config.yml
   create templates/superset/README.md
   create templates/superset/catalogIcon-superset.svg

     _-----_     ╭───────────────────────╮
    |       |    │      Bye from us!     │
    |--(o)--|    │       Chat soon.      │
   `---------´   │      Yeoman team      │
    ( _´U`_ )    │    http://yeoman.io   │
    /___A___\   /╰───────────────────────╯
     |  ~  |     
   __'.___.'__   
 ´   `  |° ´ Y ` 

そうすると以下の様なディレクトリツリーになっています。

$ tree .
.
└── templates
    ├── redash
    │   ├── 0
    │   │   ├── docker-compose.yml
    │   │   └── rancher-compose.yml
    │   ├── README.md
    │   ├── catalogIcon-redash.svg
    │   └── config.yml
    └── superset
        ├── 0
        │   ├── docker-compose.yml
        │   └── rancher-compose.yml
        ├── README.md
        ├── catalogIcon-superset.svg
        └── config.yml

5 directories, 10 files

以上、「カタログジェネレータを試してみた」でした。