LoginSignup
27
31

More than 5 years have passed since last update.

Git/Subversion リポジトリを作成して Redmine と連携する

Posted at

はじめに

vagrant - proxy 環境化の CentOS に Chef で Remine をインストール - Qiita [キータ] で構築した node 上に Git リポジトリ、Subversion リポジトリを作成して Redmine と連携する手順を示します。

Git リポジトリを作成して Redmine と連携する

Git リポジトリを作成する

まず、/var/lib/git をホームディレクトリとする git ユーザを作成します。適当なパスワードを指定すると怒られますが、今回は無視します。

[vagrant@localhost ~]$ sudo useradd -m -d /var/lib/git git

[vagrant@localhost ~]$ sudo passwd git
Changing password for user git.
New password:
BAD PASSWORD: it is WAY too short
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.

後続の手順で redmine からアクセスするため、このホームディレクトリは git グループに所属するユーザも書き込めるようパーミッションを 775 に変更します。

[vagrant@localhost ~]$ sudo chmod 775 /var/lib/git/

それでは git ユーザになって git リポジトリを作成してみましょう。

慣習に倣って .git で終わる名前のディレクトリを作成したら、--bare と --shared を指定して git init します。

[vagrant@localhost ~]$ su - git
Password:

[git@localhost ~]$ mkdir gitrepo.git

[git@localhost ~]$ git init --bare --shared gitrepo.git/
Initialized empty shared Git repository in /var/lib/git/gitrepo.git/

以上で Git リポジトリの作成は完了です。

workstation からアクセスする

さっそく workstation から vagrant ユーザで node 上のリポジトリにアクセスできることを確認してみましょう。

vagrant ユーザが作成したリポジトリにアクセスできるよう、git グループに追加します。

[vagrant@localhost lib]$ sudo gpasswd -a vagrant git
Adding user vagrant to group git

workstatiton 上に適当なディレクトリ作成して移動したら、node から Git リポジトリを clone できることを確認します。

vagrant@precise64:~$ mkdir -p devel/repos
vagrant@precise64:~$ cd devel/repos/
vagrant@precise64:~/devel/repos$ git clone vagrant@192.168.33.100:/var/lib/git/gitrepo.git
Cloning into 'gitrepo'...
warning: You appear to have cloned an empty repository.

正常に clone できたら、適当なファイルを作成して add, commit してみましょう。

vagrant@precise64:~/devel/repos$ cd gitrepo/
vagrant@precise64:~/devel/repos/gitrepo$ vi README.md

vagrant@precise64:~/devel/repos/gitrepo$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   README.md
nothing added to commit but untracked files present (use "git add" to track)

vagrant@precise64:~/devel/repos/gitrepo$ git add .
vagrant@precise64:~/devel/repos/gitrepo$ git commit -m "initial commit"
[master (root-commit) 62b8051] initial commit
 1 file changed, 2 insertions(+)
 create mode 100644 README.md

最後に、コミットした内容を push できることを確認しましょう。

vagrant@precise64:~/devel/repos/gitrepo$ git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 224 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To vagrant@192.168.33.100:/var/lib/git/gitrepo.git
 * [new branch]      master -> master

無事に push できました。

Redmine と連携する

redmine から作成したリポジトリにアクセスできるよう、apache ユーザを git グループに追加します。

[vagrant@localhost lib]$ sudo gpasswd -a apache git
Adding user apache to group git

ホスト OS 上のブラウザから http://192.168.33.100 にアクセスし、admin/admin で Redmine にログインしてください。

通常通り redmine のプロジェクトを作成してバージョン管理システムに Git を選択したら、以下の情報を入力して「作成」ボタンをクリックします。

  • 識別子:適当な識別子
  • リポジトリのパス:/var/lib/git/gitrepo.git

リポジトリタブから Git リポジトリの内容が参照できることを確認します。

SVN リポジトリを作成して Redmine と連携する

Subversion リポジトリを作成する

subversion の設定は node 上の /etc/httpd/sites-available/subversion.conf に記載されています。

[vagrant@localhost ~]$ cat /etc/httpd/sites-available/subversion.conf 
<Location /svn>
  DAV svn
  SVNParentPath /srv/svn
  SVNListParentPath off
  AuthType Basic
  AuthName "Subversion repository"
  AuthUserFile /srv/svn/htpasswd
  Require valid-user
</Location>

/src/svn にリポジトリを作成すること、認証情報は /src/svn/htpasswd で管理することが分かります。

さっそく新規にリポジトリを作成してみましょう。svnadmin create したら、apache からアクセスできるよう所有権を変更します。

[vagrant@localhost svn]$ sudo svnadmin create /srv/svn/svnrepo
[vagrant@localhost svn]$ sudo chown -R apache:apache /srv/svn/svnrepo/

続いて SVN リポジトリに vagrant/vagrant でアクセスできるよう認証情報を追記します。

[vagrant@localhost svn]$ sudo htpasswd -b -m /srv/svn/htpasswd vagrant vagrant
Adding password for user vagrant

以上で SVN リポジトリの準備は完了です。

workstation からアクセスする

さっそく workstation から vagrant ユーザで node 上のリポジトリにアクセスできることを確認してみましょう。

workstation には svn クライアントが入っていなかったので、apt-get でインストールします。

vagrant@precise64:~$ sudo apt-get install subversion
(snip)
vagrant@precise64:~$ svn --version
svn, version 1.6.17 (r1128011)
(snip)

workstatiton 上の適当なディレクトリに移動したら、node から SVN リポジトリを checkout できることを確認します。

vagrant@precise64:~$ cd devel/repos/
vagrant@precise64:~/devel/repos$ svn co http://192.168.33.100/svn/svnrepo
Authentication realm: <http://192.168.33.100:80> Subversion repository
Password for 'vagrant': 

-----------------------------------------------------------------------
ATTENTION!  Your password for authentication realm:

   <http://192.168.33.100:80> Subversion repository

can only be stored to disk unencrypted!  You are advised to configure
your system so that Subversion can store passwords encrypted, if
possible.  See the documentation for details.

You can avoid future appearances of this warning by setting the value
of the 'store-plaintext-passwords' option to either 'yes' or 'no' in
'/home/vagrant/.subversion/servers'.
-----------------------------------------------------------------------
Store password unencrypted (yes/no)? yes
Checked out revision 0.

パスワードを平文で保存するかと怖いことを聞かれますが、とりあえず yes と回答したら無事にチェックアウトできました。

チェックアウトしたディレクトリに移動したら、お決まりのディレクトリを作成して commit してみましょう。

vagrant@precise64:~/devel/repos$ cd svnrepo
vagrant@precise64:~/devel/repos/svnrepo$ mkdir trunk tags branches
vagrant@precise64:~/devel/repos/svnrepo$ svn add trunk/ tags/ branches/
A         trunk
A         tags
A         branches
vagrant@precise64:~/devel/repos/svnrepo$ svn commit -m "initial commit"
Adding         branches
Adding         tags
Adding         trunk

Committed revision 1.

無事にコミットできました。

Redmine と連携する

通常通り redmine のプロジェクトを作成してバージョン管理システムに Subversion を選択したら、以下の情報を入力して「作成」ボタンをクリックします。

リポジトリタブから SVN リポジトリの内容が参照できることを確認します。

27
31
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
27
31