Quantcast
Channel: mitc
Viewing all articles
Browse latest Browse all 10

割と楽してCentOS 6.5のgitをバージョンアップするChefのrecipe

$
0
0

環境

item version
OS CentOS 6.5
Chef 11.8.2
VPS さくらのVPS1GB

はじめに

最近休眠状態にしていたさくらのVPSの環境を久々に構築し直して遊ぼうと思ったんですが、gitのバージョンが古くて困りました。
そこで、chefのrecipeで手抜きしてgitのバージョンをアップデートする方法を紹介します。

問題

私の.gitconfigは環境ごとに設定を変えやすいように次のようになっており、[include]が重要な位置を占めています。

[include]
    path = ~/.gitconfig.local
[alias]
    co   = checkout
    st   = status
    br   = branch
    lol  = log --graph --decorate --pretty=oneline --abbrev-commit
    lola = log --graph --decorate --pretty=oneline --abbrev-commit --all
    l = log --pretty=format:\"%ci %C(yellow)%H%Creset [%cn] %Cgreen%s %C(cyan)%d%Creset\" -10
    lop = log -p -1
    cp = cherry-pick
[color]
    ui = auto
[user]
    name  = foo
    email = foo@example.com
[core]
    excludesfile = /Users/foo/.gitignore_global

しかし、この[include]はgitの1.7.10からサポートされたということで、デフォルトでは1.7.1がインストールされているCentOS 6.5では使えないという問題に当たりました。

解決

さくらのVPSを再開するに当たって、環境を作ったり壊したりをやりやすいVPSだからこそ尚更セットアップを自動化したいという思いに駆られ、今回から環境構築をChef + knife soloで行っています。
今回は次のようなレシピを用意しました。

site :opscode

cookbook 'yum-repoforge'
include_recipe 'yum-repoforge'

yum_package "git" do
  action :upgrade
  flush_cache [ :before ]
  options '--enablerepo=rpmforge-extras'
end
{
  "run_list": [
    "recipe[site_git]"
  ],
  "yum": {
      "rpmforge": {"enabled": false},
      "rpmforge-extras": {"enabled": false},
      "rpmforge-testing": {"enabled": false}
  }
}

方針

  • repoforgeは普段はenabledにはしないで、gitのインストールの時だけ使う
  • gitのバージョンはrepoforgeに上がっている最新の物を使う

おわりに

rpmforgeはいつの間にかrepoforgeという名前に変わっていたんですね。
とにかく、これで心置きなくgitの[include]を使えるようになり、幸せになりました。

尚、rpmforgeは非公式リポジトリなので、使用に注意して、できれば本番環境では使わない方がいいんじゃないかなあと思いました。

参考文献

https://tickets.opscode.com/browse/CHEF-2427


Viewing all articles
Browse latest Browse all 10

Latest Images

Trending Articles





Latest Images