Index > AP User Guide > Ruby ๊ฐ๋ฐ
- ๊ฐ์
- Ruby ์ ํ๋ฆฌ์ผ์ด์ ๊ฐ๋ฐ๊ฐ์ด๋
๋ณธ ๋ฌธ์(Ruby ์ ํ๋ฆฌ์ผ์ด์ ๊ฐ๋ฐ ๊ฐ์ด๋)๋ ๊ฐ๋ฐฉํ ํ๋ซํผ ํ๋ก์ ํธ์ ์๋น์คํฉ(Mysql, Cubrid, MongoDB, RabbitMQ, Redis, GlusterFS)์ Ruby ์ ํ๋ฆฌ์ผ์ด์ ๊ณผ ์ฐ๋ํ์ฌ ์ฌ์ฉํ๊ณ Ruby ์ ํ๋ฆฌ์ผ์ด์ ์ ๋ฐฐํฌํ๋ ๋ฐฉ๋ฒ์ ๋ํด ์ ์ํ๋ ๋ฌธ์์ด๋ค.
๋ณธ ๋ฌธ์์ ๋ฒ์๋ Open PaaS ํ๋ก์ ํธ์ Ruby ์ ํ๋ฆฌ์ผ์ด์ ๊ฐ๋ฐ๊ณผ ์๋น์คํฉ ์ฐ๋, ์ ํ๋ฆฌ์ผ์ด์ ๋ฐฐํฌ์ ๋ํ ๋ด์ฉ์ผ๋ก ํ์ ๋์ด ์๋ค.
http://rubyinstaller.org/
https://docs.pivotal.io/pivotalcf/buildpacks/ruby/index.html/
http://rubykr.github.io/rails_guides/getting_started.html/
https://github.com/brianmario/mysql2/
http://www.cubrid.org/manual/93/ko/api/ruby.html/
https://docs.mongodb.org/ecosystem/drivers/ruby/
http://rubybunny.info/articles/getting_started.html/
https://github.com/redis/redis-rb/
https://github.com/fog/fog/
๊ฐ๋ฐฉํ ํ๋ซํผ์ ๋ฑ๋ก๋ ๋ค์ํ ์๋น์คํฉ์ Ruby์ธ์ด๋ก ์์ฑ๋ ์ ํ๋ฆฌ์ผ์ด์ ๊ณผ ๋ฐ์ธ๋ฉํ๊ณ ํด๋น ์ ํ๋ฆฌ์ผ์ด์ ์ ๋ฐ์ธ๋ฉ๋ ์๋น์ค ํ๊ฒฝ์ ๋ณด(VCAP_SERVICES)๋ฅผ ์ด์ฉํ์ฌ ์ ํ๋ฆฌ์ผ์ด์ ๊ด ์ฐ๋ํ๊ณ ๊ฐ ์๋น์ค๋ฅผ ์ฌ์ฉ ํ ์ ์๋๋ก Windows๊ธฐ๋ฐ ํ๊ฒฝ์์ ๊ฐ๋ฐฉํ ํ๋ซํผ์ ๋ฐฐํฌํ Ruby ์ ํ๋ฆฌ์ผ์ด์ ์ ์์ฑํ๋ ๋ฐฉ๋ฒ์ ์ค๋ช ํ๋ค.
Ruby ์ ํ๋ฆฌ์ผ์ด์ ๊ฐ๋ฐ์ ์ํด ๋ค์๊ณผ ๊ฐ์ ํ๊ฒฝ์ผ๋ก ๊ฐ๋ฐํ๊ฒฝ์ ๊ตฌ์ฑ ํ๋ค.
- OS : Windows 7 64bit
- Ruby : 1.9.3-p551
- Framwork : Ruby On Rails 4.1.8
- IDE : RubyMine 7.1.1
โป CubridDB์ Ruby ๋๋ผ์ด๋ฒ ์ต์ ์ง์ ๋ฒ์ ์ด Ruby 1.9.3 ๊น์ง ์ง์ํ์ฌ ํด๋น ๋ฒ์ ์ ์ ํํ์๋ค. ๊ฐ ์๋น์ค๋ณ ์ง์ ๋๋ ๋๋ผ์ด๋ฒ(๋๋ Gem)์ ๋ง๋ Ruby ๋ฒ์ ์ ์ฌ์ฉํ๊ธธ ๊ถ์ฅํ๋ค.
โป Ruby IDE๋ ๊ฐ๋ณ ์ ํํ์ฌ ์ฌ์ฉํ๋ค.
- Ruby & DevKit ๋ค์ด๋ก๋
http://rubyinstaller.org/downloads/
- ๋ค์ด๋ก๋
RubyInstallers : Ruby 1.9.3-p551
DEVELOPMENT KIT : DevKit-tdm-32-4.5.2-20111229-1559-sfx
- Ruby ์ค์น
- โI accept the Licenseโ ์ ํ ํ โNextโ ๋ฒํผ ํด๋ฆญ
- โAdd Ruby executables to your PATHโ ์ ํ ํ โInstallโ ๋ฒํผ ํด๋ฆญ
- โFinishโ ๋ฒํผ์ ํด๋ฆญํ์ฌ Ruby ์ค์น๋ฅผ ์ข ๋ฃํ๋ค.
- DEVELOPMENT KIT ์ค์น
- DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe์ ๋๋ธํด๋ฆญํ์ฌ ์ค์น๋ฅผ ์คํํ๋ค.
- ์ค์นํ ํด๋๋ฅผ ์ง์ ํ๊ณ โExtractโ๋ฒํผ์ ํด๋ฆญํ๋ค.
- Windows์ CMD ์ฐฝ์ ์คํํ์ฌ DevKit ์ค์น ํด๋๋ก ์ด๋ํ๋ค.
ruby dk.rb init
ruby dk.rb install
- โruby dk.rb installโ ๋ช
๋ น์ ์คํํ์ฌ DevKit์ ์ค์นํ๋ค.
- โruby โvโ ๋ช
๋ น์ ์คํํ์ฌ ๋ฃจ๋น ๋ฒ์ ์ ํ์ธํ๋ค.
- Ruby On Rails ์ค์น
- โgem update rdocโ ๋ช
๋ น์ ์คํํ์ฌ rdoc gem์ ์
๋ฐ์ดํธํ๋ค.(๋ฏธ ์คํ์ rails install์ ์๋ฌ๊ฐ ๋ฐ์ ํ ์ ์๋ค.)
- โgem install rails โv 4.1.8โ ๋ช
๋ น์ ์คํํ์ฌ rails์ ์ค์นํ๋ค.
- โrails โvโ ๋ช
๋ น์ ์ฌ์ฉํ์ฌ rails์ ๋ฒ์ ์ ํ์ธํ๋ค.
Ruby ์ํ ์ ํ๋ฆฌ์ผ์ด์ ์ ๊ฐ๋ฐํ๊ธฐ ์ํ ์ ํ๋ฆฌ์ผ์ด์ ์ ์์ฑ๊ณผ ํ๊ฒฝ์ค์ , VCAP_SERVICES ์ ๋ณด์ ํ๋ ๋ฐ ๊ฐ ์๋น์ค์ ์ฐ๋ ๋ฐฉ๋ฒ์ ๋ํ์ฌ ์ค๋ช ํ๋ค.
- ์ํ ์ ํ๋ฆฌ์ผ์ด์ ๋ค์ด๋ก๋
์์ฑ๋ ์ํ ์ ํ๋ฆฌ์ผ์ด์ ์ ์๋ ๋งํฌ์ /OpenPaaSSample/ruby-sample-app ์์ ๋ฐ์ ์ ์๋ค.
https://nextcloud.paas-ta.org/index.php/s/x8Tg37WDFiL5ZDi/download
- Rails ์ ํ๋ฆฌ์ผ์ด์ ์์ฑ(bundle install ์ ์ธ)
- ์๋ ์์ฑ ํด๋ ๋ฐ ํ์ผ ์ ์
ํ์ผ/ํด๋ | ๋ชฉ์ |
Gemfile | ์ด ํ์ผ์ ์ฌ๋ฌ๋ถ์ ๋ ์ผ์ฆ ์ดํ๋ฆฌ์ผ์ด์ ์๊ฒ ํ์ํ ์ ฌ์ ์์กด์ฑ ์ ๋ณด๋ฅผ ๊ธฐ์ ํ๋๋ฐ ์ฌ์ฉ๋ฉ๋๋ค. |
README | ์ด ํ์ผ์ ์ดํ๋ฆฌ์ผ์ด์ ์ ์ํ ์งง๋งํ ์ค๋ช ์ ๋๋ค. ์ค์น, ์ฌ์ฉ ๋ฐฉ๋ฒ ๊ธฐ์ ์ ์ฐ์ ๋๋ค. |
Rakefile | ์ด ํ์ผ์ ํฐ๋ฏธ๋์์ ์คํํ ์ ์๋ ๋ฐฐ์น์ก๋ค์ ํฌํจํฉ๋๋ค. |
app/ | ์ดํ๋ฆฌ์ผ์ด์ ์ ์ํ ์ปจํธ๋กค๋ฌ, ๋ชจ๋ธ, ๋ทฐ๋ฅผ ํฌํจํฉ๋๋ค. ์ด ๊ฐ์ด๋์์๋ ์ด ํด๋์ ์ง์คํ ๊ฒ ์ ๋๋ค. |
config/ | ์ดํ๋ฆฌ์ผ์ด์ ์ ์คํ ์๊ฐ์ ๊ท์น, ๋ผ์ฐํ , ๋ฐ์ดํฐ๋ฒ ์ด์ค ๋ฑ ์ค์ ์ ์ ์ฅํฉ๋๋ค. |
config.ru | ๋(Rack) ๊ธฐ๋ฐ์ ์๋ฒ๋ค์ด ์์ํ ๋ ํ์ํ ์ค์ ์ ๋๋ค. |
db/ | ํ์ฌ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์คํค๋ง๋ฅผ ๋ณผ ์ ์์ต๋๋ค.(๋ฐ์ดํฐ๋ฒ ์ด์ค ๋ง์ด๊ทธ๋ ์ด์ ์ผ๋ก ์ ์๋ ค์ ธ ์์ต๋๋ค.) ์ฌ๋ฌ๋ถ์ ๋ง์ด๊ทธ๋ ์ด์ ์ ๋ํด์ ๊ฐ๋จํ๊ฒ ๋ฐฐ์ฐ๊ฒ ๋ฉ๋๋ค. |
doc/ | ์ดํ๋ฆฌ์ผ์ด์ ์ ๋ํ ์์ธํ ์ค๋ช ๋ฌธ์์ ๋๋ค. |
lib/ | ์ดํ๋ฆฌ์ผ์ด์ ์ ์ํ ํ์ฅ ๋ชจ๋์ ๋๋ค. (์ด ๋ฌธ์์์ ๋ค๋ฃจ์ง ์์ต๋๋ค.) |
public/ | ์ธ๋ถ์์ ๋ณผ์ ์๋ ์ ์ผํ ํด๋ ์ ๋๋ค.์ด๋ฏธ์ง, ์๋ฐ์คํฌ๋ฆฝํธ, ์คํ์ผ์ํธ๋ ๊ทธ์ธ ์ ์ ์ธ ํ์ผ๋ค์ ์ด๊ณณ์ ๋์ธ์. |
script/ | ๋ ์ผ์ฆ ์คํฌ๋ฆฝํธ๋ฅผ ํฌํจํฉ๋๋ค. ์ฌ๋ฌ๋ถ์ ์ดํ๋ฆฌ์ผ์ด์ ์ ์คํ์ํค๊ฑฐ๋, ๋ฐฐํฌ, ์คํ ๊ด๋ จํ ์คํฌ๋ฆฝํธ๋ฅผ ๋์ธ์. |
test/ | ์ ๋ ํ ์คํธ, ํฝ์ค์ณ, ๊ทธ์ ๋ค๋ฅธ ํ ์คํธ ๋๊ตฌ๋ค ์ ๋๋ค. ์ด ๋ถ๋ถ์ ๋ ์ผ์ฆ ์ดํ๋ฆฌ์ผ์ด์ ํ ์คํธํ๊ธฐ ๊ฐ ๋ด๋นํฉ๋๋ค. |
tmp/ | ์์ ํ์ผ |
vendor/ | ์๋ ํํฐ ์ฝ๋๋ค์ ์ํ ๊ณต๊ฐ์ ๋๋ค. ์ผ๋ฐ์ ์ธ ๋ ์ผ์ฆ ์ดํ๋ฆฌ์ผ์ด์ ์ ๋ฃจ๋น ์ ฌ๊ณผ ๋ ์ผ์ฆ ์์ค-ํ๋ก์ ํธ ๋ด์ ์ค์น์-์ ๋ฏธ๋ฆฌ ํจํค์ง๋ ์ถ๊ฐ ํ๋ฌ๊ทธ์ธ๋ค์ด ์์นํฉ๋๋ค. |
ํด๋น ์์ ๋ Ruby 1.9.3์ ๊ธฐ์ค์ผ๋ก ๊ฐ ๋๋ผ์ด๋ฒ์ ๋ฒ์ ์ ๋ช
์์ ์ผ๋ก ์ ํํ์ฌ ์ค์นํ์์ต๋๋ค.
./Gemfile ์์ (์ค์ )์ ์ค์น๋ Ruby์ ๋ฒ์ ์ ๋ง๋ ์ ฌ์ ์ค์นํ๋๋ก ๊ถ์ฅํฉ๋๋ค.
ํ์ผ/ํด๋ | ๋ชฉ์ |
./Gemfile | ์ด ํ์ผ์ ์ฌ๋ฌ๋ถ์ ๋ ์ผ์ฆ ์ดํ๋ฆฌ์ผ์ด์ ์๊ฒ ํ์ํ ์ ฌ์ ์์กด์ฑ ์ ๋ณด๋ฅผ ๊ธฐ์ |
./config/application.rb | ์ ํ๋ฆฌ์ผ์ด์ ์ ํ๊ฒฝ์ค์ |
./config/routes.rb | Request URL๊ณผ ์ปจํธ๋กค๋ฌ์ ๋งคํ ์ค์ |
./config/environments/development.rb | ๊ฐ๋ฐํ๊ฒฝ ์ค์ (Localhost ์๋ฒ ์คํ์ ๊ธฐ๋ณธ ํ๊ฒฝ์ค์ ) |
./config/environments/production.rb | ์์ฉํ๊ฒฝ ์ค์ (๊ฐ๋ฐฉํ ํ๋ซํผ ๋ฐฐํฌ์ ์ฌ์ฉ๋๋ ๊ธฐ๋ณธ ํ๊ฒฝ์ค์ ) |
- ./Gemfile ์์
- ๊ฐ ์๋น์ค์์ ์ฌ์ฉํ ๋๋ผ์ด๋ฒ ๋ฐ ํ์ํ ์ ฌ์ ์ ์ํ๋ค.
# https => http ๋ณ๊ฒฝ
source 'http://rubygems.org'
# Ruby ๋ฒ์ ๋ช
์
ruby '1.9.3'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.8'
...(์ค๋ต)...
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin]
# Cloud Foundry ์ ํธ
gem 'cf-app-utils'
# MySQL ๋๋ผ์ด๋ฒ
gem 'mysql2', '~> 0.3.20'
# Cubrid ๋๋ผ์ด๋ฒ
gem 'cubrid'
# MongoDB ๋๋ผ์ด๋ฒ
gem 'mongo'#, '~> 2.1'
# RabbitMP ๋๋ผ์ด๋ฒ
gem 'amq-protocol', '1.9.2'
gem 'bunny', '1.7.0'
# Openstack for swift(glusterfs)' ๋๋ผ์ด๋ฒ
gem 'net-ssh', '2.9.2'
gem 'fog-google', '0.1.0'
gem 'fog', '1.34.0'
# Redis ๋๋ผ์ด๋ฒ
gem 'redis'
group :development, :test do
gem 'rspec-rails', '~> 3.0.0'
end
โป Windows ํ๊ฒฝ์์ Cubrid ๋๋ผ์ด๋ฒ๋ Cubrid์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ๋ฏ๋ก ํด๋น Ruby ๋ฒ์ ์ ๋ง๋ Cubrid๋ฅผ ์ค์นํ์ฌ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฐธ์กฐ ํ ์ ์๋๋ก ํ์ฌ์ผํ๋ค.
โป ํด๋น ์ํ์ Ruby 1.9.3(64bit ๋ฏธ์ง์) ์ด๋ฏ๋ก CUBRID-Windows-x86(32bit)๋ฒ์ ์ ์ค์นํ์๋ค.
- ์ ฌ ์ค์น
- Gemfile์ ์ ์๋ ์ ฌ์ ์ค์นํ๋ค.
bundle install
- ./config/application.rb ์์
- ์ ํ๋ฆฌ์ผ์ด์ ์ ํ๊ฒฝ์ค์
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module RubySampleApp
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
# Rails ์ ํ๋ฆฌ์ผ์ด์
๊ตฌ๋์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ Loading path ์ถ๊ฐ
config.autoload_paths += %W(#{config.root}/lib)
# ์์ธ์ฒ๋ฆฌ(routes.rb์ฐธ์กฐ ํ๋๋ก ์ค์ )
config.exceptions_app = self.routes
end
end
- ./config/routes.rb ์์
- Request URL๊ณผ ์ปจํธ๋กค๋ฌ์ ๋งคํ ์ค์
Rails.application.routes.draw do
# ์ธ๋ฑ์ค(root) ํ์ด์ง ์ค์
root 'static#login'
# ์ ์ ํ์ด์ง์ค์ (.html)
get '/login' => 'static#login'
get '/main/:org_id' => 'static#main'
get '/manage' => 'static#manage'
...(์ค๋ต)...
# ๊ธฐ๋ฅ๋ณ API Path ์ค์
#[HTTP๋ฉ์๋] โ[Uri]โ => โ[Controller#๋ฉ์๋]โ
get 'org-chart/:org_id/mysql' => 'org_chart_mysql#index'
get 'org-chart/:org_id/cubrid' => 'org_chart_cubrid#index'
get 'org-chart/:org_id/mongo' => 'org_chart_mongo#index'
...(์๋ต)
- ./config/environments/development.rb
- ๊ฐ๋ฐํ๊ฒฝ ์ค์ ( Localhost ์๋ฒ ์คํ์ ๊ธฐ๋ณธ ํ๊ฒฝ์ค์ )
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
...(์ค๋ต)...
# Show full error reports and disable caching.
# ์์ธ ๋ฐ์์ฒ๋ฆฌ ๊ธฐ๋ฅ ์ค์ (Jsonํ์ผ๋ก ๋ฐํ ๋ฐ๊ธฐ์ํจ)
config.consider_all_requests_local = false
config.action_controller.perform_caching = false
...(์ค๋ต)...
# public static html page view
# ./public ํด๋ ์ ๊ทผ ํ์ฉ ์ฌ๋ถ ์ค์ (js, css, image ์ ์ ๋ฆฌ์์ค)
config.serve_static_assets = true
# Disable request forgery protection in test environment
# authenticity_token ignore
# Post, Put ๋ฉ์๋ ํธ์ถ์ ์ธ์ฆ ์ ์ฐจ ์ค์
config.action_controller.allow_forgery_protection = false
end
- ./config/environments/production.rb
- ์์ฉํ๊ฒฝ ์ค์ (๊ฐ๋ฐฉํ ํ๋ซํผ ๋ฐฐํฌ์ ์ฌ์ฉ๋๋ ๊ธฐ๋ณธ ํ๊ฒฝ์ค์ )
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
...(์ค๋ต)...
# Disable request forgery protection in test environment
# authenticity_token ignore
# Post, Put ๋ฉ์๋ ํธ์ถ์ ์ธ์ฆ ์ ์ฐจ ์ค์
config.action_controller.allow_forgery_protection = false
๊ฐ๋ฐฉํ ํ๋ซํผ์ ๋ฐฐํฌ๋๋ ์ ํ๋ฆฌ์ผ์ด์ ์ด ๋ฐ์ธ๋ฉ๋ ์๋น์ค๋ณ ์ ์ ์ ๋ณด๋ฅผ ์ป๊ธฐ ์ํด์๋ ์ ํ๋ฆฌ์ผ์ด์ ๋ณ๋ก ๋ฑ๋ก๋์ด์๋ VCAP_SERVICES ํ๊ฒฝ์ค์ ์ ๋ณด๋ฅผ ์ฝ์ด๋ค์ฌ ์ ๋ณด๋ฅผ ํ๋ ํ ์ ์๋ค.
ํ์ผ/ํด๋ | ๋ชฉ์ |
./lib/vcap.rb | ๊ฐ๋ฐฉํ ํ๋ซํผ์ ์ ํ๋ฆฌ์ผ์ด์ ๋ณ VCAP_SERVICES ํ๊ฒฝ์ ๋ณด์์ ์๋น์ค๋ณ ์ ์์ ๋ณด๋ฅผ ์ฝ์ด์ค๋ ํด๋์ค |
- ๊ฐ๋ฐฉํ ํ๋ซํผ์ ์ ํ๋ฆฌ์ผ์ด์ ํ๊ฒฝ์ ๋ณด
- ์๋น์ค๋ฅผ ๋ฐ์ธ๋ฉํ๋ฉด JSON ํํ๋ก ํ๊ฒฝ์ค์ ์ ๋ณด๊ฐ ์ ํ๋ฆฌ์ผ์ด์ ๋ณ๋ก ๋ฑ๋ก๋๋ค.
{
"VCAP_SERVICES": {
"p-mysql": [
{
"credentials": {
"hostname": "10.30.40.63",
"jdbcUrl": "jdbc:mysql://10.30.40.63:3306/cf_ea68784e_3de6_439d_afc1_d51b4e95627b?user=ZwCFnQRiT3KANqHZ\u0026password=qs7oqi4nSvWq6UQa",
"name": "cf_ea68784e_3de6_439d_afc1_d51b4e95627b",
"password": "qs7oqi4nSvWq6UQa",
"port": 3306,
"uri": "mysql://ZwCFnQRiT3KANqHZ:qs7oqi4nSvWq6UQa@10.30.40.63:3306/cf_ea68784e_3de6_439d_afc1_d51b4e95627b?reconnect=true",
"username": "ZwCFnQRiT3KANqHZ"
},
"label": "p-mysql",
"name": "sample-mysql-instance",
"plan": "100mb",
"tags": [
"mysql"
]
}
],
...(์ดํ ์๋ต)...
- ./lib/vcap.rb ํ์ผ ์์ฑ
- ๊ฐ๋ฐฉํ ํ๋ซํผ์ ์ ํ๋ฆฌ์ผ์ด์ ๋ณ VCAP_SERVICES ํ๊ฒฝ์ ๋ณด์์ ์๋น์ค๋ณ ์ ์์ ๋ณด๋ฅผ ์ฝ์ด์ค๋ ํด๋์ค
# cf-app-utils ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ฌ์ฉ
require 'cf-app-utils'
module VcapService
class Vcap
# ํด๋์ค ์ด๊ธฐํ ๋ฉ์๋
def initialize
end
def serviceInfo(service) #VCAP_SERVICES ์ ๋ณด ์กฐํ ๋ฉ์๋
#VCAP_SERVICES์ ๋ฑ๋ก๋ ์๋น์ค์ label ์ ๋ณด๋ฅผ ๊ธฐ์ค์ผ๋ก ์กฐํํ์ฌ ์ ๋ณด๋ฅผ ๋ฐํ
CF::App::Credentials.find_by_service_label(service)
end
end
end
- cf-app-utils ๋ฅผ ์ฌ์ฉํ์ง ์์๊ฒฝ์ฐ
# cf-app-utils์ ์ฌ์ฉํ์ง ์๊ณ ์ง์ ํ๊ฒฝ ๋ณ์์ ์ ๊ทผํ์ฌ Jsonํํ๋ก ์ ๋ณด๋ฅผ ์ฝ์ด์ฌ์ ์๋ค.
vcap_services = JSON.parse(ENV['VCAP_SERVICES'])
ํ์ผ/ํด๋ | ๋ชฉ์ |
./lib/mysql_service.rb | Vcap ํด๋์ค๋ฅผ ์์ํ์ฌ Connection์ ์์ฑํ๋ ํด๋์ค |
./app/controllers/orgs_chart_mysql_controller.rb | ์๋น์ค Connection ํด๋์ค ํธ์ถํ์ฌ ์ฌ์ฉํ๋ ์ปจํธ๋กค๋ฌ ํด๋์ค |
- ./lib/mysql_service.rb
- Vcap ํด๋์ค๋ฅผ ์์ํ์ฌ Mysql Connection์ ์์ฑํ๋ ํด๋์ค
require 'vcap'
module Connector
class MysqlService < VcapService::Vcap
def initialize
super()
end
def connector
credentials = serviceInfo('p-mysql') # โp-mysqlโ ์๋น์ค credentials ์กฐํ
Mysql2::Client.new(:host => credentials['hostname'],
:username => credentials['username'],
:password => credentials['password'],
:database => credentials['name'])
end
end
end
- ./app/controllers/orgs_chart_mysql_controller.rb ์๋น์ค Connection ํด๋์ค ํธ์ถ
# encoding: UTF-8 # Encoding ์ง์ (ํ๊ธ์ง์)
require 'mysql_service' # mysql_service ํด๋์ค ์ถ๊ฐ (๊ฐ ์๋น์ค๋ณ ํด๋์ค ์ถ๊ฐ๋ถ๋ถ)
class OrgChartMysqlController < ApplicationController
before_action :db_connection # ์ ์ฒ๋ฆฌ ๋ฉ์๋ ํธ์ถ(DB ์ ์)
before_action :set_param, only: [:index]
before_action :set_org, only: [:index]
after_action :db_close # ํ์ฒ๋ฆฌ ๋ฉ์๋ ํธ์ถ (DB ๋ซ์)
# Org ๊ทธ๋ฃน ๋ชฉ๋ก ์กฐํ ๋ฉ์๋
def index
if @org == nil
render json: {error: 'request value wrong'}, status: 400
else
render json: {org: @org, groups: @client.query(@query.group_index(@param[:org_id]))}
end
end
# ๋ฉ์๋๊ฐ ํธ์ถ๋๊ธฐ์ ์๋น์ค ์ ์
def db_connection
@client = Connector::MysqlService.new.connector #์๋น์ค ์ฐ๋ ํด๋์ค๋ฅผ ํธ์ถํ์ฌ ์ ์์ ๋ณด๋ฅผ ํ๋ํ๊ณ ์ด๋ฅผ ํด๋์ค ๋ณ์๋ก ์ ์ธํ์๋ค.
@query = Connector::MysqlQuery.new
end
# ๋ฉ์๋ ํธ์ถ์ด ๋๋ํ ์๋น์ค ๋ซ์
def db_close
@client.close
end
# Param ์ฒ๋ฆฌ ๋ฉ์๋
def set_param
@param = {:org_id => params[:org_id]}
end
# Org ์ ๋ณด ์กฐํ ๋ฉ์๋
def set_org
begin
@org = @client.query(@query.org_show(@param[:org_id])).first
rescue
@org = nil
end
end
end
โปํด๋น ํด๋์ค๋ ์ํ ์์ ์ด๋ฉฐ ์๋น์ค์ ์ ์์ ๋ณด์ ํ๋ ๋ฐ ํ์ฉ ๋ฐฉ๋ฒ์ ์ ํ๋ฆฌ์ผ์ด์ ์ ๊ตฌ์กฐ๋ฐ ํน์ฑ์ ๋ง๊ฒ ์ฌ์ฉ ํ ์ ์๋ค.
ํ์ผ/ํด๋ | ๋ชฉ์ |
./lib/cubrid_service.rb | Vcap ํด๋์ค๋ฅผ ์์ํ์ฌ Connection์ ์์ฑํ๋ ํด๋์ค |
./app/controllers/orgs_chart_cubrid_controller.rb | ์๋น์ค Connection ํด๋์ค ํธ์ถํ์ฌ ์ฌ์ฉํ๋ ์ปจํธ๋กค๋ฌ ํด๋์ค |
- ./lib/cubrid_service.rb
- Vcap ํด๋์ค๋ฅผ ์์ํ์ฌ Cubrid Connection์ ์์ฑํ๋ ํด๋์ค
require 'vcap'
module Connector
class CubridService < VcapService::Vcap
def initialize
super()
end
def connector
credentials = serviceInfo('CubridDB') # โCubridDBโ ์๋น์ค credentials ์กฐํ
Cubrid.connect(credentials['name'],
credentials['hostname'],
33000,
credentials['username'],
credentials['password'])
end
end
end
- ./app/controllers/orgs_chart_cubrid_controller.rb ์๋น์ค Connection ํด๋์ค ํธ์ถ
# encoding: UTF-8 # Encoding ์ง์ (ํ๊ธ์ง์)
require 'cubrid_service' # cubrid_service ํด๋์ค ์ถ๊ฐ (๊ฐ ์๋น์ค๋ณ ํด๋์ค ์ถ๊ฐ๋ถ๋ถ)
class OrgChartMysqlController < ApplicationController
before_action :db_connection # ์ ์ฒ๋ฆฌ ๋ฉ์๋ ํธ์ถ(DB ์ ์)
before_action :set_param, only: [:index]
before_action :set_org, only: [:index]
after_action :db_close # ํ์ฒ๋ฆฌ ๋ฉ์๋ ํธ์ถ (DB ๋ซ์)
# Org ๊ทธ๋ฃน ๋ชฉ๋ก ์กฐํ ๋ฉ์๋
def index
if @org == nil
render json: {error: 'request value wrong'}, status: 400
else
result = @client.query(@query.group_index(@param[:org_id]))
groups = []
while rs = result.fetch_hash
rs['label'] = rs['label'].to_s.force_encoding('UTF-8')
rs['desc'] = rs['desc'].to_s.force_encoding('UTF-8')
rs['thumb_img_name'] = rs['url'].to_s.force_encoding('UTF-8')
rs['thumb_img_path'] = rs['url'].to_s.force_encoding('UTF-8')
rs['url'] = rs['url'].to_s.force_encoding('UTF-8')
groups.push(rs)
end
render json: {org: @org, groups: groups}
end end
# ๋ฉ์๋๊ฐ ํธ์ถ๋๊ธฐ์ ์๋น์ค ์ ์
def db_connection
@client = Connector::CubridService.new.connector #์๋น์ค ์ฐ๋ ํด๋์ค๋ฅผ ํธ์ถํ์ฌ ์ ์์ ๋ณด๋ฅผ ํ๋ํ๊ณ ์ด๋ฅผ ํด๋์ค ๋ณ์๋ก ์ ์ธํ์๋ค.
@query = Connector::MysqlQuery.new
end
# ๋ฉ์๋ ํธ์ถ์ด ๋๋ํ ์๋น์ค ๋ซ์
def db_close
@client.close
end
# Param ์ฒ๋ฆฌ ๋ฉ์๋
def set_param
@param = {:org_id => params[:org_id]}
end
# Org ์ ๋ณด ์กฐํ ๋ฉ์๋
def set_org
begin
@org = @client.query(@query.org_show(@param[:org_id])).first
rescue
@org = nil
end
end
end
โปํด๋น ํด๋์ค๋ ์ํ ์์ ์ด๋ฉฐ ์๋น์ค์ ์ ์์ ๋ณด์ ํ๋ ๋ฐ ํ์ฉ ๋ฐฉ๋ฒ์ ์ ํ๋ฆฌ์ผ์ด์ ์ ๊ตฌ์กฐ๋ฐ ํน์ฑ์ ๋ง๊ฒ ์ฌ์ฉ ํ ์ ์๋ค.
ํ์ผ/ํด๋ | ๋ชฉ์ |
./lib/mongo_service.rb | Vcap ํด๋์ค๋ฅผ ์์ํ์ฌ Connection์ ์์ฑํ๋ ํด๋์ค |
./app/controllers/orgs_chart_mongo_controller.rb | ์๋น์ค Connection ํด๋์ค ํธ์ถํ์ฌ ์ฌ์ฉํ๋ ์ปจํธ๋กค๋ฌ ํด๋์ค |
- ./lib/mongo_service.rb
- Vcap ํด๋์ค๋ฅผ ์์ํ์ฌ MongoDB Connection์ ์์ฑํ๋ ํด๋์ค
require 'vcap'
module Connector
class MongoService < VcapService::Vcap
def initialize
super()
end
def connector
credentials = serviceInfo('Mongo-DB') # โMongo-DBโ ์๋น์ค credentials ์กฐํ
Mongo::Client.new(credentials['hosts'],
:database => credentials['name'],
:user => credentials['username'],
:password => credentials['password'],
:connect => :sharded)
end
end
end
- ./app/controllers/orgs_chart_mongo_controller.rb ์๋น์ค Connection ํด๋์ค ํธ์ถ
# encoding: UTF-8 # Encoding ์ง์ (ํ๊ธ์ง์)
require โmongo_serviceโ # mongo_service ํด๋์ค ์ถ๊ฐ (๊ฐ ์๋น์ค๋ณ ํด๋์ค ์ถ๊ฐ๋ถ๋ถ)
class OrgChartMysqlController < ApplicationController
before_action :db_connection # ์ ์ฒ๋ฆฌ ๋ฉ์๋ ํธ์ถ(DB ์ ์)
before_action :set_param, only: [:index]
before_action :set_org, only: [:index]
# Org ๊ทธ๋ฃน ๋ชฉ๋ก ์กฐํ ๋ฉ์๋
def index
if @org == nil
render json: {error: 'request value wrong'}, status: 400
else
result = @client[:Groups].find(:orgId => BSON::ObjectId(@param[:orgId])).sort({ _id: -1 } )
groups=[]
result.each do |rs|
rs['created'] = Date.strptime(rs['created'].as_json['t'].to_s,'%s').strftime('%F')
rs['modified'] = Date.strptime(rs['modified'].as_json['t'].to_s,'%s').strftime('%F')
rs_new = {'id' => rs.delete('_id').to_s,
'org_id' => rs.delete('orgId').to_s,
'parent_id' => rs.delete('parentId').to_s,
'label' => rs.delete('label').to_s,
'desc' => rs.delete('desc').to_s,
'thumb_img_name' => rs.delete('thumbImgName').to_s,
'thumb_img_path' => rs.delete('thumbImgPath').to_s,
'url' => rs.delete('url').to_s,
'created' => rs.delete('created').to_s,
'modified' => rs.delete('modified').to_s
}.merge(rs)
groups.push(rs_new)
end
render json: {org: @org, groups: groups}
end
end
# ๋ฉ์๋๊ฐ ํธ์ถ๋๊ธฐ์ ์๋น์ค ์ ์
def db_connection
@client = Connector:: MongoService.new.connector #์๋น์ค ์ฐ๋ ํด๋์ค๋ฅผ ํธ์ถํ์ฌ ์ ์์ ๋ณด๋ฅผ ํ๋ํ๊ณ ์ด๋ฅผ ํด๋์ค ๋ณ์๋ก ์ ์ธํ์๋ค.
end
# Param ์ฒ๋ฆฌ ๋ฉ์๋
def set_param
@param = {:orgId => params[:org_id]}
end
# Org ์ ๋ณด ์กฐํ ๋ฉ์๋
def set_org
begin
#@org = @client[:Orgs].find(:_id => BSON::ObjectId(@param[:orgId])).first
org_tmp = @client[:Orgs].find(:_id => BSON::ObjectId(@param[:orgId])).first
org_tmp['created'] = Date.strptime(org_tmp['created'].as_json['t'].to_s,'%s').strftime('%F')
org_tmp['modified'] = Date.strptime(org_tmp['modified'].as_json['t'].to_s,'%s').strftime('%F')
@org = {'id' => org_tmp.delete('_id').to_s}.merge(org_tmp)
rescue
@org = nil
End
end
end
โปํด๋น ํด๋์ค๋ ์ํ ์์ ์ด๋ฉฐ ์๋น์ค์ ์ ์์ ๋ณด์ ํ๋ ๋ฐ ํ์ฉ ๋ฐฉ๋ฒ์ ์ ํ๋ฆฌ์ผ์ด์ ์ ๊ตฌ์กฐ๋ฐ ํน์ฑ์ ๋ง๊ฒ ์ฌ์ฉ ํ ์ ์๋ค.
ํ์ผ/ํด๋ | ๋ชฉ์ |
./lib/redis_service.rb | Vcap ํด๋์ค๋ฅผ ์์ํ์ฌ Connection์ ์์ฑํ๋ ํด๋์ค |
./app/controllers/login_controller.rb | ์๋น์ค Connection ํด๋์ค ํธ์ถํ์ฌ ์ฌ์ฉํ๋ ์ปจํธ๋กค๋ฌ ํด๋์ค |
- ./lib/rddis_service.rb
- Vcap ํด๋์ค๋ฅผ ์์ํ์ฌ Redis Connection์ ์์ฑํ๋ ํด๋์ค
require 'vcap'
module Connector
class RedisService < VcapService::Vcap
def initialize
super()
end
def connector
credentials = serviceInfo('redis-sb') # โredis-sbโ ์๋น์ค credentials ์กฐํ
Redis.new(:host => credentials['host'],
:port => credentials['port'],
:password => credentials['password'])
end
end
end
- ./app/controllers/login_controller.rb ์๋น์ค Connection ํด๋์ค ํธ์ถ
# encoding: UTF-8 # Encoding ์ง์ (ํ๊ธ์ง์)
require โredis_serviceโ # redis_service ํด๋์ค ์ถ๊ฐ (๊ฐ ์๋น์ค๋ณ ํด๋์ค ์ถ๊ฐ๋ถ๋ถ)
class LoginController < ApplicationController
#์ ์ฒ๋ฆฌ ๋ฉ์๋
before_action :redis_connection # Redis ์๋ฒ ์ ์
def login
id = params[:id]
pwd = params[:password]
if id == nil || id =='' || pwd == nil || pwd == ''
render json: {error: 'request value wrong'}, status: 400
elsif (id.eql? 'admin') && (pwd.eql? 'admin')
key = SecureRandom.uuid.to_s
@redis.set(key, "admin")
cookies['login_cookie'] = key
render json: {}
else
render json: {error: 'not authz'}, status: 401
end
end
def logout
key = cookies['login_cookie'].to_s
p key
@redis.del(key)
render json: {}
end
def redis_connection
@redis = Connector::RedisService.new.connector #์๋น์ค ์ฐ๋ ํด๋์ค๋ฅผ ํธ์ถํ์ฌ ์ ์์ ๋ณด๋ฅผ ํ๋ํ๊ณ ์ด๋ฅผ ํด๋์ค ๋ณ์๋ก ์ ์ธํ์๋ค.
end
end
โปํด๋น ํด๋์ค๋ ์ํ ์์ ์ด๋ฉฐ ์๋น์ค์ ์ ์์ ๋ณด์ ํ๋ ๋ฐ ํ์ฉ ๋ฐฉ๋ฒ์ ์ ํ๋ฆฌ์ผ์ด์ ์ ๊ตฌ์กฐ๋ฐ ํน์ฑ์ ๋ง๊ฒ ์ฌ์ฉ ํ ์ ์๋ค.
ํ์ผ/ํด๋ | ๋ชฉ์ |
./lib/rabbitmq_service.rb | Vcap ํด๋์ค๋ฅผ ์์ํ์ฌ Connection์ ์์ฑํ๋ ํด๋์ค |
./app/controllers/status_controller.rb | ์๋น์ค Connection ํด๋์ค ํธ์ถํ์ฌ ์ฌ์ฉํ๋ ์ปจํธ๋กค๋ฌ ํด๋์ค |
- ./lib/rabbitmq_service.rb
- Vcap ํด๋์ค๋ฅผ ์์ํ์ฌ RabbitMQ Connection์ ์์ฑํ๋ ํด๋์ค
require 'vcap'
module Connector
class RabbitmqService < VcapService::Vcap
def initialize
super()
end
def connector
credentials = serviceInfo('p-rabbitmq') # โp-rabbitmqlโ ์๋น์ค credentials ์กฐํ
protocols = credentials['protocols']
amqp_credentials = protocols['amqp+ssl'] || protocols['amqp']
Bunny.new(
:host => amqp_credentials['hosts'].sample,
:port => amqp_credentials['port'],
:vhost => amqp_credentials['vhost'],
:user => amqp_credentials['username'],
:pass => amqp_credentials['password'],
tls_ca_certificates: %w(./tls/ca_certificate.pem),
verify_peer: false)
end
end
end
โปBunny 2.2.x ์ดํ ๋๋ผ์ด๋ฒ ๋ฒ์ ์์๋ TLS/SSL CA์ ๊ฒฝ๋ก๋ฅผ ์ง์ ํ์ง ์์ผ๋ฉด ๊ธฐ๋ณธ์ผ๋ก ์ค์ ๋ ๊ฒฝ๋ก๋ฅผ ์ฌ์ฉํ๋ค. Ex) Ubuntu/Debian : /etc/ssl/certs/ca-certificates.crt
- ./app/controllers/status_controller.rb ์๋น์ค Connection ํด๋์ค ํธ์ถ
# encoding: UTF-8 # Encoding ์ง์ (ํ๊ธ์ง์)
require โrabbitmq_serviceโ # rabbitmq_service ํด๋์ค ์ถ๊ฐ (๊ฐ ์๋น์ค๋ณ ํด๋์ค ์ถ๊ฐ๋ถ๋ถ)
class StatusController < ApplicationController
before_action :rabbit_ connection # RabbitMQ ์๋ฒ ์ ์
def status
if ENV['RAILS_ENV'].to_s != "development" && !ENV['RAILS_ENV'].to_s != "test"
@conn.start
orgId = params[:org_id]
dbType = params[:db_type]
queue_name = dbType +'_'+ orgId.to_s
@channel ||= @conn.create_channel
@queue ||= @channel.queue(queue_name, :auto_delete => true)
if @conn.queue_exists?(queue_name)
delivery_info, metadata, payload = @queue.pop
else
delivery_info, metadata, payload = nil
end
@conn.stop
end
if payload == nil || payload.length == 0
payload = 'NO_CHANGES'
end
render json: {:status => payload}
end
def rabbit_connection
@conn = Connector::RabbitmqService.new.connector #์๋น์ค ์ฐ๋ ํด๋์ค๋ฅผ ํธ์ถํ์ฌ ์ ์์ ๋ณด๋ฅผ ํ๋ํ๊ณ ์ด๋ฅผ ํด๋์ค ๋ณ์๋ก ์ ์ธํ์๋ค.
end
end
โปํด๋น ํด๋์ค๋ ์ํ ์์ ์ด๋ฉฐ ์๋น์ค์ ์ ์์ ๋ณด์ ํ๋ ๋ฐ ํ์ฉ ๋ฐฉ๋ฒ์ ์ ํ๋ฆฌ์ผ์ด์ ์ ๊ตฌ์กฐ๋ฐ ํน์ฑ์ ๋ง๊ฒ ์ฌ์ฉ ํ ์ ์๋ค.
ํ์ผ/ํด๋ | ๋ชฉ์ |
./lib/glusterfs_service.rb | Vcap ํด๋์ค๋ฅผ ์์ํ์ฌ Connection์ ์์ฑํ๋ ํด๋์ค |
./app/controllers/upload_controller.rb | ์๋น์ค Connection ํด๋์ค ํธ์ถํ์ฌ ์ฌ์ฉํ๋ ์ปจํธ๋กค๋ฌ ํด๋์ค |
- ./lib/glusterfs_service.rb
- Vcap ํด๋์ค๋ฅผ ์์ํ์ฌ GlusterFS Connection์ ์์ฑํ๋ ํด๋์ค
require 'vcap'
module Connector
class Glusterfs < VcapService::Vcap
def initialize
super()
end
def connector
credentials = serviceInfo('glusterfs') # โglusterfsโ ์๋น์ค credentials ์กฐํ
Fog::Storage.new({
:provider => 'OpenStack',
:openstack_username => credentials['username'],
:openstack_api_key => credentials['password'],
:openstack_auth_url => credentials['auth_url']+'/tokens'
})
end
end
end
- ./app/controllers/upload_controller.rb ์๋น์ค Connection ํด๋์ค ํธ์ถ
# encoding: UTF-8 # Encoding ์ง์ (ํ๊ธ์ง์)
require โglusterfs_serviceโ # glusterfs_service ํด๋์ค ์ถ๊ฐ (๊ฐ ์๋น์ค๋ณ ํด๋์ค ์ถ๊ฐ๋ถ๋ถ)
class UploadController < ApplicationController
before_filter :authenticate # ๋ฉ์๋๋ฅผ ํธ์ถํ๊ธฐ์ ์ธ์ฆ์ฌ๋ถ๋ฅผ ํ์ธํฉ๋๋ค.
before_action :gs_connection # ํ์ผ ์
๋ก๋๋ฅผ ์ํ Swift ์ธ์ฆ์ ๋ณด๋ฅผ ํ๋ํฉ๋๋ค.
# ํ์ผ์ ์
๋ก๋ ํฉ๋๋ค.
def upload
@img = params[:file]
if @img == nil || @img == ''
render json: {error: 'request value wrong'}, status: 400
else
cont = @service.directories.get "ruby-thumb"
if cont == nil
cont = @service.directories.create :key => 'ruby-thumb', :public => true
cont.save
end
file = cont.files.create :key => DateTime.now.strftime('%Q')+"_" + @img.original_filename, :body => File.open(@img.tempfile.path)
render json: {thumb_img_path: file.public_url}
end
end
def gs_connection
@service = Connector::Glusterfs.new.connector #์๋น์ค ์ฐ๋ ํด๋์ค๋ฅผ ํธ์ถํ์ฌ ์ ์์ ๋ณด๋ฅผ ํ๋ํ๊ณ ์ด๋ฅผ ํด๋์ค ๋ณ์๋ก ์ ์ธํ์๋ค.
end
end
โปํด๋น ํด๋์ค๋ ์ํ ์์ ์ด๋ฉฐ ์๋น์ค์ ์ ์์ ๋ณด์ ํ๋ ๋ฐ ํ์ฉ ๋ฐฉ๋ฒ์ ์ ํ๋ฆฌ์ผ์ด์ ์ ๊ตฌ์กฐ๋ฐ ํน์ฑ์ ๋ง๊ฒ ์ฌ์ฉ ํ ์ ์๋ค.
๊ฐ๋ฐ ์๋ฃ๋ ์ ํ๋ฆฌ์ผ์ด์ ์ ๊ฐ๋ฐฉํ ํ๋ซํผ์ ๋ฐฐํฌํ๋ ๋ฐฉ๋ฒ์ ์ค๋ช ํ๋ค.
ํ์ผ/ํด๋ | ๋ชฉ์ |
./manifest.yml | ๊ฐ๋ฐฉํ ํ๋ซํผ ๋ฐฐํฌ ํ๊ฒฝ ์ค์ ํ์ผ |
- ./manifest.yml ์์ฑ
- cf push ๋ช ๋ น์ ํ์ฌ ๋๋ ํ ๋ฆฌ์ manifest.yml์ ์ฐธ์กฐํ์ฌ ๋ฐฐํฌ๊ฐ ์งํ๋๋ค.
---
applications:
- name: ruby-sample-app # ์ ํ๋ฆฌ์ผ์ด์
์ด๋ฆ
memory: 512M # ์ ํ๋ฆฌ์ผ์ด์
๋ฉ๋ชจ๋ฆฌ ์ฌ์ด์ฆ
instances: 1 # ์ ํ๋ฆฌ์ผ์ด์
์ธ์คํด์ค ๊ฐ์
path: . # ์ ํ๋ฆฌ์ผ์ด์
์์น
command: bundle exec rails server -p $PORT # ์ ํ๋ฆฌ์ผ์ด์
๋ฐฐํฌ ํ ์คํ ๋ช
๋ น์ด
โป์ ํ๋ฆฌ์ผ์ด์ ์คํ ์ด์ง์ ํ ๋ฌ ๋ฐ์ ํฌํธ๊ฐ ํ๊ฒฝ๋ณ์๋ก ๋ฑ๋ก๋์ด์๋ค. ์ด $PORT๋ ์ ํ๋ฆฌ์ผ์ด์ ์ ์ํ ์ฒดํฌ์๋ ์ฌ์ฉ๋๋ฏ๋ก ์์ ๊ฐ์ด ํฌํธ๋ฅผ ์ง์ ํ ๊ฒ์ ๊ถ์ฅํ๋ค.
- ๊ฐ๋ฐฉํ ํ๋ซํผ ๋ก๊ทธ์ธ
$ cf api https://api.cf.open-paas.com # ๊ฐ๋ฐฉํ ํ๋ซํผ TARGET ์ง์
#cf api [๊ฐ๋ฐฉํ ํ๋ซํผ API ์ฃผ์] : ๊ฐ๋ฐฉํ ํ๋ซํผ API ์ฃผ์๋ฅผ ์ง์ ํ๋ค.
$ cf login -u testUser -o sample_test -s sample_space # ๋ก๊ทธ์ธ ์์ฒญ
#cf login โu [์ฌ์ฉ์ ์ด๋ฆ] โo [์กฐ์ง๋ช
] โs [์คํ์ด์ค๋ช
] : ์กฐ์ง, ์คํ์ด์ค๊ฐ ์์๊ฒฝ์ฐ ์์ฑํ์
API endpoint: https://api.cf.open-paas.com
Password>
Authenticating...
OK
Targeted org sample_test
Targeted space sample_space
API endpoint: https://api.cf.open-paas.com (API version: 2.29.0)
User: testUser
Org: sample_test
Space: sample_space
$
- ๊ฐ๋ฐฉํ ํ๋ซํผ ์๋น์ค ์์ฑ
$ cf marketplace # ๋ง์ผํ๋ ์ด์ค ๋ชฉ๋ก ์์ฒญ
service plans description
p-mysql 100mb, 1gb MySQL databases on demand
p-rabbitmq standard RabbitMQ is a robust โฆ..
redis-sb shared-vm, dedicated-vm Redis service to provide a โฆโฆ
$ cf create-service p-mysql 100mb sample-mysql-instance # ์๋น์ค ์์ฑ
#cf create-service [์๋น์ค๋ช
] [ํ๋๋ช
] [์์ฑํ ์๋น์ค๋ช
]
$ cf services # ์๋น์ค ๋ชฉ๋ก ์กฐํ
name service plan bound apps lastโฆ
sample-mysql-instance p-mysql 100mb node-sample, p.... โฆ
sample-rabbitmq-instance p-rabbitmq standard python-sample-.... โฆ
sample-redis-instance redis-sb shared-vm python-sample-.... โฆ
- ๊ฐ๋ฐฉํ ํ๋ซํผ ์ ํ๋ฆฌ์ผ์ด์ ์ ์๋น์ค ๋ฐ์ธ๋ฉ ๋ฐ ์ ํ๋ฆฌ์ผ์ด์ ์์
$ cf push -b https://github.com/cloudfoundry/ruby-buildpack.git#v1.3.1 --no-start
# ์ ํ๋ฆฌ์ผ์ด์
์
๋ก๋๋ง ์คํํ๊ณ ์์ํ์ง๋ ์๋๋ค.
# ์ต๊ทผ Ruby ๋น๋ํฉ(1.3.1์ดํ)์ Ruby 1.9.3์ ๊ธฐ๋ณธ์ ์ผ๋ก ์ง์ํ์ง ์๋๋ค. Ruby 1.9.3์ ์ง์ํ๋ ๋น๋ํฉ์ ์ง์ ํ์ฌ ๋ฐฐํฌํ๋ค. ๊ฐ ์ ํ๋ฆฌ์ผ์ด์
์ Ruby ๋ฒ์ ์ ๋ง๋ ๋น๋ํฉ์ ์ง์ ํ์ฌ ์ฌ์ฉํ์ฌ์ผ ํ๊ฑฐ๋ ๊ฐ๋ฐฉํ ํ๋ซํผ์์ ์ ๊ณตํ๋ ๊ธฐ๋ณธ ๋น๋ํฉ์ ์ฌ์ฉํ ๊ฒฝ์ฐ โb ์ต์
์ ์ ์ธ ํ์ฌ๋ ๋ฌด๋ฐฉํ๋ค.
# cf push โb [์ฌ์ฉ์ ๋น๋ํฉ URL] โno-start
$ cf services # ์๋น์ค ๋ชฉ๋ก ์กฐํ
name service plan bound apps lastโฆ
sample-mysql-instance p-mysql 100mb node-sample, p.... โฆ
sample-cubrid-instance CubridDB utf8 node-sample, p.... โฆ
sample-mongo-instance Mongo-DB default-plan node-sample, p.... โฆ
sample-rabbitmq-instance p-rabbitmq standard python-sample-.... โฆ
sample-redis-instance redis-sb shared-vm python-sample-.... โฆ
sample-glusterfs-instance glusterfs glusterfs-1000Mb glusterfs-samp.... โฆ
$ cf bind-service ruby-sample-app sample-mysql-instance # ์ ํ๋ฆฌ์ผ์ด์
์๋น์ค ๋ฐ์ธ๋ฉ
# cf bind-service [์ ํ๋ฆฌ์ผ์ด์
๋ช
] [์๋น์ค ๋ช
]
$ cf start ruby-sample-app # ์ ํ๋ฆฌ์ผ์ด์
์์
# cf start [์ ํ๋ฆฌ์ผ์ด์
๋ช
]
โป์ต์ ๋น๋ํฉ์ Ruby 1.9.3์ ์ง์ํ์ง ์๊ธฐ ๋๋ฌธ์ ruby-buildpack 1.3.1 ๋ฒ์ ์ ์ฌ์ฉํ์ฌ ๋ฐฐํฌ๋ฅผ ์งํํฉ๋๋ค. ๊ฐ๋ฐฉํ ํ๋ซํผ์์ ์ง์ํ๋ ๊ธฐ๋ณธ ๋น๋ํฉ์ ์ฌ์ฉํ ๊ฒฝ์ฐ โb ์ต์ ์ ์ ์ธ
โป์ ํ๋ฆฌ์ผ์ด์ ๋ฐฐํฌ์ ์ฐจ๋ฅผ ์๋์ฐ ๋จธ์ ์์ ์ํํ๋ ๊ฒฝ์ฐ(cf cli๋ฅผ ์๋์ฐ ๋จธ์ ์ ์ค์นํ์ฌ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ), ์ ํ๋ฆฌ์ผ์ด์ ์์('cf start')์ด ์ ๋๋ก ๋์ง ์์ ์ ์์ต๋๋ค. ์ด ๋๋ bin ํด๋๋ด์ 3๊ฐ์ ํ์ผ bundle, rake, rails๋ฅผ ์ ๋์ค์ฉ์ผ๋ก ๋ณํํ์ฌ 'cf push' ๋ถํฐ ๋ค์ ์งํํฉ๋๋ค. ํ์ผ ๋ณํ ์ ์ฐจ๋ ๋ค์์ ๋ฐ๋ฆ ๋๋ค.
-
์๋์ฐ ์ปค๋งจ๋ ์ฐฝ์ ์ด์ด ์ ํ๋ฆฌ์ผ์ด์ ํด๋๋ก ์ด๋ํฉ๋๋ค.
-
(๋ฐฉ๋ฒ1.) ๋ค์์ url์์ dos2unix๋ฅผ ๋ค์ด๋ก๋ ํ๊ณ ์์ถ์ ํด์ ํ์ฌ dos2unix.exeํ์ผ์ ์ํ ์ดํ๋ฆฌ์ผ์ด์ ์ bin ํด๋๋ก ์ด๋ํฉ๋๋ค.
http://sourceforge.net/projects/dos2unix/files/latest/download(๋ฐฉ๋ฒ2.) ์ํ ์ดํ๋ฆฌ์ผ์ด์ ์ 'git clone'ํ ์ฌ์ฉ์๋ ๋ค์์ ๋ช ๋ น์ด๋ฅผ ์ด์ฉํ์ฌ ์ ํ๋ฆฌ์ผ์ด์ ํด๋ ๋ด์ dos2unix ํ์ผ์ ํ์ผ๋ช ์ ๋ณ๊ฒฝํฉ๋๋ค. 'rename' ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํ ์ ์๋ค๋ฉด, 'ren' ๋ช ๋ น์ด๋ฅผ ๋์ ์ฌ์ฉํ๊ฑฐ๋ ์ง์ ํ์ผ๋ช ์ 'dos2unix.exe'๋ก ๋ณ๊ฒฝํ์ฌ๋ ๋ฌด๋ฐฉํฉ๋๋ค.
rename dos2unix dos2unix.exe
- ๋ค์ ๋ช ๋ น์ด๋ฅผ ์ด์ฉํ์ฌ bin ํด๋ ๋ด์ 3๊ฐ์ ํ์ผ์ ์ ๋์ค ํ์ผ๋ก ๋ณํํฉ๋๋ค.
dos2unix bin/bundle bin/rake bin/rails
โป ์๋์ฐ์ฆ Power Shell์์๋ ํด๋น ๋ช ๋ น์ด๊ฐ ์คํ๋์ง ์์ต๋๋ค. ๋ช ๋ น ํ๋กฌํํธ๋ฅผ ์ด์ฉํ๋ฉด ๋ช ๋ น์ด๋ฅผ ์คํ์ํฌ ์ ์์ต๋๋ค. ๋ณํ์ด ์ ์์ ์ผ๋ก ์๋ฃ๋๋ฉด ๋ค์๊ณผ ๊ฐ์ ํ๋ฉด์ ํ์ธํ ์ ์์ต๋๋ค.
- [4) ๊ฐ๋ฐฉํ ํ๋ซํผ ์ ํ๋ฆฌ์ผ์ด์ ์ ์๋น์ค ๋ฐ์ธ๋ฉ ๋ฐ ์ ํ๋ฆฌ์ผ์ด์ ์์] ์ ์ฐจ๋ฅผ ๋ค์ ์ํํฉ๋๋ค.
Rspec์ ์ด์ฉํ Ruby ์ ํ๋ฆฌ์ผ์ด์ ํ ์คํธ
- ํด๋ ๋ฐ ํ์ผ ์ ์
ํ์ผ/ํด๋ | ๋ชฉ์ |
Spec | rspec ํ ์คํธ ์ผ์ด์ค ๋ฃจ๋น ํ์ผ์ด ์กด์ฌ ํด๋ |
*_spec | rspec ํ ์คํธ ์ผ์ด์ค ๋ฃจ๋น ํ์ผ |
- ํ ์คํธ ์คํ
bundle exec rspec
โป์ ์์ ์ธ ํ ์คํธ ์งํ์ ์ํด์๋ ํด๋น ์๋น์ค์ ์ ์์ด ๊ฐ๋ฅํ์ฌ์ผ ํ๋ค.(ํ๋ก์, ํฐ๋๋ง ๋ฑ..)