Tech Tips

  1. プログラミング
  2. 2548 view

[git][gitweb][nginx]Ubuntu12.04LTSサーバにgitリポジトリ作って gitweb を入れる

gitweb

Contents

やりたいこと

Ubuntu 12.04 LTS上にGitの共用リポジトリを作成して、
gitwebをWebUIとして入れて複数人でプライベートで共同開発したい。

Gitのリモートリポジトリの作成

Gitのインストール

Gitのインストールは単純に
[ubuntu@remote]
$sudo apt-get install git

でOK!

リモートリポジトリ作成

まずgitユーザーを作成してグループの設定をする。
[ubuntu@remote]
$sudo adduser git
$sudo usermod -a -G git zuqqhi2
$sudo usermod -a -G git test
$sudo su - git
[git@remote]
$vim ~/.bashrc
umask 002
次にリモートリポジトリ作成を作成する。
[git@remote]
$mkdir -p /home/git/repositories/test.git
$cd /home/git/repositories/test.git
$git --bare init --shared=group
その次は、自分のユーザで中身の作成と登録。
[zuqqhi2@remote]
$mkdir ~/test
$cd ~/test
$git init
$echo "Hello git project" > README
$git add .
$git commit -m "first push"
$git push /home/git/repositories/test.git master
これで中身も出来たから、後は他のユーザでチェックする。
[test@remote]
$git clone /home/git/repositories/test.git
$cd test
$vim README
update
$git commit -m "update test" -a
$git push /home/git/repositories/test.git master
[zuqqhi2@remote]
$cd ~/test
$git pull

これでリポジトリは出来た!

nginxでHTTPアクセスできるようにする

今度はローカルからHTTPでcloneとpushを出来るようにする。

nginxとfcgiwrapをインストール

fcgiwrapでgitを動かすためにインストールする。
これも単純にapt-getでOK!
[ubuntu@remote]
$sudo apt-get install nginx fcgiwrap

configの設定

nginxのコンフィグとあと細かい設定を行う。
[ubuntu@remote]
$sudo mv /etc/nginx/sites-enabled/default /etc/nginx/sites-available/default
$sudo vim /etc/nginx/sites-available/git
server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        root /home/git;
        index index.html index.htm;

        access_log /home/git/logs/access.log;
        error_log /home/git/logs/error.log;

        # Make site accessible from http://localhost/
        server_name git.example.com;

        location /repositories {
                auth_basic "Restricted";
                auth_basic_user_file /etc/nginx/htpasswds/git;

                include /etc/nginx/fcgi_params;
                fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
                fastcgi_param GIT_PROJECT_ROOT /home/git;
                fastcgi_param GIT_HTTP_EXPORT_ALL "";
                fastcgi_param PATH_INFO $uri;
                fastcgi_param REMOTE_USER $remote_user;

                fastcgi_pass unix:/var/run/fcgiwrap.socket;
        }
        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;
}
$sudo cp /etc/nginx/sites-available/git /etc/nginx/sites-enabled/git
$sudo vim /etc/nginx/htpasswds/git
test:vtDa1cB7mCB3Q
$sudo usermod -a -G git www-data
$sudo su - git
[git@remote]
$mkdir /home/git/logs
$cd /home/git/repositories/test.git
$cp hooks/post-update.sample hooks/post-update
$git update-server-info
$git config http.receivepack true
$exit
[ubuntu@remote]
$sudo /etc/init.d/fcgiwrap stop
$sudo /etc/init.d/fcgiwrap start
$sudo /etc/init.d/nginx stop
$sudo /etc/init.d/nginx start

最後の方でhookの設定もしてる。
これでpushするとHEADが最新のになって、cloneでも最新のソースが得られる。 また、www-data(fcgiwrapの実行ユーザ)をgitに追加している。
これをしないとpushがunpack errorが起きてできない。

確認

設定完了したから後はローカルからcloneとpushが出来るか確認する。
[zuqqhi2@local]
$git clone http://git.example.com/repositories/test.git
$cd test
$vim README
push from local
$git commit -m "first push from local" -a
$git push origin master

OK!うまく行った!

gitweb

最後はgitwebをインストールするだけだ。

gitwebのインストール

apt-get installで大丈夫。
[ubuntu@remote]
$sudo apt-get install gitweb

gitweb.confの設定

gitwebの設定をする。
[ubuntu@remote]
$sudo vim /etc/gitweb.conf
# path to git projects (<project>.git)
$projectroot = "/home/git/repositories";

# directory to use for temp files
$git_temp = "/tmp";

# target of the home link on top of all pages
#$home_link = $my_uri || "/";

# html text to include at home page
#$home_text = "indextext.html";

# file with project list; by default, simply scan the projectroot dir.
#$projects_list = $projectroot;

# stylesheet to use
@stylesheets = ("static/gitweb.css");

# javascript code for gitweb
$javascript = "static/gitweb.js";

# logo to use
$logo = "static/git-logo.png";

# the 'favicon'
$favicon = "static/git-favicon.png";

# git-diff-tree(1) options to use for generated patches
#@diff_opts = ("-M");
@diff_opts = ();

nginxの設定

gitweb.cgi用のnginx設定をする。
[ubuntu@remote]
$sudo vim /etc/nginx/sites-available/git
server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        root /home/git;
        index index.html index.htm;

        access_log /home/git/logs/access.log;
        error_log /home/git/logs/error.log;

        # Make site accessible from http://localhost/
        server_name git.example.com;

        location /repositories {
                auth_basic "Restricted";
                auth_basic_user_file /etc/nginx/htpasswds/git;

                include /etc/nginx/fcgi_params;
                fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
                fastcgi_param GIT_PROJECT_ROOT /home/git;
                fastcgi_param GIT_HTTP_EXPORT_ALL "";
                fastcgi_param PATH_INFO $uri;
                fastcgi_param REMOTE_USER $remote_user;

                fastcgi_pass unix:/var/run/fcgiwrap.socket;
        }

        location /gitweb {
                auth_basic "Restricted";
                auth_basic_user_file /etc/nginx/htpasswds/git;

                index index.cgi;
                include /etc/nginx/fcgi_params;
                gzip off;

                if ($uri ~ "/gitweb/index.cgi") {
                        fastcgi_pass unix:/var/run/fcgiwrap.socket;
                }
        }

        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;
}

確認

gitweb

完成!!

リファレンス

プログラミングの最近記事

  1. PlatformIO IDE for VSCode を使用して VSCode で Ardu…

  2. ROS Docker イメージで発生した GPG error の解消方法

  3. Streamlit で訪れた国を色づけした世界地図を作成できるアプリケーションを作成してみ…

  4. M5Stack Core2 for AWS – ESP32 IoT開発キットで…

  5. D3.js v7 で点・線・テキスト・ツールチップ・ズームを設定する方法

関連記事

PAGE TOP