Skip to content

Commit

Permalink
release v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nfort committed Dec 25, 2024
1 parent e458023 commit 34a1d7d
Show file tree
Hide file tree
Showing 18 changed files with 766 additions and 67 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
gopher-bot
BUILD.md
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 Kirill
Copyright (c) 2024 Kirill Malyakin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
152 changes: 150 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,102 @@
<div align="center">

# gopher-bot

Бот для проверки Pull Request's в Gitea

<h4>
<a href="#-установка">Установка</a>
·
<a href="#-разработка">Разработка</a>
</h4>

![alt text](https://github.com/nfort/gopher-bot/blob/main/screenshot.png?raw=true)

## Разработка
</div>

## ✨ Возможности

- Компиляция кода и проверка на ошибки сборки
- Запуск линтера
- Запуск автоматизированных тестов для проверки работоспособности кода
- Анализ покрытия кода тестами
- Может выполнять команды из Makefile (make build, lint, test)

## 📦 Установка

Для начала настройте Gitea

Для доступа к хуку нужно добавить
Убедитесь что Gitea позволят взаймодействовать с ботом,
для этого в конфиге должна быть прописана директива `ALLOWED_HOST_LIST` с хостом, на котором развернут gopher-bot.

```bash
cat << EOF >> /etc/gitea/app.ini
[webhook]
ALLOWED_HOST_LIST = *
EOF
```
1. Для всех репозиторий, где вы хотите использовать gopher-bot, откройте настройки webhook репозитория и создайте новый `Gitea` webhook (Trigger On and Branch filter depend on what you would like to use, of course)
* Target URL: URL на котором развернут gopher-bot, вместе `/hook` сегментом (`http://gopher-bot:8080/hook`)
* HTTP Method: `POST`
* POST Content Type: `application/json`
* Secret: the secret your [config](#config) contains
* Trigger On: Custom Events...
* Pull Request Events
* Pull Request
* Pull Request Synchronized
* Branch filter: `*`
* Active: ✅
2. Добавить пользователя gopher-bot c токеном c правами на repo
2. Добавить пользователя gopher-bot в репозиторий
3. Установите gopher-bot

Можно выполнить установка двумя способа: Docker или бинарник

### Docker

На машине выполнить команды, указав gitea_host, token пользователя gopher-bot и secret

```bash
docker volume create gopher-bot_config
docker volume create gopher-bot_var
docker run -it --rm -v gopher-bot_config:/etc/gopher-bot busybox sh -c 'cat << EOF >> /etc/gopher-bot/config.ini
[tokens]
"[gitea_host]"=gopher-bot:[token]
[server]
DEBUG_MODE=true
SECRET=[SECRET]'
docker run --restart always -p 8080:8080 -v gopher-bot_config:/etc/gopher-bot -v gopher-bot_var:/var/gopher-bot --name gopher-bot nfort/gopher-bot:1.0.0
```

### Бинарник

Соберите или загрузите бинарник из релиза

```bash
CGO_ENABLED=0 GOOS=linux go build -o /gopher-bot cmd/main.go
```

Добавьте конфиг файл

```bash
cat << EOF >> /etc/gopher-bot/config.ini
[tokens]
"http://[gitea_host]:[gitea_port]"=gopher-bot:[token]
[server]
DEBUG_MODE=true
SECRET=[secret]
```
Добавьте бинарник на сервер и запустите.
Если вы используете golangci-lint или другие инструменты в качестве зависимостей проекта, их также следует установить на сервер.
## 🚀 Разработка
После запуска `docker compose up`, нужно остановить.
1. Выполнить команду
```bash
docker run -it --rm -v gitea_gitea-config:/etc/gitea busybox sh -c 'cat << EOF >> /etc/gitea/app.ini
Expand All @@ -13,3 +105,59 @@ ALLOWED_HOST_LIST = *
EOF'
```
2. При настройки Gitea указать `gitea:3000` вместо `localhost:3000` в качестве хоста.
Добавить пользотеля `gopher-bot`, добавить токен с правами на repo.
Скопировать токен
```bash
docker volume create gopher-bot_config
docker volume create gopher-bot_var
docker run -it --rm -v gopher-bot_config:/etc/gopher-bot busybox sh -c 'cat << EOF >> /etc/gopher-bot/config.ini
[tokens]
"http://gitea:3000"=gopher-bot:[token]
[server]
DEBUG_MODE=true
SECRET=iNeydroTioUC'
docker run --restart always -p 8080:8080 -v gopher-bot_config:/etc/gopher-bot -v gopher-bot_var:/var/gopher-bot --name gopher-bot nfort/gopher-bot:1.0.0
```
3. Добавить webhook для репозитория
4. Указать SECRET
5. В качестве хоста указать `gopher-bot:8080/hooks`
6. Дать права на PR, PR Synchronize
7. Добавить пользователя gopher-bot в репозиторий
## Как добавить gopher-bot в systemd
```bash
cat << EOF >> /etc/systemd/system/gopher-bot.service
[Unit]
Description=gopher-bot
[Service]
Environment="HOME=/root"
Environment="GOPATH=/root/.go"
Environment="GOCACHE=/root/.go-cache"
ExecStart=/opt/gopher-bot/gopher-bot
Restart=always
StandardOutput=append:/var/log/gopher-bot.log
StandardError=append:/var/log/gopher-bot.log
[Install]
WantedBy=multi-user.target
EOF
```

Выполнить перезагрузку systemd

```bash
systemctl daemon-reload
```

Добавить сервис в systemd

```bash
systemctl enable gopher-bot
```
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/gin-gonic/gin"
)

const VERSION = "v1.0.6"
const VERSION = "v1.1.0"

func main() {
if err := config.InitConfig(); err != nil {
Expand Down
34 changes: 0 additions & 34 deletions deployments/gitea/README.md

This file was deleted.

28 changes: 28 additions & 0 deletions deployments/gitea/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ volumes:
gopher-bot_config:
external: true
name: gopher-bot_config
gopher-bot_var:
external: true
name: gopher-bot_var
gopher-bot_ssh:
external: true
name: gopher-bot_ssh
Expand All @@ -17,6 +20,15 @@ services:
gitea:
image: gitea/gitea:latest-rootless
userns_mode: keep-id:uid=1000,gid=1000
container_name: gitea
environment:
- USER_UID=1000
- USER_GID=1000
- GITEA__database__DB_TYPE=mysql
- GITEA__database__HOST=db:3306
- GITEA__database__NAME=gitea
- GITEA__database__USER=gitea
- GITEA__database__PASSWD=gitea
restart: always
volumes:
- gitea:/var/lib/gitea
Expand All @@ -28,6 +40,21 @@ services:
- "2222:2222"
networks:
- gitea-network
depends_on:
- db

db:
image: mysql:8
restart: always
environment:
- MYSQL_ROOT_PASSWORD=gitea
- MYSQL_USER=gitea
- MYSQL_PASSWORD=gitea
- MYSQL_DATABASE=gitea
networks:
- gitea-network
volumes:
- ./mysql:/var/lib/mysql - gitea-network

gopher-bot:
build:
Expand All @@ -36,6 +63,7 @@ services:
restart: always
volumes:
- gopher-bot_config:/etc/gopher-bot
- gopher-bot_var:/var/gopher-bot
ports:
- "8080:8080"
networks:
Expand Down
30 changes: 23 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ require (
github.com/gin-gonic/gin v1.8.2
github.com/go-git/go-git/v5 v5.5.2
gopkg.in/ini.v1 v1.67.0
modernc.org/sqlite v1.34.2
xorm.io/xorm v1.3.9
)

require (
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230117203413-a47887b8f098 // indirect
github.com/acomagu/bufpipe v1.0.3 // indirect
github.com/cloudflare/circl v1.3.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
Expand All @@ -22,28 +25,41 @@ require (
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.11.1 // indirect
github.com/goccy/go-json v0.10.0 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/ncruces/go-strftime v0.1.9 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pjbgf/sha1cd v0.2.3 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/skeema/knownhosts v1.1.0 // indirect
github.com/syndtr/goleveldb v1.0.0 // indirect
github.com/ugorji/go/codec v1.2.8 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
golang.org/x/crypto v0.5.0 // indirect
golang.org/x/mod v0.7.0 // indirect
golang.org/x/net v0.5.0 // indirect
golang.org/x/sys v0.4.0 // indirect
golang.org/x/text v0.6.0 // indirect
golang.org/x/tools v0.5.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.19.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 // indirect
modernc.org/libc v1.55.3 // indirect
modernc.org/mathutil v1.6.0 // indirect
modernc.org/memory v1.8.0 // indirect
modernc.org/strutil v1.2.0 // indirect
modernc.org/token v1.1.0 // indirect
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978 // indirect
)
Loading

0 comments on commit 34a1d7d

Please sign in to comment.