This commit is contained in:
2022-04-18 11:21:20 +08:00
commit 45a7af638f
210 changed files with 8997 additions and 0 deletions

76
gitea/ADD/ccmd Executable file
View File

@@ -0,0 +1,76 @@
#!/bin/bash
##################################################
# Mount dir #
# - /var/lib/gitea #
# - /var/log/gitea #
##################################################
set -euo pipefail
export LANG=en_US.UTF-8
trap Quit EXIT
PIDS=
GOT_SIGTERM=
function Print {
local file=/dev/null
[ '-f' = "$1" ] && file=$2 && shift && shift
date +"[%F %T] $*" | tee -a $file
}
function Quit {
while :; do
pkill -f gitea && Print killing gitea ... || break
sleep 1
done
Print Container stopped.
test -n "$GOT_SIGTERM"
}
function Usage {
Print 'This container should run with
**root user**
**/var/{lib,log}/gitea mounted from host**
'
}
function RestoreConf {
if [ -z "$(ls gitea/)" ]; then
Print Restore default config files and quit ...
tar zxf gitea.tgz
exit
fi
}
function ChangeOwner {
Print Change file owner ...
chown -R gitea.www-data gitea/ /var/log/gitea/
}
function StartProc {
Print Start gitea ...
su - gitea -c '
gitea web --config /var/lib/gitea/custom/conf/app.ini
' &>> /var/log/gitea/gitea.out &
PIDS="$PIDS $!"
}
function Main {
local pid=
cd /var/lib
Usage
RestoreConf
ChangeOwner
StartProc
trap "GOT_SIGTERM=1; Print Got SIGTERM ..." SIGTERM
while [ -z "$GOT_SIGTERM" ] && sleep 1; do
for pid in $PIDS; do
[ ! -e /proc/$pid ] && Print Unexpected error! && exit
done
done
}
# Start here
Main

View File

@@ -0,0 +1,59 @@
# 部署 gitea, 由 nginx 反代
- 配合 nginx 反代,并单独挂载 indexers 目录
- 根据实际环境修改
- docker-compose.yml
- 创建目录
```
grep '\<source:' docker-compose.yml | cut -d: -f2 | xargs mkdir -p
mkdir -p -m 0777 socket
```
- 启动
```
docker-compose up -d
```
- 运行 gitea
```
docker-compose up -d gitea
```
- 停止 gitea
```
docker-compose down -v
```
- 修改 gitea 配置文件 /compose/gitea/gitea/custom/conf/app.ini
```
[indexer]
...
ISSUE_INDEXER_TYPE = bleve
ISSUE_INDEXER_PATH = /indexers/issues.bleve
ISSUE_INDEXER_QUEUE_TYPE = levelqueue
ISSUE_INDEXER_QUEUE_DIR = /indexers/issues.queue
REPO_INDEXER_ENABLED = true
REPO_INDEXER_PATH = /indexers/repos.bleve
UPDATE_BUFFER_LEN = 20
MAX_FILE_SIZE = 1048576
REPO_INDEXER_INCLUDE = **.go,**.yml,**.toml,**.c,**.h,**makefile,**.py,**.txt,**.ini,**.rs,**.sh,**.md,**Dockerfile*,**docker-entrypoint*,**.cnf,**.conf,**.json,**.sql,**.xml,**.js,**.jsx,**.vue,**.ts,**.tsx,**.html,**.css,**.scss,**.less
...
[server]
...
PROTOCOL = unix
DOMAIN = git.xxxx.com
ROOT_URL = http://git.xxxx.com
HTTP_ADDR = /socket/gitea
UNIX_SOCKET_PERMISSION = 666
...
```
- 运行
```
docker-compose up -d
```
- 浏览器访问 http://git.xxxx.com

View File

@@ -0,0 +1,48 @@
version: "3.7"
services:
gitea:
image: harbor.colben.cn/general/gitea
container_name: gitea
restart: on-failure
stop_grace_period: 1m
networks:
gitea:
volumes:
- type: bind
source: ./gitea/gitea
target: /var/lib/gitea
- type: bind
source: ./gitea/log
target: /var/log/gitea
- type: bind
source: ./gitea/indexers
target: /indexers
- type: bind
source: ./socket
target: /socket
nginx:
image: harbor.colben.cn/general/nginx
container_name: nginx
restart: on-failure
stop_grace_period: 1m
networks:
gitea:
ports:
- 80:80
volumes:
- type: bind
source: ./nginx/http.d
target: /etc/nginx/http.d
- type: bind
source: ./nginx/log
target: /var/log/nginx
- type: bind
source: ./socket
target: /socket
networks:
gitea:
external: false

