高渐离の屋

一个不起眼的个人小站

0%

搭建自己的Git

前言

事情的起因非常简单,得益于某位校长的功劳,我的网络访问 Github 奇慢无比,最近甚至出现了 push 失败的情况,我连博客都没法好好更新了!(说的好像你更新得很多一样)
嘛,正好潇在给我孜孜不倦地推荐Gitea,我就来试试在树莓派上搭建一下吧。
首先我们来看官方文档:

易安装
您除了可以根据操作系统平台通过 二进制运行,还可以通过 Docker 或 Vagrant,以及 包管理 安装。

嚯,挺厉害嘛,那就图个省事,用 Docker 安装吧。然而这之后我才知道,这是地狱的开始。

Docker 试探

安装

官方的教程非常的简单,看起来就和能用一样

我们在 Docker Hub 的 Gitea 组织中提供了自动更新的 Docker 镜像,它会保持最新的稳定版。你也可以用其它 Docker 服务来更新。首先你需要 pull 镜像:

1
2
3
docker pull gitea/gitea:latest
sudo mkdir -p /var/lib/gitea //如果要将git和其它数据持久化,你需要创建一个目录来作为数据存储的地方
docker run -d --name=gitea -p 10022:22 -p 10080:3000 -v /var/lib/gitea:/data gitea/gitea:latest //然后就可以运行 docker 容器了,这很简单。 当然你需要定义端口数数据目录:

这时候我才发现我根本就没有安装 docker,赶紧 apt 解决:

1
apt install docker

然后开始 pull,这时又要忍受国内网络的龟速:

1
2
3
4
5
6
7
8
9
10
docker pull gitea/gitea:latest
latest: Pulling from gitea/gitea
911c6d0c7995: Pull complete
fe8708a98e1d: Pull complete
754e5dc9c218: Pull complete
99ffba26b3d3: Pull complete
ee04a0c4cde1: Pull complete
78a8e5235d3e: Pull complete
Digest: sha256:6f28b3e5127f29f614b765738cf5e4d673b1a0762d42c095323433c26eef779d
Status: Downloaded newer image for gitea/gitea:latest

受阻

尝试运行一下

1
2
3
# root @ rasp in ~ [14:46:44]
$ docker run -d --name=gitea -p 10022:22 -p 10080:3000 -v /mnt/disk/Git:/data gitea/gitea:latest
ee43cb4883e4d6e75f0eea1c8b90988880c1569b7088bc1f072274f2a2eaf4dc

没有回显,不过还是先看看容器跑起来没有:

1
2
3
# root @ rasp in ~ [14:46:54]
$ docker logs gitea
standard_init_linux.go:185: exec user process caused "exec format error"

喵喵喵?这尼玛是啥?看起来好像是可执行文件架构不对。。

原因分析

兔角龟毛,总之先 inspect 一下吧

1
2
# root @ rasp in ~ [14:55:17]
$ docker inspect gitea/gitea:latest

