LoginSignup
3
3

More than 5 years have passed since last update.

Omnibus を利用して OSX のパッケージを作成する

Last updated at Posted at 2014-09-06

今さらなのですが諸事情で作ってみたので

dmgファイルになって配布が簡単になります。インストールはpkgをクリックしてもらうだけです

sass.png

Sass単体だと用途があまり思い浮かばないのですがchefgitlabみたいなプロダクトやミドルウェアなど配布するときには便利なのではないかと思います。

試していないですがWindows配布にも対応しているし。

試したバージョン

  • Omnibus - v3.2.1
  • ruby - 2.1.1p76

(作成する)パッケージ情報

  • /opt/sassにインストール
  • rubyのバージョンは2.1.1
  • rubygemsのバージョンは2.2.1

作成方法

以下にずらずら書いてる手順で作成したサンプルはGitHubにアップしています

omnibusをインストールする

$ gem install omnibus
$ omnibus -v
Omnibus v3.2.1

プロジェクトを作成

$ omnibus new sass
      create  omnibus-sass/Gemfile
      create  omnibus-sass/.gitignore
      create  omnibus-sass/README.md
      create  omnibus-sass/omnibus.rb
      create  omnibus-sass/config/projects/sass.rb
      create  omnibus-sass/config/software/c-example.rb
      create  omnibus-sass/config/software/erlang-example.rb
      create  omnibus-sass/config/software/ruby-example.rb
      create  omnibus-sass/.kitchen.local.yml
      create  omnibus-sass/.kitchen.yml
      create  omnibus-sass/Berksfile
      create  omnibus-sass/package-scripts/sass/makeselfinst
       chmod  omnibus-sass/package-scripts/sass/makeselfinst
      create  omnibus-sass/package-scripts/sass/preinst
       chmod  omnibus-sass/package-scripts/sass/preinst
      create  omnibus-sass/package-scripts/sass/prerm
       chmod  omnibus-sass/package-scripts/sass/prerm
      create  omnibus-sass/package-scripts/sass/postinst
       chmod  omnibus-sass/package-scripts/sass/postinst
      create  omnibus-sass/package-scripts/sass/postrm
       chmod  omnibus-sass/package-scripts/sass/postrm
      create  omnibus-sass/files/mac_pkg/Resources/license.html
      create  omnibus-sass/files/mac_pkg/Resources/welcome.html
      create  omnibus-sass/files/mac_pkg/Resources/background.png
      create  omnibus-sass/files/mac_dmg/Resources/background.png
      create  omnibus-sass/files/mac_dmg/Resources/icon.png
      create  omnibus-sass/files/windows_msi/Resources/localization-en-us.wxl.erb
      create  omnibus-sass/files/windows_msi/Resources/parameters.wxi.erb
      create  omnibus-sass/files/windows_msi/Resources/source.wxs
      create  omnibus-sass/files/windows_msi/Resources/assets/LICENSE.rtf
      create  omnibus-sass/files/windows_msi/Resources/assets/banner_background.bmp
      create  omnibus-sass/files/windows_msi/Resources/assets/dialog_background.bmp
      create  omnibus-sass/files/windows_msi/Resources/assets/project.ico
      create  omnibus-sass/files/windows_msi/Resources/assets/project_16x16.ico
      create  omnibus-sass/files/windows_msi/Resources/assets/project_32x32.ico

Gemfileを修正

omnibus-softwareをインストールするようにします

※ 現在のブランチだとcacertがチェックサムでエラーになってしまうのでフォークして修正した自分のブランチを利用しています

source 'https://rubygems.org'

# Use Berkshelf for resolving cookbook dependencies
gem 'berkshelf', '~> 3.0'

# Install omnibus software
gem 'omnibus', '~> 3.2'

# Use Chef's software definitions. It is recommended that you write your own
# software definitions, but you can clone/fork Chef's to get you started.
# gem 'omnibus-software', github: 'opscode/omnibus-software'
gem 'omnibus-software', github: 'ryshinoz/omnibus-software', branch: 'omnibus/3.2-stable'