View File

@@ -0,0 +1,12 @@
server {
listen 80;
server_name git.xxxx.com;
access_log off;
error_log /var/log/nginx/error-gitea.log;
location / {
proxy_pass http://unix:/socket/gitea;
client_max_body_size 1024m;
client_body_buffer_size 1024m;
}
}

View File

@@ -0,0 +1,17 @@
# 部署 gitea
- 根据实际环境修改
- docker-compose.yml
- 创建目录
```
grep '\<source:' docker-compose.yml | cut -d: -f2 | xargs mkdir -p
```
- 启动
```
docker-compose up -d
```
- 访问 http://x.x.x.x:3000

View File

@@ -0,0 +1,18 @@
version: "3.7"
services:
gitea:
image: harbor.colben.cn/general/gitea
container_name: gitea
restart: "on-failure"
stop_grace_period: 1m
ports:
- 3000:3000
volumes:
- type: bind
source: ./gitea/gitea
target: /var/lib/gitea
- type: bind
source: ./gitea/log
target: /var/log/gitea

13
gitea/Dockerfile Normal file
View File

@@ -0,0 +1,13 @@
ARG ARCH
FROM harbor.colben.cn/general/alpine$ARCH
MAINTAINER Colben colbenlee@gmail.com
ADD --chown=root:root /ADD/ /opt/
RUN apk update \
&& apk add --no-cache gitea \
&& sed -i 's,/ash,/bash,' /etc/passwd \
&& cd /var/lib \
&& mv /etc/gitea gitea/custom/conf \
&& tar zcf gitea.tgz gitea/ \
&& rm -rf /var/cache/apk/* gitea/*
CMD ["/opt/ccmd"]

13
gitea/README.md Normal file
View File

@@ -0,0 +1,13 @@
# 构建 gitea 镜像
## 定制
- 安装 gitea
## 外挂目录和文件
- /var/lib/gitea: gitea 数据目录
- /var/log/gitea: gitea 日志目录
## 案例
- [Demo/SingleNode/](Demo/SingleNode/): 单独部署 gitea
- [Demo/GiteaWithNginx/](Demo/GiteaWithNginx/): 部署 gitea用 nginx 反代

67
gitea/gitea.sh Executable file
View File

@@ -0,0 +1,67 @@
#!/bin/bash
#=========================================
# Author : colben
#=========================================
set -euo pipefail
export LANG=en_US.UTF-8
trap Quit EXIT
[ 'x86_64' == "$(uname -m)" ] && ARCH='' || ARCH="-$(uname -m)"
ROOT_DIR="$(cd $(dirname $0) && pwd)"
IMAGE="harbor.colben.cn/general/$(basename ${0%.sh})$ARCH:latest"
if [ -t 0 ]; then
function Print { echo -e "\033[36;1m$(date +'[%F %T]')\033[32;1m $*\033[0m"; }
function Warn { echo -e "\033[36;1m$(date +'[%F %T]')\033[33;1m $*\033[0m"; }
function Error { echo -e "\033[36;1m$(date +'[%F %T]')\033[31;1m $*\033[0m"; exit 1; }
else
function Print { echo -e "$(date +'[%F %T INFO]') $*"; }
function Warn { echo -e "$(date +'[%F %T WARN]') $*"; }
function Error { echo -e "$(date +'[%F %T ERROR]') $*"; exit 1; }
fi
function Quit {
local exitCode=$?
[ 0 -ne $exitCode ] && Error Failed to build or push image!
[ -z "${END:-}" ] && echo && Error Interrupted manually!
Print Succeeded to build and push image.
}
function YesOrNo {
Warn $*
local sw=
while :; do
read -p '(Yes/No/Quit) ' -n1 sw
[[ "$sw" =~ ^Y|y$ ]] && echo && return 0
[[ "$sw" =~ ^N|n$ ]] && echo && return 1
[[ "$sw" =~ ^Q|q$ ]] && echo && exit 0
[ -n "$sw" ] && echo
done
}
function Update {
:
}
function Build {
local yn
cd $ROOT_DIR
docker images --format='{{.Repository}}:{{.Tag}}' | grep "^$IMAGE$" \
&& Warn Removing image $IMAGE ... \
&& docker rmi $IMAGE
Warn Building image: $IMAGE ...
docker build --force-rm --build-arg ARCH="$ARCH" -t $IMAGE .
YesOrNo Push image: $IMAGE? && docker push $IMAGE
}
function Main {
Update
Build
END=1
}
# Start here
Main