得到如下结果:

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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
[
{
"Id": "sha256:67ff9596dc004fdbbd87289f854ef8fb2920ab66621155117f618290457f42c9",
"RepoTags": ["gitea/gitea:latest"],
"RepoDigests": [
"gitea/gitea@sha256:6f28b3e5127f29f614b765738cf5e4d673b1a0762d42c095323433c26eef779d"
],
"Parent": "",
"Comment": "",
"Created": "2018-07-12T14:14:03.941666864Z",
"Container": "9c524fa2972be8a9c2e777219e07bdb23c8a21a18cff8d7884f2df6c95795948",
"ContainerConfig": {
"Hostname": "9c524fa2972b",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"22/tcp": {},
"3000/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"USER=git",
"GITEA_CUSTOM=/data/gitea"
],
"Cmd": [
"/bin/sh",
"-c",
"#(nop) ",
"LABEL org.label-schema.build-date=2018-07-12T14:11:41Z org.label-schema.vcs-ref=659bc727bd12bf219d80d38d8b634bd578ddb84f org.label-schema.vcs-url=https://github.com/go-gitea/gitea.git"
],
"ArgsEscaped": true,
"Image": "sha256:5789f396c54923dbf5643737a149337f5fc0c1fd0cc186f41ecc30c96b300e9a",
"Volumes": {
"/data": {}
},
"WorkingDir": "",
"Entrypoint": ["/usr/bin/entrypoint"],
"OnBuild": null,
"Labels": {
"maintainer": "maintainers@gitea.io",
"org.label-schema.build-date": "2018-07-12T14:11:41Z",
"org.label-schema.vcs-ref": "659bc727bd12bf219d80d38d8b634bd578ddb84f",
"org.label-schema.vcs-url": "https://github.com/go-gitea/gitea.git"
}
},
"DockerVersion": "17.12.0-ce",
"Author": "",
"Config": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"22/tcp": {},
"3000/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"USER=git",
"GITEA_CUSTOM=/data/gitea"
],
"Cmd": ["/bin/s6-svscan", "/etc/s6"],
"ArgsEscaped": true,
"Image": "sha256:5789f396c54923dbf5643737a149337f5fc0c1fd0cc186f41ecc30c96b300e9a",
"Volumes": {
"/data": {}
},
"WorkingDir": "",
"Entrypoint": ["/usr/bin/entrypoint"],
"OnBuild": null,
"Labels": {
"maintainer": "maintainers@gitea.io",
"org.label-schema.build-date": "2018-07-12T14:11:41Z",
"org.label-schema.vcs-ref": "659bc727bd12bf219d80d38d8b634bd578ddb84f",
"org.label-schema.vcs-url": "https://github.com/go-gitea/gitea.git"
}
},
"Architecture": "amd64",
"Os": "linux",
"Size": 75448364,
"VirtualSize": 75448364,
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/9fce26ccc4b7e0aefe663ecb165615aadda2d2437b3ab7cafab599de5d055736/diff:/var/lib/docker/overlay2/a0cf2ef094b8fb958037aff40de9cf54cd2c1be580fbe2fe592b5839e1a08cd5/diff:/var/lib/docker/overlay2/29e0cfce429c5eba2e674761d6a27dc914a2432a5b87c4eb7168623f62f0ed35/diff:/var/lib/docker/overlay2/b37847000ccdd55f5acd0ea549f16073da142458dd7e1cc1487d5ce2ea944611/diff:/var/lib/docker/overlay2/c1e252414cf059e505f719e559a35d5635608c136cdac00bce2ecba73dbf5111/diff",
"MergedDir": "/var/lib/docker/overlay2/196a454e1b7f7f5f0424e1afefd7a5b1b07edce529dca3f5b8a6a591f51de02f/merged",
"UpperDir": "/var/lib/docker/overlay2/196a454e1b7f7f5f0424e1afefd7a5b1b07edce529dca3f5b8a6a591f51de02f/diff",
"WorkDir": "/var/lib/docker/overlay2/196a454e1b7f7f5f0424e1afefd7a5b1b07edce529dca3f5b8a6a591f51de02f/work"
},
"Name": "overlay2"
},
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:717b092b8c86356cf976d9c83fa6f0ea67f2bf3148a5bbb7e02026a5d3245e68",
"sha256:0c8bc7fe995df099706fa9de6efe8780873009fa9bd88c1d061a9da42208ce3d",
"sha256:934a2cc01616c95aceffe2f7c906d0608e3d3e69d6c315e6b35980138b72bfa6",
"sha256:13f47d251abf8fb04b518a7f78a626d3aa8edd19690cec8158972ad6297866a7",
"sha256:5e395242ed599a17ffa4225218344a6ac2c336ba774be69ef59d5a4323f0a1e9",
"sha256:dd6e07b2f31502448541c62eb16a27958f3a8cb91fafa8010961a72b209ccc43"
]
},
"Metadata": {
"LastTagTime": "0001-01-01T00:00:00Z"
}
}
]

进入到 LowerDir 看一下?

1
2
3
# root @ rasp in /var/lib/docker/overlay2/9fce26ccc4b7e0aefe663ecb165615aadda2d2437b3ab7cafab599de5d055736/diff/app/gitea [15:18:01]
$ ls
gitea

