前边有写过使用omnibus-ctl 制作软件包的,但是当时没有集成chef,只有一个空壳子,实际上omnibus-ctl 已经内置
了对于chef 的操作(但是我们还需要在添加一个依赖),以下简单说明两者如何进行集成

demo 是一个类似gitlab-ctl 的操作,但是只有一个简单的cookbook,实际上可以自己进行扩展

项目准备

  • 项目初始化
  1. omnibus new gitlab
  • 项目结构

    添加了关于cookbook 操作之后的

  1. ├── Berksfile
  1. ├── Gemfile
  1. ├── README.md
  1. ├── config
  1. ├── projects
  1. └── gitlab.rb
  1. ├── software
  1. ├── chef-gem.rb
  1. ├── chef-zero.rb
  1. ├── gitlab-cookbooks.rb
  1. ├── gitlab-ctl.rb
  1. ├── gitlab-zlib.rb
  1. └── preparation.rb
  1. └── templates
  1. └── gitlab-cookbooks
  1. └── dna.json.erb
  1. ├── files
  1. ├── gitlab-cookbooks
  1. ├── dalong
  1. ├── CHANGELOG.md
  1. ├── Gemfile
  1. ├── Gemfile.lock
  1. ├── LICENSE
  1. ├── README.md
  1. ├── attributes
  1. └── userlogin.rb
  1. ├── chefignore
  1. ├── files
  1. └── dalong
  1. ├── kitchen.yml
  1. ├── metadata.rb
  1. ├── recipes
  1. ├── dalong.rb
  1. ├── default.rb
  1. └── userlogin.rb
  1. ├── spec
  1. ├── spec_helper.rb
  1. └── unit
  1. └── recipes
  1. ├── dalong_spec.rb
  1. ├── default_spec.rb
  1. └── userlogin_spec.rb
  1. ├── templates
  1. └── userlogin.erb
  1. └── test
  1. └── integration
  1. └── default
  1. ├── dalong_test.rb
  1. ├── default_test.rb
  1. └── userlogin_test.rb
  1. ├── dna.json
  1. └── solo.rb
  1. └── gitlab-ctl-commands
  1. └── config.rb
  1. ├── omnibus.rb
  1. └── package-scripts
  1. └── gitlab
  1. ├── postinst
  1. ├── postrm
  1. ├── preinst
  1. └── prerm
  • 简单说明
    以上就是一个普通的使用omnibus 创建的包项目,同时添加了omnibus-ctl 对于cookbbok 操作的配置以及集成omnibus-ctl

代码说明

详细代码参考:https://github.com/rongfengliang/omnibus-ctl-demo

  • config/project/gitlab.rb
    主要是关于项目的说明以及依赖的处理
  1. #
  1. # Copyright 2019 YOUR NAME
  1. #
  1. # All Rights Reserved.
  1. #
  1. name "gitlab"
  1. maintainer "rongfengliang"
  1. homepage "https://github.com/rongfengliang"
  1. # Defaults to C:/my on Windows
  1. # and /opt/my on all other platforms
  1. install_dir "#{default_root}/#{name}"
  1. build_version Omnibus::BuildVersion.semver
  1. build_iteration 1
  1. # Creates required build directories
  1. dependency "preparation"
  1. dependency "gitlab-ctl"
  1. dependency 'gitlab-cookbooks'
  1. dependency 'chef-zero'
  1. dependency 'chef-gem'
  1. # my dependencies/components
  1. # dependency "somedep"
  1. exclude "**/.git"
  1. exclude "**/bundler/git"
  • software 定义
    这个分了ctl的以及关于cookbook ,还有就是chef 操作的(omnibus-ctl的命令依赖)
    config/software/gitlab-ctl.rb:
  1. name "gitlab-ctl"
  1. dependency "omnibus-ctl"
  1. source :path => File.expand_path("files/gitlab-ctl-commands", RbConfig::CONFIG['project_root'])
  1. build do
  1. block do
  1. open("#{install_dir}/embedded/bin/gitlab-ctl", "w") do |file|
  1. file.print <<-EOH
  1. #!/bin/bash
  1. # Ruby environment if gitlab-ctl is called from a Ruby script.
  1. for ruby_env_var in RUBYOPT \\
  1. BUNDLE_BIN_PATH \\
  1. BUNDLE_GEMFILE \\
  1. GEM_PATH \\
  1. GEM_HOME
  1. do
  1. unset $ruby_env_var
  1. done
  1. #{install_dir}/embedded/bin/omnibus-ctl gitlab #{install_dir}/embedded/service/omnibus-ctl $@
  1. EOH
  1. end
  1. end
  1. command "chmod 755 #{install_dir}/embedded/bin/gitlab-ctl"
  1. # additional omnibus-ctl commands
  1. sync "#{project_dir}/", "#{install_dir}/embedded/service/omnibus-ctl/"
  1. end

