言成言成啊 | Kit Chen's Blog

Gitblit迁移Gitea

发布于2022-09-06 23:25:09,更新于2024-04-15 14:47:24,标签:devops git hexo  转载随意,文章会持续修订,请注明来源地址:https://meethigher.top/blog

在给甲方讲述svn和git的区别时,发现对svn了解不太够,以至于两者的区别没说清楚,此处简单记录下。

Git与SVN都是常见的版本控制系统,区别如下

  1. 分布式 vs 集中式

    • Git是一种分布式版本控制系统。每个机器都有独立的仓库,即使没有网络也可以进行同步操作。
    • SVN是一种集中式版本控制系统。所有代码都存储在中央服务器上,开发者通过客户端与中央服务器进行交互。
  2. 分支模型

    • Git鼓励频繁地创建和合并分支,因为分支的创建和合并操作非常轻量级。
    • SVN的分支操作较重,创建和合并分支均需在服务器上进行,会占用较多的服务器资源。
  3. 提交模型

    • Git使用快照模型。每次提交都会保存文件状态的快照,这意味着每次提交都是一个完整的文件快照。
    • SVN使用增量模型,每次提交只会记录文件的变化,这意味着每个提交只包含发生变化的文件差异。
  4. 性能

  • Git在大型项目中性能表现通常比SVN更好,因为Git的分布式性质,就减少了与中央服务器的交互。
    • SVN在处理大型文件和代码库时,会严重占用中央服务器的资源。

Gitblit、Gitlab、Gitea,之前一直使用的Gitblit,相对来说,是目前所有GitServer中,最具性价比的。

但是后来服务器也更换了,所以就想找一个性价比次高的平台,那就是Gitea了。

一、安装

官网链接从二进制安装 - Docs

首先Gitea需要git版本2以上的,Centos7默认自带的是git1.8,所以需要更新yum存储库。

1
2
3
yum -y install \
https://repo.ius.io/ius-release-el7.rpm \
https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

搜索Git并安装合适版本

1
2
3
yum search git|grep 'Fast Version Control System'
yum -y install git236
git --version

下载并安装gitea

1
2
3
4
5
6
7
8
9
10
11
curl -L -o /usr/local/bin/gitea https://dl.gitea.io/gitea/1.17.1/gitea-1.17.1-linux-amd64
chmod +x gitea
useradd git
# userdel -rf git
# 创建结构
mkdir -p /var/lib/gitea/{custom,data,log}
chown -R git:git /var/lib/gitea/
chmod -R 750 /var/lib/gitea/
mkdir /etc/gitea
chown root:git /etc/gitea
chmod 770 /etc/gitea

安装完成之后,需要将gitea配置成服务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
cat > /usr/lib/systemd/system/gitea.service <<EOF
[Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target
###
# Don't forget to add the database service dependencies
###
#
#Wants=mysql.service
#After=mysql.service
#
#Wants=mariadb.service
#After=mariadb.service
#
#Wants=postgresql.service
#After=postgresql.service
#
#Wants=memcached.service
#After=memcached.service
#
#Wants=redis.service
#After=redis.service
#
###
# If using socket activation for main http/s
###
#
#After=gitea.main.socket
#Requires=gitea.main.socket
#
###
# (You can also provide gitea an http fallback and/or ssh socket too)
#
# An example of /etc/systemd/system/gitea.main.socket
###
##
## [Unit]
## Description=Gitea Web Socket
## PartOf=gitea.service
##
## [Socket]
## Service=gitea.service
## ListenStream=<some_port>
## NoDelay=true
##
## [Install]
## WantedBy=sockets.target
##
###

[Service]
# Modify these two values and uncomment them if you have
# repos with lots of files and get an HTTP error 500 because
# of that
###
#LimitMEMLOCK=infinity
#LimitNOFILE=65535
RestartSec=2s
Type=simple
User=git
Group=git
WorkingDirectory=/var/lib/gitea/
# If using Unix socket: tells systemd to create the /run/gitea folder, which will contain the gitea.sock file
# (manually creating /run/gitea doesn't work, because it would not persist across reboots)
#RuntimeDirectory=gitea
ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini
Restart=always
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea
# If you install Git to directory prefix other than default PATH (which happens
# for example if you install other versions of Git side-to-side with
# distribution version), uncomment below line and add that prefix to PATH
# Don't forget to place git-lfs binary on the PATH below if you want to enable
# Git LFS support
#Environment=PATH=/path/to/git/bin:/bin:/sbin:/usr/bin:/usr/sbin
# If you want to bind Gitea to a port below 1024, uncomment
# the two values below, or use socket activation to pass Gitea its ports as above
###
#CapabilityBoundingSet=CAP_NET_BIND_SERVICE
#AmbientCapabilities=CAP_NET_BIND_SERVICE
###
# In some cases, when using CapabilityBoundingSet and AmbientCapabilities option, you may want to
# set the following value to false to allow capabilities to be applied on gitea process. The following
# value if set to true sandboxes gitea service and prevent any processes from running with privileges
# in the host user namespace.
###
#PrivateUsers=false
###

[Install]
WantedBy=multi-user.target
EOF

之后就正常作为服务操作

1
systemctl start|stop|restart|status|enable|disable gitea

二、Hook钩子

使用Git的Hook钩子,实现push操作后,服务器自动将上传内容部署到博客的路由下。

由于使用Gitblit习惯了,找了半天Gitea上面,都没找到hooks,原来是需要直接在仓库下面配置。而不是其他平台在网页配置。

以我仓库为例

1
cd /var/lib/gitea/data/gitea-repositories/meethigher/blog.git/hooks/post-receive.d

创建一个push后要触发的hook钩子脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
cat > /var/lib/gitea/data/gitea-repositories/meethigher/blog.git/hooks/post-receive.d/post-receive <<EOF
#!/usr/bin/env bash
repo_dir=/var/lib/gitea/data/gitea-repositories/meethigher/blog.git
blog_dir=/var/lib/gitea/data/gitea-repositories/meethigher/blog
web_dir=/site/web/youarebitch/
rm -rf \${blog_dir}
echo "delete bak"
git clone \${repo_dir} \${blog_dir}
echo "clone into bak"
rm -rf \${web_dir}blog/*
echo "delete old blog"
cp -rf \${blog_dir} \${web_dir}
echo "copy bak into new blog"
echo "success"
EOF

一定要添加执行权限

1
chmod +x /var/lib/gitea/data/gitea-repositories/meethigher/blog.git/hooks/post-receive.d/post-receive

然后重启gitea

1
systemctl restart gitea

push上传测试一下,查看git服务端返回内容

三、参考

IUS - YUM存储库

从二进制安装 - Docs

使用 Gitea + Git Hook 实现 Hexo 博客源码托管与持续集成 | 朝花夕拾

Hexo使用Git部署到Windows

发布:2022-09-06 23:25:09
修改:2024-04-15 14:47:24
链接:https://meethigher.top/blog/2022/gitea/
标签:devops git hexo 
付款码 打赏 分享
shift+ctrl+1可控制目录显示