• 制作容器化GITWEB管理GIT仓库


    最近在RK3399上部署了GIT服务器,本来想着部署一个GITLAB的,但是太大了,后来想想部署一个简单的GITOLITE也满足小团队使用。
    于是使用GITOLITE+GITWEB的方式。

    常规安装GITWEB

    在Ubuntu下默认安装gitweb 它会把apache2也安装好。

    • 修改/etc/gitweb.conf, 修改projectroot的参数

    $projectroot = "/home/git/repositories";

    然后直接重启一下apache

    > sudo apt install gitweb
    > sudo a2enmod cgi
    > sudo systemctl restart apache2
    

    通过浏览器打开:
    http://localhot/gitweb

    问题
    如果仓库的权限存在问题,比如使用/home/git gitolite或gitosis维护的仓库,权限默认是700,这个时候,其他用户没有办法查看。为了解决这个问题。有以下方法:

    • 将现有的目录权限修改为0755, 最好使用find命令查找到目录修改

    sudo su git
    chmod -R 755 /home/git/repositories

    • 修改GIT服务创建目录的权限。

    sudo su git
    cd ~
    cat .gitolite.rc

    修改方法如下:


    进阶

    • 如何将URL中的gitweb去掉!!!
    • 如果能做成容器版本,那将方便好多,可以同时跑多个实例!!!
    • 安全性问题,最好需要登录才能访问

    第一个问题:

    sudo vi sites-available/000-default.conf
    将DocumentRoot 改为 /usr/share/gitweb
    sudo systemctl restart apache2

    重新打开即可。

    第二问题

    直接上Dockerfile

    FROM ubuntu
    MAINTAINER einsn
    RUN sed -i 's/archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
    RUN apt-get update
    RUN apt-get install -y gitweb apache2
    RUN a2enmod cgi
    RUN sed -i 's#/var/www/html#/usr/share/gitweb#g' /etc/apache2/sites-available/000-default.conf
    COPY apache-foreground /usr/sbin/
    RUN chmod a+x /usr/sbin/apache-foreground
    EXPOSE 80
    CMD ["apache-foreground"]
    

    里面用一个脚本文件apache-foreground:

    #!/bin/sh
    
    set -e
    
    # Apache gets grumpy about PID files pre-existing
    rm -f /var/run/apache2/apache2.pid
    
    exec apache2ctl -DFOREGROUND
    
    

    执行build

    docker build -t gitweb .

    默认容器内的监听的GIT目录为 /var/lib/git 所以,使用-v选项可以指定本地监听目录。
    看看能否正常运行

    docker run -d -p8100:80 -v /home/einsn/work:/var/lib/git --name gitweb gitweb

    安全,是比较重要
    这样一来,安全问题又出现了,需要增加一个安全验证,准备在这个容器基础上,创建了新的容器

    创建一个文件 digest.conf

    <Location "/">
        AuthType Digest
        AuthName "Hello,gitweb"
        AuthDigestDomain "/"
        AuthDigestProvider file
        AuthUserFile "/var/www/passwd.digest"
        require valid-user
    </Location>
    

    创建一个密码文件,记住输入的密码。

    htdigest -c passwd.digest "Hello,gitweb" einsn
    

    再创建一个Dockerfile

    FROM einsn/gitweb_arm64
    MAINTAINER einsn
    RUN cd /etc/apache2/mods-enabled && ln -s ../mods-available/auth_digest.load
    RUN sed -i 's/#ServerName/ServerName/g' /etc/apache2/sites-available/000-default.conf
    COPY digest.conf /etc/apache2/conf-enabled/
    COPY passwd.digest /var/www/
    EXPOSE 80
    CMD ["apache-foreground"]
    

    创建

    docker build -t gitweb_digest .

    我的运行脚本:(加上--restart保证一直可靠运行)

    docker run -d -p8100:80 -v /home/git/repositories:/var/lib/git --restart always --name gitweb_all einsn/gitweb_arm64

    通过docker化GITWEB,可以轻易的部署在不同的设备上。

  • 相关阅读:
    perl get请求发送json数据
    一招教你玩转SQL:通过找出数据的共同属性实现SQL需求
    Uncaught (in promise) Error: Component series.map not exists. Load it first
    python post 参数
    python 发送json数据
    毫秒级从百亿大表任意维度筛选数据,是怎么做到的…
    python 日期处理
    python urlencode urldecode
    在服务器本地监控服务端口命令之ss
    在服务器本地监控服务端口命令之ss
  • 原文地址:https://www.cnblogs.com/eehut/p/12672940.html
Copyright © 2020-2023  润新知