config/software/gitlab-cookbooks.rb:

  1. #
  1. # Copyright:: Copyright (c) 2012 Opscode, Inc.
  1. # Copyright:: Copyright (c) 2014 GitLab.com
  1. # License:: Apache License, Version 2.0
  1. #
  1. # Licensed under the Apache License, Version 2.0 (the "License");
  1. # you may not use this file except in compliance with the License.
  1. # You may obtain a copy of the License at
  1. #
  1. # http://www.apache.org/licenses/LICENSE-2.0
  1. #
  1. # Unless required by applicable law or agreed to in writing, software
  1. # distributed under the License is distributed on an "AS IS" BASIS,
  1. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1. # See the License for the specific language governing permissions and
  1. # limitations under the License.
  1. #
  1. name 'gitlab-cookbooks'
  1. license 'Apache-2.0'
  1. source path: File.expand_path('files/gitlab-cookbooks', Omnibus::Config.project_root)
  1. build do
  1. cookbook_name = 'dalong::default'
  1. command "mkdir -p #{install_dir}/embedded/cookbooks"
  1. sync './', "#{install_dir}/embedded/cookbooks/"
  1. erb dest: "#{install_dir}/embedded/cookbooks/dna.json",
  1. source: 'dna.json.erb',
  1. mode: 0644,
  1. vars: { master_cookbook: cookbook_name }
  1. end
  1.  

config/software/chef-gem.rb:

  1. #
  1. # Copyright 2012-2014 Chef Software, Inc.
  1. #
  1. # Licensed under the Apache License, Version 2.0 (the "License");
  1. # you may not use this file except in compliance with the License.
  1. # You may obtain a copy of the License at
  1. #
  1. # http://www.apache.org/licenses/LICENSE-2.0
  1. #
  1. # Unless required by applicable law or agreed to in writing, software
  1. # distributed under the License is distributed on an "AS IS" BASIS,
  1. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1. # See the License for the specific language governing permissions and
  1. # limitations under the License.
  1. #
  1. name 'chef-gem'
  1. # The version here should be in agreement with /Gemfile.lock so that our rspec
  1. # testing stays consistent with the package contents.
  1. default_version '14.13.11'
  1. license 'Apache-2.0'
  1. license_file 'LICENSE'
  1. skip_transitive_dependency_licensing true
  1. dependency 'ruby'
  1. dependency 'rubygems'
  1. dependency 'libffi'
  1. dependency 'rb-readline'
  1. build do
  1. env = with_standard_compiler_flags(with_embedded_path)
  1. gem 'install chef' \
  1. " --version '#{version}'" \
  1. " --bindir '#{install_dir}/embedded/bin'" \
  1. ' --no-document', env: env
  1. end

