!!注意!!
MicroPCFはPCF Devに名前に変わりました。 PCF Dev版の記事をこちらに書き直しました。Cloud FoundryはオープンソースなPaaSプラットフォームであり、ローカルにもPaaS環境を構築することができます。
MicroPCFは開発用にローカル環境で簡単にCloud Foundryを試すための環境です。(MicroPCFとは?や、BOSH Liteとの違いはこちらのissueを参照してください)
vagrant up
だけで、ローカルに簡単にCloudFoundry環境を作ることができます。
試したのはv0.6.0です。 また、VagrantとVirtualBoxのバージョンは以下の通りです。
$ vagrant --version
Vagrant 1.8.1
$ VBoxManage --version
5.0.12r104815
セットアップ方法
$ wget https://github.com/pivotal-cf/micropcf/releases/download/v0.6.0/micropcf-v0.6.0.zip
$ unzip micropcf-v0.6.0.zip
$ cd micropcf-v0.6.0
設定可能な環境変数は以下の通りです。
MICROPCF_IP
... MicroPCFのIPアドレス(デフォルトは192.168.11.11
)MICROPCF_DOMAIN
... MicroPCFのドメイン名(デフォルトのIPアドレスを使う場合はlocal.micropcf.io
、それ以外の場合は$MICROPCF_IP.xip.io
)VM_CORES
... VMに割り当てるCPU数(デフォルトはホストマシンの論理コア数)VM_MEMORY
... VMに割り当てるメモリ(MB)(デフォルトはホストマシンの1/4のメモリ)
192.168.11.*
をすでに使っている場合は、MICROPCF_IP
を設定しないと、
The specified host network collides with a non-hostonly network!
This will cause your specified IP to be inaccessible. Please change
the IP or name of your host only network so that it no longer matches that of
a bridged or non-hostonly network.
と言われます。この場合は、以下の環境変数を設定してください。
$ export MICROPCF_IP=192.168.33.10
この設定を行った場合は、この後のlocal.micropcf.io
を$MICROPCF_IP.xip.io
に読み替えてください。
以上の設定の後、vagrant up
します。boxのファイルサイズがかなり大きいので初回ダウンロードは時間がかかります。
$ vagrant up --provider virtualbox
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'micropcf/micropcf' could not be found. Attempting to find and install...
default: Box Provider: virtualbox
default: Box Version: 0.14.0
==> default: Loading metadata for box 'micropcf/micropcf'
default: URL: https://atlas.hashicorp.com/micropcf/micropcf
==> default: Adding box 'micropcf/micropcf' (v0.14.0) for provider: virtualbox
default: Downloading: https://atlas.hashicorp.com/micropcf/boxes/micropcf/versions/0.14.0/providers/virtualbox.box
==> default: Successfully added box 'micropcf/micropcf' (v0.14.0) for 'virtualbox'!
==> default: Importing base box 'micropcf/micropcf'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'micropcf/micropcf' is up to date...
==> default: Setting the name of the VM: micropcf-v060_default_1456170793796_10179
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: hostonly
==> default: Forwarding ports...
default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default:
default: Vagrant insecure key detected. Vagrant will automatically replace
default: this with a newly generated keypair for better security.
default:
default: Inserting generated public key within guest...
default: Removing insecure key from the guest if it's present...
default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
==> default: Running provisioner: shell...
default: Running: inline script
==> default: stdin: is not a tty
==> default: Waiting for services to start...
==> default: MicroPCF is now running.
==> default: To begin using MicroPCF, please run:
==> default: cf api api.local.micropcf.io --skip-ssl-validation
==> default: cf login
==> default: Email: admin
==> default: Password: admin
あっさり立ち上がりました!
アプリケーションをデプロイ
まずはログインします。ユーザー名、パスワードともにadmin
です。
$ cf login -a api.local.micropcf.io -u admin -p admin --skip-ssl-validation
API endpoint: api.local.micropcf.io
Authenticating...
OK
Targeted org micropcf-org
Targeted space micropcf-space
API endpoint: https://api.local.micropcf.io (API version: 2.48.0)
User: admin
Org: micropcf-org
Space: micropcf-space
前に書いた入門記事と同じくhello-pws
をpushします。
$ git clone https://github.com/making/hello-pws
$ cd hello-pws
$ mvn clean package
$ cf push hello-pws -p target/hello-pws.jar -m 256m
Creating app hello-pws in org micropcf-org / space micropcf-space as admin...
OK
Using route hello-pws.local.micropcf.io
Binding hello-pws.local.micropcf.io to hello-pws...
OK
Uploading hello-pws...
Uploading app files from: target/hello-pws.jar
Uploading 485.1K, 89 files
Done uploading
OK
Starting app hello-pws in org micropcf-org / space micropcf-space as admin...
Downloading go_buildpack...
Downloading python_buildpack...
Downloading php_buildpack...
Downloading java_buildpack...
Downloading staticfile_buildpack...
Downloading binary_buildpack...
Downloading ruby_buildpack...
Downloading nodejs_buildpack...
Downloaded php_buildpack
Downloaded staticfile_buildpack
Downloaded go_buildpack
Downloaded binary_buildpack
Downloaded java_buildpack
Downloaded nodejs_buildpack
Downloaded python_buildpack
Downloaded ruby_buildpack
Creating container
Successfully created container
Downloading app package...
Downloaded app package (11.7M)
Staging...
-----> Java Buildpack Version: v3.5.1 (offline) | http://github.com/pivotal-cf/pcf-java-buildpack.git#d6c19f8
-----> Downloading Open Jdk JRE 1.8.0_65 from https://download.run.pivotal.io/openjdk/trusty/x86_64/openjdk-1.8.0_65.tar.gz (found in cache)
Expanding Open Jdk JRE to .java-buildpack/open_jdk_jre (1.0s)
-----> Downloading Open JDK Like Memory Calculator 2.0.1_RELEASE from https://download.run.pivotal.io/memory-calculator/trusty/x86_64/memory-calculator-2.0.1_RELEASE.tar.gz (found in cache)
Memory Settings: -Xss853K -Xmx160M -Xms160M -XX:MetaspaceSize=64M -XX:MaxMetaspaceSize=64M
-----> Downloading Spring Auto Reconfiguration 1.10.0_RELEASE from https://download.run.pivotal.io/auto-reconfiguration/auto-reconfiguration-1.10.0_RELEASE.jar (found in cache)
Exit status 0
Staging complete
Uploading droplet, build artifacts cache...
Uploading droplet...
Uploading build artifacts cache...
Uploaded build artifacts cache (108B)
Uploaded droplet (56.7M)
Uploading complete
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
1 of 1 instances running
App started
OK
App hello-pws was started using this command `CALCULATED_MEMORY=$($PWD/.java-buildpack/open_jdk_jre/bin/java-buildpack-memory-calculator-2.0.1_RELEASE -memorySizes=metaspace:64m.. -memoryWeights=heap:75,metaspace:10,native:10,stack:5 -memoryInitials=heap:100%,metaspace:100% -totMemory=$MEMORY_LIMIT) && JAVA_OPTS="-Djava.io.tmpdir=$TMPDIR -XX:OnOutOfMemoryError=$PWD/.java-buildpack/open_jdk_jre/bin/killjava.sh $CALCULATED_MEMORY" && SERVER_PORT=$PORT eval exec $PWD/.java-buildpack/open_jdk_jre/bin/java $JAVA_OPTS -cp $PWD/.:$PWD/.java-buildpack/spring_auto_reconfiguration/spring_auto_reconfiguration-1.10.0_RELEASE.jar org.springframework.boot.loader.JarLauncher`
Showing health and status for app hello-pws in org micropcf-org / space micropcf-space as admin...
OK
requested state: started
instances: 1/1
usage: 256M x 1 instances
urls: hello-pws.local.micropcf.io
last uploaded: Mon Feb 22 21:07:39 UTC 2016
stack: cflinuxfs2
buildpack: java-buildpack=v3.5.1-offline-http://github.com/pivotal-cf/pcf-java-buildpack.git#d6c19f8 java-main open-jdk-like-jre=1.8.0_65 open-jdk-like-memory-calculator=2.0.1_RELEASE spring-auto-reconfiguration=1.10.0_RELEASE
state since cpu memory disk details
#0 running 2016-02-22 01:08:13 PM 0.0% 206.3M of 256M 136.1M of 1G
デプロイできました。
$ curl hello-pws.local.micropcf.io
Hello from 10.0.2.15:60000
スケールアウトも前記事と同じようにできます。
ローカルでCloud Foundryを色々試したい場合に便利です。
ただし、管理コンソールはありません。
またマーケットプレイスにはv0.6.0の段階で
- MySQL
- Redis
が登録されています。これはPivotal Cloud Foundryで使えるサービスとほぼ同じもので、MicroPCFで動いたアプリがPCFでも動くことを目的としてサービスが用意されているようです。
$ cf marketplace
Getting services from marketplace in org micropcf-org / space micropcf-space as admin...
OK
service plans description
p-mysql 512mb, 1gb MySQL databases on demand
p-redis shared-vm Redis service to provide a key-value store
TIP: Use 'cf marketplace -s SERVICE' to view descriptions of individual plans of a given service.
次のバージョンでRabbitMQも使えるようになるかも?