# Use Test Kitchen with Vagrant for converging the build environment
gem 'test-kitchen',    '~> 1.2'
gem 'kitchen-vagrant', '~> 0.14'

インストールします

$ bundle install --binstubs

config/software/sass.rbを作成

config/software配下にそれぞれのソフトウェアをインストールするDSLを用意します

今回はSassをインストールするDSLを作成します

ビルド手順は以下です、パスで/opt/sass配下にインストールされているbundlerakeを利用するようにしています

  1. bundle installで依存ライブラリをインストール
  2. rake packageでパッケージ作成
  3. 作成したパッケージをインストール
  4. /opt/sass/bin/sassでシンボリックリンクを作成する
name 'sass'
default_version 'stable'
gem_version = '3.4.3'

source :git => 'https://github.com/sass/sass.git'
relative_path 'sass'

env = {
  'PATH' => "#{install_dir}/embedded/bin:#{ENV['PATH']}"
}

build do
  command "bundle install", :env => env
  command "rake package", :env => env
  command "#{install_dir}/embedded/bin/gem install --no-ri --no-rdoc -l pkg/sass-#{gem_version}.gem", :env => env
  command "ln -fs #{install_dir}/embedded/bin/sass #{install_dir}/bin/sass", :env => env
end

config/project/sass.rbを作成

ここにプロジェクト用の設定を記述します

dependencyで先ほど作成したsassやそれのインストールに必要なrubyなども指定します

インストール先やメンテナーなども必要に応じて修正します

name 'sass'
maintainer 'CHANGE ME'
homepage 'https://CHANGE-ME.com'

install_dir     '/opt/sass'
build_version   Omnibus::BuildVersion.semver
build_iteration 1

override :ruby, version: '2.1.1'
override :rubygems, version: '2.2.1'

# creates required build directories
dependency 'preparation'

# sass dependencies/components
# dependency 'somedep'
dependency 'ruby'
dependency 'rubygems'
dependency 'bundler'

dependency "sass"

# version manifest file
dependency 'version-manifest'

exclude '\.git*'
exclude 'bundler\/git'

キャッシュ用ディレクトリを作成

デフォルトだとキャッシュ用ディレクトリが/var/cache/omnibusになっていますが、存在しないのでそのままだとエラーになりますので作成しておきます

$ sudo mkdir -p -m 777 /var/cache/omnibus

インストールディレクトリを作成する

config/project/sass.rbで指定したinstall_dirを作成して実行するユーザにパーミッションを付与しておいてください

$ sudo mkdir /opt/sass
$ sudo chown xxx:xxx /opt/sass

ビルド

いっぱいDEPRECATEDが出ますが今回は無視します

$ bin/omnibus build sass
                     [BuildVersion] W | Could not extract version information from 'git describe'! Setting version to 0.0.0.
Building sass 0.0.0+20140906094658...
                   [Software: zlib] W | DEPRECATED: project_file (DSL). Please use `downloaded_file' instead.
                [Software: ncurses] W | DEPRECATED: project_file (DSL). Please use `downloaded_file' instead.
...
...
...
                           [Config] W | DEPRECATED: fetch ([]). Please use `Config.dmg_window_bounds' instead.
                           [Config] W | DEPRECATED: fetch ([]). Please use `Config.dmg_pkg_position' instead.

完了するとpkgディレクトリ配下にpkgとdmgファイルが作成されています

$ tree pkg
pkg
├── sass-0.0.0+20140906094658-1.dmg
├── sass-0.0.0+20140906094658-1.dmg.metadata.json
├── sass-0.0.0+20140906094658-1.pkg
└── sass-0.0.0+20140906094658-1.pkg.metadata.json

インストール

作成されたsass-0.0.0+20140906094658-1.dmgからインストールしてみます

バージョンが出れば多分問題なく動きます

$ /opt/sass/bin/sass -v
Sass 3.4.3 (Selective Steve)

Links

以上

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3