config/software/chef-zero.rb(chef-client 实际上就是调用的这个,所以是一个比较重要的)

  1. #
  1. #
  1. # Licensed under the Apache License, Version 2.0 (the "License");
  1. # you may not use this file except in compliance with the License.
  1. # You may obtain a copy of the License at
  1. #
  1. # http://www.apache.org/licenses/LICENSE-2.0
  1. #
  1. # Unless required by applicable law or agreed to in writing, software
  1. # distributed under the License is distributed on an "AS IS" BASIS,
  1. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1. # See the License for the specific language governing permissions and
  1. # limitations under the License.
  1. #
  1. name 'chef-zero'
  1. # The version here should be in agreement with /Gemfile.lock so that our rspec
  1. # testing stays consistent with the package contents.
  1. default_version '14.0.12'
  1. license 'Apache-2.0'
  1. license_file 'LICENSE'
  1. skip_transitive_dependency_licensing true
  1. dependency 'ruby'
  1. dependency 'rubygems'
  1. build do
  1. env = with_standard_compiler_flags(with_embedded_path)
  1. gem 'install chef-zero' \
  1. " --version '#{version}'" \
  1. " --bindir '#{install_dir}/embedded/bin'" \
  1. ' --no-document', env: env
  1. end
  • cookbook
    编写了一个简单的cookbook,可以在执行reconfigure 的时候自动生成需要的文件
    files/gitlab-cookbooks 目录,实际上就是一个简单的chef cookbook 项目,核心是
    使用chef-client local 模式的配置solo.rb 以及dns.json(实际是用模版生成的)
    solo.rb:
  1. CURRENT_PATH = File.expand_path(File.dirname(__FILE__))
  1. TIME = Time.now.to_i
  1. LOG_PATH = '/var/log/gitlab/reconfigure'.freeze
  1. Dir.exist?(LOG_PATH) || FileUtils.mkdir_p(LOG_PATH)
  1. file_cache_path "#{CURRENT_PATH}/cache"
  1. cookbook_path CURRENT_PATH
  1. cache_path "#{CURRENT_PATH}/cache"
  1. verbose_logging false
  1. # Log to the reconfigure log
  1. log_location "#{LOG_PATH}/#{TIME}.log"
  1. log_level :info

dns.json:

  1. {
  1. "run_list": [ "recipe[dalong::default]" ]
  1. } 

构建&&运行效果

  • 构建
  1. bundle install --binstubs
  1. bin/omnibus build gitlab
  • 生成的rpm 包
  1. ├── gitlab-0.0.0+20190706121815-1.el7.x86_64.rpm
  1. ├── gitlab-0.0.0+20190706121815-1.el7.x86_64.rpm.metadata.json
  1. └── version-manifest.json
  • 安装rpm 包
  1. yum install gitlab-0.0.0+20190706121815-1.el7.x86_64.rpm
  1. 已加载插件:fastestmirror
  1. 正在检查 gitlab-0.0.0+20190706121815-1.el7.x86_64.rpm: gitlab-0.0.0+20190706121815-1.el7.x86_64
  1. gitlab-0.0.0+20190706121815-1.el7.x86_64.rpm 将被安装
  1. 正在解决依赖关系
  1. --> 正在检查事务
  1. ---> 软件包 gitlab.x86_64.0.0.0.0+20190706121815-1.el7 将被 安装
  1. --> 解决依赖关系完成
  1. 依赖关系解决
  1. =======================================================================================================================
  1. Package 架构 版本 大小
  1. =======================================================================================================================
  1. 正在安装:
  1. gitlab x86_64 0.0.0+20190706121815-1.el7 /gitlab-0.0.0+20190706121815-1.el7.x86_64 82 M
  1. 事务概要
  1. =======================================================================================================================
  1. 安装 1 软件包
  1. 总计:82 M
  1. 安装大小:82 M
  1. Is this ok [y/d/N]: y
  1. Downloading packages:
  1. Running transaction check
  1. Running transaction test
  1. Transaction test succeeded
  1. Running transaction
  1. You're about to install gitlab!
  1. 正在安装 : gitlab-0.0.0+20190706121815-1.el7.x86_64 1/1
  1. Thank you for installing gitlab! please run gitlab-ctl reconfigure
  1. 验证中 : gitlab-0.0.0+20190706121815-1.el7.x86_64 1/1
  1. 已安装:
  1. gitlab.x86_64 0:0.0.0+20190706121815-1.el7
  1. 完毕!
 
 
  • 配置path
    因为是测试,就没有配置使用软连接配置gitlab-ctl,临时方法
  1. export PATH=$PATH:/opt/gitlab/embedded/bin/
  • 运行reconfigure
  1. gitlab-ctl reconfigure

