martin@localhost~/Documents$habsetupHabitatCLISetup=================Welcometohabsetup.Let's get started.
Set up a default origin
Every package in Habitat belongs to an origin, which indicates the
person or organization responsible for maintaining that package. Each
origin also has a key used to cryptographically sign packages in that
origin.
Selecting a default origin tells package building operations such as
'habpkgbuild' what key should be used to sign the packages produced.
If you do not set a default origin now, you will have to tell package
building commands each time what origin to use.
For more information on origins and how they are used in building
packages, please consult the docs at
https://www.habitat.sh/docs/build-packages-overview/
Set up a default origin? [Yes/no/quit] yes 这里输入 yes
Enter the name of your origin. If you plan to publish your packages
publicly, we recommend that you select one that is not already in use on
the Habitat build service found at https://app.habitat.sh/.
You already have a default origin set up as `martin',butfeelfreetochangeitifyouwish.Defaultoriginname:[default:martin]这是用来做Habitat包签名和加密用的标识,在代码里面会用到。Youalreadyhaveanoriginkeyformartincreatedandinstalled.Greatwork!GitHubAccessTokenWhileyoucanbuildandrunHabitatpackageswithoutsharingthemonthepublicdepot,doingsoallowsyoutocollaboratewiththeHabitatcommunity.Inaddition,itishowyoucanperformcontinuousdeploymentwithHabitat.ThedepotusesGitHubauthenticationwithanaccesstoken(https://help.github.com/articles/creating-an-access-token-for-command-line-use/).Ifyouwouldliketoshareyourpackagesonthedepot,pleaseenteryourGitHubaccesstoken.Otherwise,justenterNo.Formoreinformationonsharingpackagesonthedepot,pleasereadthedocumentationathttps://www.habitat.sh/docs/share-packages-overview/SetupadefaultGitHubaccesstoken?[Yes/no/quit]yes这里选择yesEnteryourGitHubaccesstoken.Youalreadyhaveadefaultauthtokensetup,butfeelfreetochangeitifyouwish.GitHubaccesstoken:[default:martin-github-token]这个token需要自己去github里面生成AnalyticsThe`hab`command-linetoolwilloptionallysendanonymoususagedatatoHabitat's Google Analytics account. This is a strictly opt-in activity
and no tracking will occur unless you respond affirmatively to the
question below.
We collect this data to help improve Habitat'suserexperience.Forexample,wewouldliketoknowthecategoryoftasksusersareperforming,andwhichonestheyarehavingtroublewith(e.g.mistypingcommandlinearguments).Toseewhatkindsofdataaresentandhowtheyareanonymized,pleasereadmoreaboutouranalyticshere:https://www.habitat.sh/docs/about-analytics/Enableanalytics?[yes/No/quit]no这里选择no»Optingoutofanalytics☑Creating/Users/martin/.hab/cache/analytics/OPTED_OUT★Analyticsoptedout,wesaluteyoujustthesame!CLISetupCompleteThat's all for now. Thanks for using Habitat!
martin@localhost ~/Documents $
$ docker-machine ls NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
default - virtualbox Running tcp://192.168.99.100:2376 v1.11.1
$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
martin@localhost~/Documents/GitHub/habitat-example-plans/mytutorialapp$habstudioenter[±master●●]hab-studio:CreatingStudioat/hab/studios/src(default)hab-studio:Importingmartinsecretoriginkey»Importingoriginkeyfromstandardinput★Importedsecretoriginkeymartin-20160630040241.hab-studio:EnteringStudioat/hab/studios/src(default)hab-studio:Exported:HAB_ORIGIN=martin[1][default:/src:0]# build:Loading/src/plan.shmytutorialapp:Planloadedmytutorialapp:hab-plan-buildsetupmytutorialapp:UsingHAB_BIN=/hab/pkgs/core/hab/0.7.0/20160614230104/bin/habforinstalls,signing,andhashingmytutorialapp:Resolvingdependencies»Installingcore/node→Usingcore/gcc-libs/5.2.0/20160612075020→Usingcore/glibc/2.22/20160612063629→Usingcore/linux-headers/4.3/20160612063537↓Downloadingcore/node/4.2.6/201606121435316.44MB/6.44MB \ [=======================================================================]100.00%457.82KB/s↓Downloadingcore-20160612031944publicoriginkey75B/75B|[=============================================================================]100.00%575.13KB/s☑Cachedcore-20160612031944publicoriginkey✓Installedcore/node/4.2.6/20160612143531★Installofcore/nodecompletewith4packagesinstalled.mytutorialapp:Resolveddependency'core/node'to/hab/pkgs/core/node/4.2.6/20160612143531mytutorialapp:SettingPATH=/hab/pkgs/core/node/4.2.6/20160612143531/bin:/hab/pkgs/core/hab-plan-build/0.7.0/20160614232259/bin:/hab/pkgs/core/bash/4.3.42/20160612075613/bin:/hab/pkgs/core/binutils/2.25.1/20160612064534/bin:/hab/pkgs/core/bzip2/1.0.6/20160612075040/bin:/hab/pkgs/core/coreutils/8.24/20160612075329/bin:/hab/pkgs/core/file/5.24/20160612064523/bin:/hab/pkgs/core/findutils/4.4.2/20160612080341/bin:/hab/pkgs/core/gawk/4.1.3/20160612075739/bin:/hab/pkgs/core/grep/2.22/20160612075540/bin:/hab/pkgs/core/gzip/1.6/20160612080637/bin:/hab/pkgs/core/hab/0.7.0/20160614230104/bin:/hab/pkgs/core/sed/4.2.2/20160612075228/bin:/hab/pkgs/core/tar/1.28/20160612075701/bin:/hab/pkgs/core/unzip/6.0/20160612081414/bin:/hab/pkgs/core/wget/1.16.3/20160612081342/bin:/hab/pkgs/core/xz/5.2.2/20160612080402/bin:/hab/pkgs/core/acl/2.2.52/20160612075215/bin:/hab/pkgs/core/attr/2.4.47/20160612075207/bin:/hab/pkgs/core/glibc/2.22/20160612063629/bin:/hab/pkgs/core/less/481/20160612080021/bin:/hab/pkgs/core/libcap/2.24/20160612075226/bin:/hab/pkgs/core/libidn/1.32/20160612081104/bin:/hab/pkgs/core/ncurses/6.0/20160612075116/bin:/hab/pkgs/core/openssl/1.0.2h/20160612081127/bin:/hab/pkgs/core/pcre/8.38/20160612075520/binmkdir:createddirectory'/hab/cache/src'mytutorialapp:Downloading'https://s3-us-west-2.amazonaws.com/mytutorialapp/mytutorialapp-0.1.0.tar.gz'to'mytutorialapp-0.1.0.tar.gz'--2016-07-0102:27:51--https://s3-us-west-2.amazonaws.com/mytutorialapp/mytutorialapp-0.1.0.tar.gzResolvings3-us-west-2.amazonaws.com(s3-us-west-2.amazonaws.com)...54.231.184.216Connectingtos3-us-west-2.amazonaws.com(s3-us-west-2.amazonaws.com)|54.231.184.216|:443...connected.HTTPrequestsent,awaitingresponse...200OKLength:1041(1.0K)[application/x-gzip]Savingto:'mytutorialapp-0.1.0.tar.gz'mytutorialapp-0.1.0.tar.gz100%[===================================================>]1.02K--.-KB/sin0.03s2016-07-0102:28:08(32.1KB/s)-'mytutorialapp-0.1.0.tar.gz'saved[1041/1041]mytutorialapp:Downloaded'mytutorialapp-0.1.0.tar.gz'mytutorialapp:Verifyingmytutorialapp-0.1.0.tar.gzmytutorialapp:Checksumverifiedformytutorialapp-0.1.0.tar.gzmytutorialapp:Cleanthecachemytutorialapp:Unpackingmytutorialapp-0.1.0.tar.gzmytutorialapp:Settingbuildenvironmentmytutorialapp:SettingPREFIX=/hab/pkgs/martin/mytutorialapp/0.1.0/20160701022725mytutorialapp:SettingLD_RUN_PATH=/hab/pkgs/core/node/4.2.6/20160612143531/libmytutorialapp:SettingCFLAGS=-I/hab/pkgs/core/node/4.2.6/20160612143531/includemytutorialapp:SettingLDFLAGS=-L/hab/pkgs/core/node/4.2.6/20160612143531/libmytutorialapp:Preparingtobuildmytutorialapp:BuildingnpmWARNpackage.jsonmytutorialapp@0.1.0Norepositoryfield.npmWARNpackage.jsonmytutorialapp@0.1.0NoREADMEdatanconf@0.8.4node_modules/nconf├──ini@1.3.4├──secure-keys@1.0.0├──async@1.5.2└──yargs@3.32.0(decamelize@1.2.0,camelcase@2.1.1,window-size@0.1.4,y18n@3.2.1,os-locale@1.4.0,cliui@3.2.0,string-width@1.0.1)mytutorialapp:Installing'node_modules/nconf'->'/hab/pkgs/martin/mytutorialapp/0.1.0/20160701022725/node_modules/nconf'忽略了好几百行输出'node_modules/nconf/node_modules/secure-keys/test/simple-test.js'->'/hab/pkgs/martin/mytutorialapp/0.1.0/20160701022725/node_modules/nconf/node_modules/secure-keys/test/simple-test.js''node_modules/nconf/node_modules/secure-keys/test/test.secret.key'->'/hab/pkgs/martin/mytutorialapp/0.1.0/20160701022725/node_modules/nconf/node_modules/secure-keys/test/test.secret.key''node_modules/nconf/node_modules/secure-keys/package.json'->'/hab/pkgs/martin/mytutorialapp/0.1.0/20160701022725/node_modules/nconf/node_modules/secure-keys/package.json'mytutorialapp:Writingconfigurationmytutorialapp:Writingservicemanagementscriptsmytutorialapp:Strippingunneededsymbolsfrombinariesandlibrariesmytutorialapp:Creatingmanifestmytutorialapp:Buildingpackagemetadatamytutorialapp:Generatingblake2bhashesofallfilesinthepackagemytutorialapp:GeneratingsignedmetadataFILES»Signingmytutorialapp_blake2bsums☛Signingmytutorialapp_blake2bsumswithmartin-20160630040241tocreate/hab/pkgs/martin/mytutorialapp/0.1.0/20160701022725/FILES★Signedartifact/hab/pkgs/martin/mytutorialapp/0.1.0/20160701022725/FILES.mytutorialapp:Generatingpackageartifact/hab/pkgs/core/tar/1.28/20160612075701/bin/tar:Removingleading`/' from member names/hab/cache/artifacts/.martin-mytutorialapp-0.1.0-20160701022725-x86_64-linux.tar(1/1)100%121.4KiB/900.0KiB=0.135»Signing/hab/cache/artifacts/.martin-mytutorialapp-0.1.0-20160701022725-x86_64-linux.tar.xz☛Signing/hab/cache/artifacts/.martin-mytutorialapp-0.1.0-20160701022725-x86_64-linux.tar.xzwithmartin-20160630040241tocreate/hab/cache/artifacts/martin-mytutorialapp-0.1.0-20160701022725-x86_64-linux.hart★Signedartifact/hab/cache/artifacts/martin-mytutorialapp-0.1.0-20160701022725-x86_64-linux.hart.'/hab/cache/artifacts/martin-mytutorialapp-0.1.0-20160701022725-x86_64-linux.hart'->'/src/results/martin-mytutorialapp-0.1.0-20160701022725-x86_64-linux.hart'mytutorialapp:hab-plan-buildcleanupmytutorialapp:mytutorialapp:SourceCache:/hab/cache/src/mytutorialapp-0.1.0mytutorialapp:InstalledPath:/hab/pkgs/martin/mytutorialapp/0.1.0/20160701022725mytutorialapp:Artifact:/src/results/martin-mytutorialapp-0.1.0-20160701022725-x86_64-linux.hartmytutorialapp:BuildReport:/src/results/last_build.envmytutorialapp:SHA256Checksum:d4bfb3a44989b8a5b1295eac2600d75f42dd2be6f537344312c8917cba47d05dmytutorialapp:Blake2bChecksum:fbff257eb36fffa61e6cbf5ec89fa3f507095f80f5cca610c2bb72685d758706mytutorialapp:mytutorialapp:Iloveitwhenaplan.shcomestogether.mytutorialapp:mytutorialapp:Buildtime:1m3s[2][default:/src:0]#
检查结果,在代码的目录中可以看的 result 目录,关注一下这个目录,关键看 build 命令的最后一段。
1
2
mytutorialapp: hab-plan-build cleanup mytutorialapp: mytutorialapp: Source Cache: /hab/cache/src/mytutorialapp-0.1.0 mytutorialapp: Installed Path: /hab/pkgs/martin/mytutorialapp/0.1.0/20160701022725 mytutorialapp: Artifact: /src/results/martin-mytutorialapp-0.1.0-20160701022725-x86_64-linux.hart mytutorialapp: Build Report: /src/results/last_build.env mytutorialapp: SHA256 Checksum: d4bfb3a44989b8a5b1295eac2600d75f42dd2be6f537344312c8917cba47d05d mytutorialapp: Blake2b Checksum: fbff257eb36fffa61e6cbf5ec89fa3f507095f80f5cca610c2bb72685d758706 mytutorialapp: mytutorialapp: I love it when a plan.sh comes together. mytutorialapp: mytutorialapp: Build time: 1m3s
昨晚分享的高潮部分, habitat 导出 docker image
其实就是一条命令,在 habitat Studio 中执行 导出命令 hab pkg export docker martin/mytutorialapp
$docker-composeconfignetworks:{}services:db:image:192.168.99.20:5000/postgres:9.4redis:image:192.168.99.20:5000/redis:alpineports:-'6379'result:build:context:/Users/martin/Documents/GitHub/example-voting-app/resultcommand:nodemon--debugserver.jsports:-5001:80-5858:5858volumes:-/Users/martin/Documents/GitHub/example-voting-app/result:/app:rwvote:build:context:/Users/martin/Documents/GitHub/example-voting-app/votecommand:pythonapp.pyports:-5000:80volumes:-/Users/martin/Documents/GitHub/example-voting-app/vote:/app:rwworker:build:context:/Users/martin/Documents/GitHub/example-voting-app/workerversion:'2.0'volumes:{}$docker-composeupRecreatingexamplevotingapp_vote_1Recreatingexamplevotingapp_worker_1Startingexamplevotingapp_db_1Startingexamplevotingapp_redis_1Recreatingexamplevotingapp_result_1Attachingtoexamplevotingapp_db_1,examplevotingapp_redis_1,examplevotingapp_worker_1,examplevotingapp_result_1,examplevotingapp_vote_1redis_1|_._redis_1|_.-``__''-._redis_1|_.-```.`_.''-._Redis3.2.1(00000000/0)64bitredis_1|.-``.-```.```\/_.,_''-._db_1|LOG:databasesystemwasshutdownat2016-06-2009:58:19UTCredis_1|(' , .-` | `, ) Running in standalone mode
redis_1 | |`-._`-...-` __...-.``-._|'`_.-'| Port: 6379
redis_1 | | `-._ `._ / _.-'|PID:1redis_1|`-._`-._`-./_.-' _.-'redis_1||`-._`-._`-.__.-' _.-'_.-'|
redis_1 | | `-._`-._ _.-'_.-' | http://redis.io
redis_1 | `-._ `-._`-.__.-'_.-' _.-'redis_1||`-._`-._`-.__.-' _.-'_.-'|
db_1 | LOG: MultiXact member wraparound protections are now enabled
redis_1 | | `-._`-._ _.-'_.-' |
redis_1 | `-._ `-._`-.__.-'_.-' _.-'db_1|LOG:databasesystemisreadytoacceptconnectionsredis_1|`-._`-.__.-' _.-'redis_1|`-.__.-'
redis_1 | `-.__.-'redis_1|redis_1|1:M20Jun10:13:36.216# WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
redis_1|1:M20Jun10:13:36.216# Server started, Redis version 3.2.1
redis_1|1:M20Jun10:13:36.216# WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
db_1|LOG:autovacuumlauncherstartedredis_1|1:M20Jun10:13:36.216# WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
redis_1|1:M20Jun10:13:36.216*Theserverisnowreadytoacceptconnectionsonport6379vote_1|*Runningonhttp://0.0.0.0:80/(PressCTRL+Ctoquit)vote_1|*Restartingwithstatresult_1|[nodemon]1.9.2result_1|[nodemon]torestartatanytime,enter`rs`result_1|[nodemon]watching:*.*result_1|[nodemon]starting`node--debugserver.js`result_1|Debuggerlisteningonport5858vote_1|*Debuggerisactive!vote_1|*Debuggerpincode:139-254-286worker_1|Foundredisat172.19.0.2result_1|Mon,20Jun201610:13:40GMTbody-parserdeprecatedbodyParser:useindividualjson/urlencodedmiddlewaresatserver.js:67:9result_1|Mon,20Jun201610:13:40GMTbody-parserdeprecatedundefinedextended:provideextendedoptionat../node_modules/body-parser/index.js:105:29result_1|Apprunningonport80result_1|Connectedtodb
打开浏览器测试 vote 应用。
1
open http://192.168.99.114:5000
正常显示结果如下图所示:
打开浏览器测试 result 应用。
1
open http://192.168.99.114:5001
正常显示结果如下图所示:
在 Rancher 的 hosts 界面中应该看到这些运行的容器。
至此所有关于应用构建和功能测试的过程完成,按 ctl + c 结束 docker-compose up 的运行。