Bluemix 试用
账号
官网注册一下bluemix的账号, 如果之前注册过IBM的账号的话, 可以直接拿来登录并激活该功能.
(有部分Script似乎在墙外, 最好翻一下操作).
创建空间
首次登入, 会被告知试用天数, 和简单的收费介绍, 大概就是超出免费使用额的时候进行收费.
然后呢, 会有一个指引, 来创建"组织名称">"空间名称". 这里也会选择服务器物理位置. 自动给我匹配了一个“悉尼”, 看似最近的也只有这个了.
创建服务
选一个服务吧. 各类应用容器...(这样算, 一个服务一份钱?).
因为要部署的是Hubot, 一个NodeJS做的程序, 所以这里就直接选个CloudFoundry的Node.js应用类型就行啦.
同样, 创建好名称, 比如我这里就叫“nodejshubot”.
创建完后, 系统会自动为你启动该服务.
准备工具
bluemix环境已有, 接下来就是获取hubot并部署到该服务中.
那这个环境是一个CloudFoundry环境, 就需要它的交互工具.
在macOS中, 还是老一套, 用Homebrew来安装吧:
brew install cloudfoundry/tap/cf-cli
使用cf
命令测试了一下,
$ cf
cf version 6.30.0+decf883fc.2017-09-01, Cloud Foundry command line tool
Usage: cf [global options] command [arguments...] [command options]
挺正常的.
然后还需要git和node环境, 如果你还没有的话.
下载安装过Xcode的, 都会由Command Line Tools附带安装了git.
node环境, 也是可以直接brew install
的.
获取Hubot
$ git clone git@github.com:hubotio/hubot.git
Cloning into 'hubot'...
remote: Counting objects: 8746, done.
remote: Total 8746 (delta 0), reused 0 (delta 0), pack-reused 8746
Receiving objects: 100% (8746/8746), 1.91 MiB | 117.00 KiB/s, done.
Resolving deltas: 100% (4926/4926), done.
官方解释到:
如果要部署到 Bluemix,设置 manifest.yml 文件会很有用。manifest.yml 包含有关应用程序的基本信息,例如名称、要为每个实例分配的内存量以及路径。
那我们就在这个项目里创建一个manifest.yml文件, name呢就是我们的应用程序名称.
---
applications:
- name: nodejshubot
command: ./bin/hubot --adapter slack
instances: 1
memory: 256M
部署应用程序
到了用Cloud Foundry CLI的地方啦.
cf api <API-endpoint>
API-endpoint呢 则是前面选好的区域, 比如我选的悉尼.
API 端点 |
区域 |
https://api.ng.bluemix.net |
美国南部 |
https://api.eu-gb.bluemix.net |
英国 |
https://api.au-syd.bluemix.net |
悉尼 |
实际使用:
$ cf api https://api.au-syd.bluemix.net
Setting api endpoint to https://api.au-syd.bluemix.net...
OK
api endpoint: https://api.au-syd.bluemix.net
api version: 2.75.0
Not logged in. Use 'cf login' to log in.
那么就是OK的了, 都提示好让我直接login:
$ cf login
API endpoint: https://api.au-syd.bluemix.net
Email> blodely@gmail.com
Password>
Authenticating...
OK
Targeted org blodelyAtSyd
Targeted space dev
API endpoint: https://api.au-syd.bluemix.net (API version: 2.75.0)
User: blodely@gmail.com
Org: blodelyAtSyd
Space: dev
这就可以从程序目录push应用程序到bluemix了(感觉这个架构很重):
$ cf push
Using manifest file /Users/blodely/Desktop/bluemixhubot/hubot/manifest.yml
Updating app nodejshubot in org blodelyAtSyd / space dev as blodely@gmail.com...
OK
Uploading nodejshubot...
Uploading app files from: /Users/blodely/Desktop/bluemixhubot/hubot
Uploading 85K, 64 files
Done uploading
OK
Stopping app nodejshubot in org blodelyAtSyd / space dev as blodely@gmail.com...
OK
Starting app nodejshubot in org blodelyAtSyd / space dev as blodely@gmail.com...
Downloading liberty-for-java_v3_11-20170710-0312...
# 省略省略大段的远端环境自动下载配置的信息...
Staging complete
Uploading droplet, build artifacts cache...
Uploading build artifacts cache...
Uploading droplet...
Uploaded build artifacts cache (1.2M)
Uploaded droplet (18.8M)
Uploading complete
Destroying container
Successfully destroyed container
0 of 1 instances running, 1 starting
1 of 1 instances running
App started
OK
App nodejshubot was started using this command `npm start`
Showing health and status for app nodejshubot in org blodelyAtSyd / space dev as blodely@gmail.com...
OK
requested state: started
instances: 1/1
usage: 256M x 1 instances
urls: nodejshubot.au-syd.mybluemix.net
last uploaded: Sat Sep 2 04:10:43 UTC 2017
stack: cflinuxfs2
buildpack: SDK for Node.js(TM) (ibm-node.js-6.11.1, buildpack-v3.13-20170725-1347)
state since cpu memory disk details
#0 running 2017-09-02 12:12:13 PM 0.2% 48.7M of 256M 75.4M of 1G
这就push成功,应用也启动了.
状态也列举出来在最后面, manifest中写到的一样, 指派了256M内存的使用(???).
Author
骆昱, September 2, 2017
indie.luo@gmail.com