效果

  1. gitlab-ctl reconfigure
  1. [2019-07-06T20:52:31+08:00] INFO: Started chef-zero at chefzero://localhost:1 with repository at /opt/gitlab/embedded
  1. One version per cookbook
  1. Starting Chef Client, version 14.13.11
  1. [2019-07-06T20:52:31+08:00] INFO: *** Chef 14.13.11 ***
  1. [2019-07-06T20:52:31+08:00] INFO: Platform: x86_64-linux
  1. [2019-07-06T20:52:31+08:00] INFO: Chef-client pid: 28331
  1. [2019-07-06T20:52:31+08:00] INFO: The plugin path /etc/chef/ohai/plugins does not exist. Skipping...
  1. [2019-07-06T20:52:35+08:00] INFO: Setting the run_list to ["recipe[dalong::default]"] from CLI options
  1. [2019-07-06T20:52:35+08:00] INFO: Run List is [recipe[dalong::default]]
  1. [2019-07-06T20:52:35+08:00] INFO: Run List expands to [dalong::default]
  1. [2019-07-06T20:52:35+08:00] INFO: Starting Chef Run for dalong
  1. [2019-07-06T20:52:35+08:00] INFO: Running start handlers
  1. [2019-07-06T20:52:35+08:00] INFO: Start handlers complete.
  1. resolving cookbooks for run list: ["dalong::default"]
  1. [2019-07-06T20:52:35+08:00] INFO: Loading cookbooks [dalong@0.1.0]
  1. Synchronizing Cookbooks:
  1. - dalong (0.1.0)
  1. Installing Cookbook Gems:
  1. Compiling Cookbooks...
  1. Converging 2 resources
  1. Recipe: dalong::default
  1. * cookbook_file[/opt/dalongdemo] action create (up to date)
  1. * 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
  1. [2019-07-06T20:52:35+08:00] INFO: template[/opt/userinfo] updated file contents /opt/userinfo
  1. - update content in file /opt/userinfo from 1c0757 to 5899a9
  1. --- /opt/userinfo 2019-07-06 20:19:37.413578996 +0800
  1. +++ /opt/.chef-userinfo20190706-28331-7hw6nj 2019-07-06 20:52:35.476613088 +0800
  1. @@ -1,4 +1,4 @@
  1. -user demo 2019-07-06 20:19:37 +0800
  1. +user demo 2019-07-06 20:52:35 +0800
  1. config info dalong
  1. [2019-07-06T20:52:35+08:00] INFO: Chef Run complete in 0.237688022 seconds
  1. Running handlers:
  1. [2019-07-06T20:52:35+08:00] INFO: Running report handlers
  1. Running handlers complete
  1. [2019-07-06T20:52:35+08:00] INFO: Report handlers complete
  1. Chef Client finished, 1/2 resources updated in 03 seconds
  1. 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 制作一个可配置的软件包的更多相关文章

  1. 使用React制作一个可配置的页面生成器[0]

    背景 上班两年多,终于来到一家互联网公司,告别之前的朝九晚六的腐败生活,开始了11116的码农之旅. 因为公司做的是直播相关的业务,所以伴随着直播,不定期的就会有运营活动-.- 但是这类活动留给码农的 ...

  2. Swift 制作一个新闻通知中心插件1

    使用 Swift 制作一个新闻通知中心插件(1) 随着 iOS 8 的发布,苹果为开发者们开放了很多新的 API,而在这些开放的接口中 通知中心插件 无疑是最显眼的一个.通知中心就不用过多介绍了,相信 ...

  3. springboot2.x基础教程:动手制作一个starter包

    上一篇博客介绍了springboot自动装配的原理.springboot本身有丰富的spring-boot-starter-xx集成组件,这一篇趁热打铁加深理解,我们利用springboot自动装配的 ...

  4. 制作一个简洁的jquery插件

    原文:http://mp.weixin.qq.com/s?__biz=MzAxMzgwNDU3Mg==&mid=401571467&idx=1&sn=08cb00963e6ef ...

  5. iOS自定义控件教程:制作一个可重用的旋钮

    当你的APP需要一些新功能时,自定义UI控件会十分有用,尤其是这些自定义控件可以在其他APP里面很好的重用.Colin Eberhart写过一篇很棒的介绍自定义UI控件的教程.这个教程涉及的是一个继承 ...

  6. 用WebCollector制作一个爬取《知乎》并进行问题精准抽取的爬虫(JAVA)

    简单介绍: WebCollector是一个无须配置.便于二次开发的JAVA爬虫框架(内核),它提供精简的的API.仅仅需少量代码就可以实现一个功能强大的爬虫. 怎样将WebCollector导入项目请 ...

  7. 实例学习SSIS(一)--制作一个简单的ETL包

    原文:实例学习SSIS(一)--制作一个简单的ETL包 导读: 实例学习SSIS(一)--制作一个简单的ETL包 实例学习SSIS(二)--使用迭代 实例学习SSIS(三)--使用包配置 实例学习SS ...

  8. ASP.NET MVC + 百度富文本编辑器 + EasyUi + EntityFrameWork 制作一个添加新闻功能

    本文将交大伙怎么集成ASP.NET MVC + 百度富文本编辑器 + EasyUi + EntityFrameWork来制作一个新闻系统 先上截图: 添加页面如下: 下面来看代码部分 列表页如下: @ ...

  9. 老李分享:持续集成学好jenkins之Git和Maven配置

    老李分享:持续集成学好jenkins之Git和Maven配置   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣 ...

