集成omnibus-ctl+ chef 制作一个可配置的软件包
前边有写过使用omnibus-ctl 制作软件包的,但是当时没有集成chef,只有一个空壳子,实际上omnibus-ctl 已经内置
了对于chef 的操作(但是我们还需要在添加一个依赖),以下简单说明两者如何进行集成
demo 是一个类似gitlab-ctl 的操作,但是只有一个简单的cookbook,实际上可以自己进行扩展
项目准备
- 项目初始化
omnibus new gitlab
- 项目结构
添加了关于cookbook 操作之后的
├── Berksfile
├── Gemfile
├── README.md
├── config
│ ├── projects
│ │ └── gitlab.rb
│ ├── software
│ │ ├── chef-gem.rb
│ │ ├── chef-zero.rb
│ │ ├── gitlab-cookbooks.rb
│ │ ├── gitlab-ctl.rb
│ │ ├── gitlab-zlib.rb
│ │ └── preparation.rb
│ └── templates
│ └── gitlab-cookbooks
│ └── dna.json.erb
├── files
│ ├── gitlab-cookbooks
│ │ ├── dalong
│ │ │ ├── CHANGELOG.md
│ │ │ ├── Gemfile
│ │ │ ├── Gemfile.lock
│ │ │ ├── LICENSE
│ │ │ ├── README.md
│ │ │ ├── attributes
│ │ │ │ └── userlogin.rb
│ │ │ ├── chefignore
│ │ │ ├── files
│ │ │ │ └── dalong
│ │ │ ├── kitchen.yml
│ │ │ ├── metadata.rb
│ │ │ ├── recipes
│ │ │ │ ├── dalong.rb
│ │ │ │ ├── default.rb
│ │ │ │ └── userlogin.rb
│ │ │ ├── spec
│ │ │ │ ├── spec_helper.rb
│ │ │ │ └── unit
│ │ │ │ └── recipes
│ │ │ │ ├── dalong_spec.rb
│ │ │ │ ├── default_spec.rb
│ │ │ │ └── userlogin_spec.rb
│ │ │ ├── templates
│ │ │ │ └── userlogin.erb
│ │ │ └── test
│ │ │ └── integration
│ │ │ └── default
│ │ │ ├── dalong_test.rb
│ │ │ ├── default_test.rb
│ │ │ └── userlogin_test.rb
│ │ ├── dna.json
│ │ └── solo.rb
│ └── gitlab-ctl-commands
│ └── config.rb
├── omnibus.rb
└── package-scripts
└── gitlab
├── postinst
├── postrm
├── preinst
└── prerm
- 简单说明
以上就是一个普通的使用omnibus 创建的包项目,同时添加了omnibus-ctl 对于cookbbok 操作的配置以及集成omnibus-ctl
代码说明
详细代码参考:https://github.com/rongfengliang/omnibus-ctl-demo
- config/project/gitlab.rb
主要是关于项目的说明以及依赖的处理
#
# Copyright 2019 YOUR NAME
#
# All Rights Reserved.
#
name "gitlab"
maintainer "rongfengliang"
homepage "https://github.com/rongfengliang"
# Defaults to C:/my on Windows
# and /opt/my on all other platforms
install_dir "#{default_root}/#{name}"
build_version Omnibus::BuildVersion.semver
build_iteration 1
# Creates required build directories
dependency "preparation"
dependency "gitlab-ctl"
dependency 'gitlab-cookbooks'
dependency 'chef-zero'
dependency 'chef-gem'
# my dependencies/components
# dependency "somedep"
exclude "**/.git"
exclude "**/bundler/git"
- software 定义
这个分了ctl的以及关于cookbook ,还有就是chef 操作的(omnibus-ctl的命令依赖)
config/software/gitlab-ctl.rb:
name "gitlab-ctl"
dependency "omnibus-ctl"
source :path => File.expand_path("files/gitlab-ctl-commands", RbConfig::CONFIG['project_root'])
build do
block do
open("#{install_dir}/embedded/bin/gitlab-ctl", "w") do |file|
file.print <<-EOH
#!/bin/bash
# Ruby environment if gitlab-ctl is called from a Ruby script.
for ruby_env_var in RUBYOPT \\
BUNDLE_BIN_PATH \\
BUNDLE_GEMFILE \\
GEM_PATH \\
GEM_HOME
do
unset $ruby_env_var
done
#{install_dir}/embedded/bin/omnibus-ctl gitlab #{install_dir}/embedded/service/omnibus-ctl $@
EOH
end
end
command "chmod 755 #{install_dir}/embedded/bin/gitlab-ctl"
# additional omnibus-ctl commands
sync "#{project_dir}/", "#{install_dir}/embedded/service/omnibus-ctl/"
end
config/software/gitlab-cookbooks.rb:
#
# Copyright:: Copyright (c) 2012 Opscode, Inc.
# Copyright:: Copyright (c) 2014 GitLab.com
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
name 'gitlab-cookbooks'
license 'Apache-2.0'
source path: File.expand_path('files/gitlab-cookbooks', Omnibus::Config.project_root)
build do
cookbook_name = 'dalong::default'
command "mkdir -p #{install_dir}/embedded/cookbooks"
sync './', "#{install_dir}/embedded/cookbooks/"
erb dest: "#{install_dir}/embedded/cookbooks/dna.json",
source: 'dna.json.erb',
mode: 0644,
vars: { master_cookbook: cookbook_name }
end
config/software/chef-gem.rb:
#
# Copyright 2012-2014 Chef Software, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
name 'chef-gem'
# The version here should be in agreement with /Gemfile.lock so that our rspec
# testing stays consistent with the package contents.
default_version '14.13.11'
license 'Apache-2.0'
license_file 'LICENSE'
skip_transitive_dependency_licensing true
dependency 'ruby'
dependency 'rubygems'
dependency 'libffi'
dependency 'rb-readline'
build do
env = with_standard_compiler_flags(with_embedded_path)
gem 'install chef' \
" --version '#{version}'" \
" --bindir '#{install_dir}/embedded/bin'" \
' --no-document', env: env
end
config/software/chef-zero.rb(chef-client 实际上就是调用的这个,所以是一个比较重要的)
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
name 'chef-zero'
# The version here should be in agreement with /Gemfile.lock so that our rspec
# testing stays consistent with the package contents.
default_version '14.0.12'
license 'Apache-2.0'
license_file 'LICENSE'
skip_transitive_dependency_licensing true
dependency 'ruby'
dependency 'rubygems'
build do
env = with_standard_compiler_flags(with_embedded_path)
gem 'install chef-zero' \
" --version '#{version}'" \
" --bindir '#{install_dir}/embedded/bin'" \
' --no-document', env: env
end
- cookbook
编写了一个简单的cookbook,可以在执行reconfigure 的时候自动生成需要的文件
files/gitlab-cookbooks 目录,实际上就是一个简单的chef cookbook 项目,核心是
使用chef-client local 模式的配置solo.rb 以及dns.json(实际是用模版生成的)
solo.rb:
CURRENT_PATH = File.expand_path(File.dirname(__FILE__))
TIME = Time.now.to_i
LOG_PATH = '/var/log/gitlab/reconfigure'.freeze
Dir.exist?(LOG_PATH) || FileUtils.mkdir_p(LOG_PATH)
file_cache_path "#{CURRENT_PATH}/cache"
cookbook_path CURRENT_PATH
cache_path "#{CURRENT_PATH}/cache"
verbose_logging false
# Log to the reconfigure log
log_location "#{LOG_PATH}/#{TIME}.log"
log_level :info
dns.json:
{
"run_list": [ "recipe[dalong::default]" ]
}
构建&&运行效果
- 构建
bundle install --binstubs
bin/omnibus build gitlab
- 生成的rpm 包
├── gitlab-0.0.0+20190706121815-1.el7.x86_64.rpm
├── gitlab-0.0.0+20190706121815-1.el7.x86_64.rpm.metadata.json
└── version-manifest.json
- 安装rpm 包
yum install gitlab-0.0.0+20190706121815-1.el7.x86_64.rpm
已加载插件:fastestmirror
正在检查 gitlab-0.0.0+20190706121815-1.el7.x86_64.rpm: gitlab-0.0.0+20190706121815-1.el7.x86_64
gitlab-0.0.0+20190706121815-1.el7.x86_64.rpm 将被安装
正在解决依赖关系
--> 正在检查事务
---> 软件包 gitlab.x86_64.0.0.0.0+20190706121815-1.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
=======================================================================================================================
Package 架构 版本 源 大小
=======================================================================================================================
正在安装:
gitlab x86_64 0.0.0+20190706121815-1.el7 /gitlab-0.0.0+20190706121815-1.el7.x86_64 82 M
事务概要
=======================================================================================================================
安装 1 软件包
总计:82 M
安装大小:82 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
You're about to install gitlab!
正在安装 : gitlab-0.0.0+20190706121815-1.el7.x86_64 1/1
Thank you for installing gitlab! please run gitlab-ctl reconfigure
验证中 : gitlab-0.0.0+20190706121815-1.el7.x86_64 1/1
已安装:
gitlab.x86_64 0:0.0.0+20190706121815-1.el7
完毕!
- 配置path
因为是测试,就没有配置使用软连接配置gitlab-ctl,临时方法
export PATH=$PATH:/opt/gitlab/embedded/bin/
- 运行reconfigure
gitlab-ctl reconfigure
效果
gitlab-ctl reconfigure
[2019-07-06T20:52:31+08:00] INFO: Started chef-zero at chefzero://localhost:1 with repository at /opt/gitlab/embedded
One version per cookbook
Starting Chef Client, version 14.13.11
[2019-07-06T20:52:31+08:00] INFO: *** Chef 14.13.11 ***
[2019-07-06T20:52:31+08:00] INFO: Platform: x86_64-linux
[2019-07-06T20:52:31+08:00] INFO: Chef-client pid: 28331
[2019-07-06T20:52:31+08:00] INFO: The plugin path /etc/chef/ohai/plugins does not exist. Skipping...
[2019-07-06T20:52:35+08:00] INFO: Setting the run_list to ["recipe[dalong::default]"] from CLI options
[2019-07-06T20:52:35+08:00] INFO: Run List is [recipe[dalong::default]]
[2019-07-06T20:52:35+08:00] INFO: Run List expands to [dalong::default]
[2019-07-06T20:52:35+08:00] INFO: Starting Chef Run for dalong
[2019-07-06T20:52:35+08:00] INFO: Running start handlers
[2019-07-06T20:52:35+08:00] INFO: Start handlers complete.
resolving cookbooks for run list: ["dalong::default"]
[2019-07-06T20:52:35+08:00] INFO: Loading cookbooks [dalong@0.1.0]
Synchronizing Cookbooks:
- dalong (0.1.0)
Installing Cookbook Gems:
Compiling Cookbooks...
Converging 2 resources
Recipe: dalong::default
* cookbook_file[/opt/dalongdemo] action create (up to date)
* template[/opt/userinfo] action create[2019-07-06T20:52:35+08:00] INFO: template[/opt/userinfo] backed up to /opt/gitlab/embedded/cookbooks/cache/backup/opt/userinfo.chef-20190706205235.478792
[2019-07-06T20:52:35+08:00] INFO: template[/opt/userinfo] updated file contents /opt/userinfo
- update content in file /opt/userinfo from 1c0757 to 5899a9
--- /opt/userinfo 2019-07-06 20:19:37.413578996 +0800
+++ /opt/.chef-userinfo20190706-28331-7hw6nj 2019-07-06 20:52:35.476613088 +0800
@@ -1,4 +1,4 @@
-user demo 2019-07-06 20:19:37 +0800
+user demo 2019-07-06 20:52:35 +0800
config info dalong
[2019-07-06T20:52:35+08:00] INFO: Chef Run complete in 0.237688022 seconds
Running handlers:
[2019-07-06T20:52:35+08:00] INFO: Running report handlers
Running handlers complete
[2019-07-06T20:52:35+08:00] INFO: Report handlers complete
Chef Client finished, 1/2 resources updated in 03 seconds
gitlab Reconfigured!
说明
以上就是一个简单的学习,测试,实际上我们将两者集成起来,可以方便的进行软件配置管理
参考资料
https://github.com/rongfengliang/omnibus-ctl-demo
https://www.cnblogs.com/rongfengliang/p/11114158.html
https://github.com/chef/omnibus
https://github.com/chef/omnibus-ctl
https://github.com/chef/omnibus-software
https://github.com/gitlabhq/omnibus-gitlab
https://docs.chef.io/ctl_chef_client.html
集成omnibus-ctl+ chef 制作一个可配置的软件包的更多相关文章
- 使用React制作一个可配置的页面生成器[0]
背景 上班两年多,终于来到一家互联网公司,告别之前的朝九晚六的腐败生活,开始了11116的码农之旅. 因为公司做的是直播相关的业务,所以伴随着直播,不定期的就会有运营活动-.- 但是这类活动留给码农的 ...
- Swift 制作一个新闻通知中心插件1
使用 Swift 制作一个新闻通知中心插件(1) 随着 iOS 8 的发布,苹果为开发者们开放了很多新的 API,而在这些开放的接口中 通知中心插件 无疑是最显眼的一个.通知中心就不用过多介绍了,相信 ...
- springboot2.x基础教程:动手制作一个starter包
上一篇博客介绍了springboot自动装配的原理.springboot本身有丰富的spring-boot-starter-xx集成组件,这一篇趁热打铁加深理解,我们利用springboot自动装配的 ...
- 制作一个简洁的jquery插件
原文:http://mp.weixin.qq.com/s?__biz=MzAxMzgwNDU3Mg==&mid=401571467&idx=1&sn=08cb00963e6ef ...
- iOS自定义控件教程:制作一个可重用的旋钮
当你的APP需要一些新功能时,自定义UI控件会十分有用,尤其是这些自定义控件可以在其他APP里面很好的重用.Colin Eberhart写过一篇很棒的介绍自定义UI控件的教程.这个教程涉及的是一个继承 ...
- 用WebCollector制作一个爬取《知乎》并进行问题精准抽取的爬虫(JAVA)
简单介绍: WebCollector是一个无须配置.便于二次开发的JAVA爬虫框架(内核),它提供精简的的API.仅仅需少量代码就可以实现一个功能强大的爬虫. 怎样将WebCollector导入项目请 ...
- 实例学习SSIS(一)--制作一个简单的ETL包
原文:实例学习SSIS(一)--制作一个简单的ETL包 导读: 实例学习SSIS(一)--制作一个简单的ETL包 实例学习SSIS(二)--使用迭代 实例学习SSIS(三)--使用包配置 实例学习SS ...
- ASP.NET MVC + 百度富文本编辑器 + EasyUi + EntityFrameWork 制作一个添加新闻功能
本文将交大伙怎么集成ASP.NET MVC + 百度富文本编辑器 + EasyUi + EntityFrameWork来制作一个新闻系统 先上截图: 添加页面如下: 下面来看代码部分 列表页如下: @ ...
- 老李分享:持续集成学好jenkins之Git和Maven配置
老李分享:持续集成学好jenkins之Git和Maven配置 poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣 ...
随机推荐
- aop 打印请求信息
项目中使用 AOP 打印请求信息,打印响应信息.package com.example.aspect; import com.alibaba.fastjson.JSON;import com.goog ...
- Drool7s kmodule的作用--系列02课
本文是介绍drool7s kmodule. 一.为什么komdule.xml文件一定要放在resources下的META-INF文件夹中 --->直接看源码吧,请看下图,应该都知道为什么要放在固 ...
- Spring Boot整合Mybatis完成级联一对多CRUD操作
在关系型数据库中,随处可见表之间的连接,对级联的表进行增删改查也是程序员必备的基础技能.关于Spring Boot整合Mybatis在之前已经详细写过,不熟悉的可以回顾Spring Boot整合Myb ...
- ASP.NET SignalR 系列(六)之连接事件
本章主要介绍下SignalR自带的连接事件 其实再前面的示例中,有出现了一些事件的重载,比如 public override Task OnConnected() 下面简单介绍一下SignalR提供了 ...
- Mybatis中使用collection进行多对多双向关联示例(含XML版与注解版)
Mybatis中使用collection进行多对多双向关联示例(含XML版与注解版) XML版本: 实体类: @Data @NoArgsConstructor public class Course ...
- 获取form表单默认提交的返回值
1.经常用form表单提交的小伙伴有没有发现,form表单默认的提交是没有返回值的,而且默认提交成功之后是跳转,跳转的action的路径,下面写一下默认的提交如何获取到form表单的返回值json,并 ...
- js节流与防抖函数封装
js节流与防抖函数封装 常见应用场景: window的 resize 和 scroll 事件: 文字输入时的 keyup 事件: 元素拖拽.移动时的 mousemove 事件: 防抖 定义:多次触发事 ...
- Nuxt.js vue init nuxt-community/koa-template 初始化项目报错
报错提示: Module build failed: Error: Plugin/Preset files are not allowed to export objects, only functi ...
- Alpha_6
一. 站立式会议照片 二. 工作进展 (1) 昨天已完成的工作 a. 修改设计图的小毛病 b. 补签卡页面 c. 实现我的,我的卡包,卡片细节功能页面,并可预览 d. 已实现“番茄钟_数据统计”页面和 ...
- elasticsearch获取字段missing的数据
用head查询: demo如下 http://localhost:9200/sj_0505/lw_point_location/ _search post { "query": { ...