はじめに
『格安なScaleway C2サーバでmicroPCF(自分専用Cloud Foundry)を構築』の記事にて格安のScaleway C2サーバを使って自分用のCloud Foundry環境を構築する記事を書きました。
上記の構築の手順ですと別のマシンやインターネット経由からアクセスするのが面倒なので
外部からアクセスを可能にしたいと思い始めたので、手順をまとめていきたいと思います。
- 事前準備について
『格安なScaleway C2サーバでmicroPCF(自分専用Cloud Foundry)を構築』を合わせて確認してください。 - Scalewayのsecurity groupsについて
security groupsの設定については必要に応じてポートを制限するようにしてください
変更手順
Vagrantfileの変更
Vagrantのport forwardする為に設定を変更します
※60,61を追加
# vi Vagrantfile
58 if !vagrant_up_aws
59 config.vm.network "private_network", ip: local_public_ip
60 config.vm.network :forwarded_port, guest: 80, host: 80
61 config.vm.network :forwarded_port, guest: 443, host: 443
62 end
MICROPCF_DOMAINを設定する
Cloud FoundryのAPI用にワイルドカード・ドメインが必要になります。
今回は便利なxip.ioを使って対応します。
MICROPCF_DOMAINにScaleway のdashboardから確認できるマシンのPublic_IPを指定します。
※今回は仮の値としてpublic_ipが163.1.2.3
の場合の設定をしていきます。
# export MICROPCF_DOMAIN=163.1.2.3.xip.io
Vagrant upする
# vagrant up --provider=virtualbox
動作確認
curlで試す
$ curl https://api.163.1.2.3.xip.io/v2/info -k
{"name":"micropcf-cc","build":"","support":"micropcf@pivotal.io","version":0,"description":"","authorization_endpoint":"http://login.163.1.2.3.xip.io","token_endpoint":"http://uaa.163.1.2.3.xip.io","min_cli_version":null,"min_recommended_cli_version":null,"api_version":"2.48.0","app_ssh_endpoint":"ssh.163.1.2.3.xip.io:2222","app_ssh_host_key_fingerprint":"a6:d1:08:0b:b0:cb:9b:5f:c4:ba:44:2a:97:26:19:8a","app_ssh_oauth_client":"ssh-proxy","routing_endpoint":"https://api.163.1.2.3.xip.io/routing","logging_endpoint":"wss://loggregator.163.1.2.3.xip.io:443","doppler_logging_endpoint":"wss://doppler.163.1.2.3.xip.io:443"}
cfコマンドでログイン
$ cf login -a https://api.163.1.2.3.xip.io --skip-ssl-validation API endpoint: https://api.163.1.2.3.xip.io
Email> admin
Password>
Authenticating...
OK
Targeted org micropcf-org
Targeted space micropcf-space
API endpoint: https://api.163.1.2.3.xip.io (API version: 2.48.0)
User: admin
Org: micropcf-org
Space: micropcf-space
cf passwdでadminパスワードを変更
デフォルトの状態だとパスワードがあまりに単純なので変更していきます。※デフォルトはadmin/admin
です。
$ cf passwd
Current Password>
New Password>
Verify Password>
Changing password...
OK
Please log in again
doraをpushしてみる
$ git clone https://github.com/cloudfoundry/cf-acceptance-tests.git
$ cd cf-acceptance-tests/assets/dora
$ cf push dora
Creating app dora in org micropcf-org / space micropcf-space as admin...
OK
Creating route dora.163.1.2.3.xip.io...
OK
Binding dora.163.1.2.3.xip.io to dora...
OK
Uploading dora...
Uploading app files from: /home/morika-t/cf-acceptance-tests/assets/dora
Uploading 1.2M, 43 files
Done uploading
OK
Starting app dora in org micropcf-org / space micropcf-space as admin...
Downloading java_buildpack...
Downloading ruby_buildpack...
Downloading nodejs_buildpack...
Downloading go_buildpack...
Downloading python_buildpack...
Downloading php_buildpack...
Downloading staticfile_buildpack.
Downloaded binary_buildpack (8.3K)
Downloaded staticfile_buildpack (2.4M)
Downloaded nodejs_buildpack (44.3M)
Downloaded ruby_buildpack (269.1M)
Downloaded java_buildpack (239.9M)
Downloaded go_buildpack (344.8M)
Downloaded python_buildpack (254M)
Downloaded php_buildpack (327.7M)
Creating container
Successfully created container
Downloading app package...
Downloaded app package (1.1M)
Staging...
-------> Buildpack version 1.6.12
Downloaded [file:///tmp/buildpacks/b63e4fc8b7f44b192e4165e7a069bc5f/dependencies/https___pivotal
-buildpacks.s3.amazonaws.com_ruby_binaries_shared_bundler-1.9.7.tgz]
-----> Compiling Ruby/Rack
Downloaded [file:///tmp/buildpacks/b63e4fc8b7f44b192e4165e7a069bc5f/dependencies/https___pivotal
-buildpacks.s3.amazonaws.com_concourse-binaries_ruby_ruby-2.2.3-linux-x64.tgz]
-----> Using Ruby version: ruby-2.2.3
-----> Installing dependencies using bundler 1.9.7
Downloaded [file:///tmp/buildpacks/b63e4fc8b7f44b192e4165e7a069bc5f/dependencies/https___pivotal
-buildpacks.s3.amazonaws.com_ruby_binaries_cflinuxfs2_libyaml-0.1.6.tgz]
Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
Using json 1.8.1
Using bundler 1.9.7
Installing rack 1.5.1
Installing tilt 1.3.3
Installing rack-protection 1.3.2
Installing sinatra 1.3.4
Bundle complete! 4 Gemfile dependencies, 6 gems now installed.
Gems in the groups development and test were not installed.
Bundled gems are installed into ./vendor/bundle.
Bundle completed (2.80s)
Cleaning up the bundler cache.
###### WARNING:
You have not declared a Ruby version in your Gemfile.
To set your Ruby version add this line to your Gemfile:
ruby '2.2.3'
# See https://devcenter.heroku.com/articles/ruby-versions for more information.
###### WARNING:
No Procfile detected, using the default web server (webrick)
https://devcenter.heroku.com/articles/ruby-default-web-server
Exit status 0
Staging complete
Uploading droplet, build artifacts cache...
Uploading droplet...
Uploading build artifacts cache...
Uploaded build artifacts cache (1.3M)
Uploaded droplet (17.8M)
Uploading complete
1 of 1 instances running
App started
OK
App dora was started using this command `bundle exec rackup config.ru -p $PORT`
Showing health and status for app dora in org micropcf-org / space micropcf-space as admin...
OK
requested state: started
instances: 1/1
usage: 1G x 1 instances
urls: dora.163.1.2.3.xip.io
package uploaded: Sun Mar 13 06:24:38 UTC 2016
state since cpu memory disk details
# 0 running 2016-03-13 03:27:20 PM 0.0% 0 of 1G 0 of 1G
curlで確認
$ curl dora.163.1.2.3.xip.io
Hi, I'm Dora!
無事にアクセスできました。
microPCFに内包されているサービスを使う
リリースノートによるとredis
とmysql
がv0.6.0の場合は利用可能なようです。
通常の場合cf marketplace
を叩くと利用可能なサービスが出てくるはずなのですが、今回C2サーバで外部アクセス可能にした環境ではそのままでは一覧に表示されていませんでした。
vagrantのVMの中のプロセスをみると、サービス自体は動作してるようだったので、以下のコマンドを実行することで動作するようになりました。
※おそらく原因はAWS以外では外部アクセス可能なMICROPCF_DOMAIN
の設定変更をするとサービスがうまく登録されない?
手動でservice-brokerを登録する
※cf login
の時のAPIがapi.163.1.2.3.xip.io
の場合は以下のようになります
redisの登録
※service-brokersのIDとパスワードがデフォルトではadminなので、外部アクセス可能な環境の場合はvagrant ssh
でvmに入って/var/vcap/jobs/cf-redis-broker/config/broker.yml
のauth
部分を書き換えた後で/var/vcap/bosh/bin/monit restart cf-redis-broker
で変更することを推奨します。
$ cf create-service-broker p-redis admin admin http://redis-broker.163.1.2.3.xip.io
Creating service broker p-redis as admin...
OK
mysqlの登録
※service-brokersのIDとパスワードがデフォルトではadminなので、外部アクセス可能な環境の場合はvagrant ssh
でvmに入って/var/vcap/jobs/cf-mysql-broker/config/settings.yml
のauth
部分を書き換えた後で/var/vcap/bosh/bin/monit restart cf-mysql-broker
で変更することを推奨します。
$ cf create-service-broker p-mysql admin admin http://mysql.163.1.2.3.xip.io
Creating service broker p-mysql as admin...
OK
enable-service-access
まずは登録したbrokerの一覧確認
$ cf service-brokers
Getting service brokers as admin...
name url
p-mysql http://mysql.163.1.2.3.xip.io
p-redis http://redis-broker.163.1.2.3.xip.io
サービスの有効化
$ cf enable-service-access p-mysql
Enabling access to all plans of service p-mysql for all orgs as admin...
OK
$ cf enable-service-access p-redis
Enabling access to all plans of service p-redis for all orgs as admin...
OK
登録確認
$ 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.