只有一个执行文件,这时候需要请出 file 大法了

1
2
3
# root @ rasp in /var/lib/docker/overlay2/9fce26ccc4b7e0aefe663ecb165615aadda2d2437b3ab7cafab599de5d055736/diff/app/gitea [15:18:02]
$ file gitea
gitea: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-x86_64.so.1, stripped

やっぱり!™ 这个文档谁写的!头伸过来,看我不来给你加个 bug,你写这个文档的时候就没考虑过其他架构的 CPU 的感受么!你是不是看不起 ARM!!

最后的挣扎

嘛,既然这样了,摆在我面前也就三条路:

  1. 制作基于 ARM64 的 docker 容器
  2. 放弃 docker
  3. 玩一些骚操作
    首先来看看骚操作,既然它的运行依靠的是单文件,那我如果下载 arm64 的二进制文件手动替换,不就可以运行了么?
    但是事实狠狠的打了我的脸,前面的替换进行地很顺利,直到…
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
root@rasp:/var/lib/docker/overlay2# cd b37847000ccdd55f5acd0ea549f16073da142458dd7e1cc1487d5ce2ea944611/diff/bin/
root@rasp:/var/lib/docker/overlay2/b37847000ccdd55f5acd0ea549f16073da142458dd7e1cc1487d5ce2ea944611/diff/bin# ls
background fdreserve multisubstitute s6-fdholder-list s6-ipcserver s6-svlisten1
backtick fdswap pipeline s6-fdholder-listc s6-ipcserver-access s6-svok
bash forbacktickx piperw s6-fdholder-retrieve s6-ipcserverd s6-svscan
bashbug foreground redirfd s6-fdholder-retrievec s6-ipcserver-socketbinder s6-svscanctl
cd forstdin runblock s6-fdholder-setdump s6lockd s6-svstat
define forx s6-accessrules-cdb-from-fs s6-fdholder-setdumpc s6-log s6-svwait
dollarat getcwd s6-accessrules-fs-from-cdb s6-fdholder-store s6-mkfifodir s6-tai64n
elgetopt getpid s6-applyuidgid s6-fdholder-storec s6-notifyoncheck s6-tai64nlocal
elgetpositionals heredoc s6-cleanfifodir s6-fdholder-transferdump s6-setlock shift
elglob homeof s6-connlimit s6-fdholder-transferdumpc s6-setsid trap
emptyenv if s6-envdir s6-fghack s6-setuidgid tryexec
exec ifelse s6-envuidgid s6-ftrig-listen s6-softlimit ucspilogd
execlineb ifte s6-fdholderd s6-ftrig-listen1 s6-sudo umask
exit ifthenelse s6-fdholder-daemon s6-ftrig-notify s6-sudoc unexport
export import s6-fdholder-delete s6-ftrigrd s6-sudod wait
fdblock importas s6-fdholder-deletec s6-ftrig-wait s6-supervise withstdinas
fdclose loopwhilex s6-fdholder-getdump s6-ioconnect s6-svc
fdmove multidefine s6-fdholder-getdumpc s6-ipcclient s6-svlisten
root@rasp:/var/lib/docker/overlay2/b37847000ccdd55f5acd0ea549f16073da142458dd7e1cc1487d5ce2ea944611/diff/bin# file bash
bash: ELF 64-bit LSB pie executable x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-x86_64.so.1, stripped

惹不起,惹不起,告辞!
至于编译,我实在不想弄,理由如下:
首先,有了上次编译驱动的经历之后,我是再也不想在树莓派上编译任何东西了。且不说 CPU 的弱鸡,光是内存不足就足够你喝一壶的。至于交叉编译?不好意思,编译之神 Baymax 持续掉线中。

二进制安装

那就只有来二进制文件了。
嘛,这个就没啥说的了,直接参照官方教程就好了。
配置文件随便根据官网改改就好,这里就不贴出来。

最终效果

Gitea
嘛,就是这样,试过了速度还行。还拥有镜像功能,可以自动追踪某一个远程仓库,以后有啥小项目就决定是你了!
では、諸君は。