「Gitlab + Jenkins環境構築のCookbookを作成」のGitlabとJenkinsのCookBook作成
・Gitlab
gitlab_url = node['gitlab']['url']
gitlab_rpm = node['gitlab']['rpm']
# openssh-server インストール
package "openssh-server" do
action :install
end
# postfix インストール
package "postfix" do
action :install
end
# gitlab インストール
remote_file "/tmp/#{gitlab_rpm}" do
source "#{gitlab_url}"
end
rpm_package "gitlab_rpm_package" do
action :install
provider Chef::Provider::Package::Rpm
source "/tmp/#{gitlab_rpm}"
end
# 設定ファイル修正
template "/etc/gitlab/gitlab.rb" do
mode 0755
source "gitlab.rb.erb"
variables(:external_url => node['gitlab']['external_url'])
end
# 起動
script "launch_gitlab" do
interpreter "bash"
user "root"
code <<-EOL
gitlab-ctl reconfigure
lokkit -s http -s ssh
gitlab-ctl start
EOL
end
※設定ファイルにはテンプレートを使用
・gitlab.rb.erb
# Change the external_url to the address your users will type in their browser
external_url '<%= @external_url %>'
・Attributes
#
# Cookbook Name:: gitlab
# Attributes:: default
default['gitlab']['url'] = 'https://downloads-packages.s3.amazonaws.com/centos-6.5/gitlab-7.0.0_omnibus-1.el6.x86_64.rpm'
default['gitlab']['rpm'] = 'gitlab-7.0.0_omnibus-1.el6.x86_64.rpm'
default['gitlab']['external_url'] = 'http://localhost'
・Jenkins
# Recipe:: default
#
# Copyright 2015, YOUR_COMPANY_NAME
#
# All rights reserved - Do Not Redistribute
#
jenkins_yum = node['jenkins']['yum']
jenkins_url = node['jenkins']['url']
jenkins_key = node['jenkins']['key']
# リポジトリの追加
script "add_repo" do
interpreter "bash"
user "root"
code <<-EOL
wget -O "#{jenkins_yum}" "#{jenkins_url}"
rpm --import "#{jenkins_key}"
EOL
end
# インストール
package "jenkins" do
action :install
end
# 環境変数の設定
template "/etc/sysconfig/jenkins" do
mode 0600
source "jenkins.erb"
variables(:port => node['jenkins']['port'])
end
# 起動
service "jenkins" do
action [ :enable, :start ]
end
# iptablesの無効化
service "iptables" do
action [ :disable, :stop]
end
・Attributes
#
# Cookbook Name:: jenkins
# Attributes:: default
default['jenkins']['port'] = 8081
default['jenkins']['yum'] = '/etc/yum.repos.d/jenkins.repo'
default['jenkins']['url'] = 'http://pkg.jenkins-ci.org/redhat/jenkins.repo'
default['jenkins']['key'] = 'http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key'
0 件のコメント:
コメントを投稿