随机推荐

  1. jdbc 简单示例和优缺点

    一个使用JDBC的例子: Class.forName("com.mysql.cj.jdbc.Driver"); //加载驱动 Connection connection = Dri ...

  2. 一文快速入门Docker

    Docker提供一种安全.可重复的环境中自动部署软件的方式,拉开了基于与计算平台发展方式的变革序幕.如今Docker在互联网公司使用已经非常普遍.本文用十分钟时间,带你快速入门Docker. Dock ...

  3. EFCore自动迁移

    2019/05/14,EFCore 2.2.4 有两种方式: 使用Migrate()方法 if (DbContext.Database.GetPendingMigrations().Any()) { ...

  4. Visual Studio 2019 使用.Net Core 3.0 二

    一.遇到难题 在微软官方逛了一圈,看到了这个. 马上点击,进去看看什么情况. 1.安装previewVisual studio 2019 2.设置SDK previews in Visual Stud ...

  5. 分享AWS网站

    1.AWS服务运行状况检测网站:   https://status.amazonaws.cn/ 2.AWS架构白皮书:https://aws.amazon.com/cn/architecture/?a ...

  6. Iris Network Traffic Analyzer嗅探器

    网卡配置 ftp测试

  7. ResourceDictionary文件排序方法

    默认生成的ResourceDictionary文件是根据主键的hashcode排序生成的,如果想按主键排序生成是不可能的. 可以使用Xml的处理方法来生成ResourceDictionary文件. 1 ...

  8. 【兼容调试】cffi library '_openssl' has no function, constant or global variable named 'Cryptography_HAS

    重装cryptography就好了. conda uninstall cryptography conda install cryptography https://github.com/pyca/c ...

  9. 基于 K8S 集群安装部署 istio-1.2.4

    使用云平台可以为组织提供丰富的好处.然而,不可否认的是,采用云可能会给 DevOps 团队带来压力.开发人员必须使用微服务以满足应用的可移植性,同时运营商管理了极其庞大的混合和多云部署.Istio 允 ...

  10. [JavaScript] js中全局标识正则表达式的lastIndex属性

    在JavaScript中使用正则表达式时,遇到一个坑:第一次匹配是true,第二次匹配是false. 因为在带全局标识"g"的正则表达式对象中,才有“lastIndex” 属性,该 ...