- Code compilation and build error checks
- Running a linter
- Running automated tests to check code functionality
- Code coverage analysis
- Executing commands from Makefile (e.g., make build, lint, test)
Make sure that Gitea allows interaction with the bot. For this, the ALLOWED_HOST_LIST
directive should be specified in the configuration with the host where gopher-bot is deployed:
cat << EOF >> /etc/gitea/app.ini
[webhook]
ALLOWED_HOST_LIST = *
EOF
- For each repository where you want to use gopher-bot, open the webhook settings and create a new Gitea webhook:
- Target URL: The URL where gopher-bot is deployed with the
/hook
segment (http://gopher-bot:8080/hook
) - HTTP Method:
POST
- POST Content Type:
application/json
- Secret: the secret your config contains
- Trigger On: Custom Events...
- Pull Request Events
- Pull Request
- Pull Request Synchronized
- Pull Request Events
- Branch filter:
*
- Active: ✅
- Target URL: The URL where gopher-bot is deployed with the
- Add the gopher-bot user with a token and repository rights.
- Add the gopher-bot user to the repository.
- Install gopher-bot.
Installation can be done in two ways: via Docker or using a binary.
On the machine, execute the commands, specifying gitea_host, the gopher-bot user token, and the secret:
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
Build or download the binary from the release page:
CGO_ENABLED=0 GOOS=linux go build -o gopher-bot cmd/main.go
Add the configuration:
cat << EOF >> /etc/gopher-bot/config.ini
[tokens]
"http://[gitea_host]:[gitea_port]"=gopher-bot:[token]
[server]
DEBUG_MODE=true
SECRET=[secret]
Add the binary to the server and run it. If your project dependencies include tools like golangci-lint, ensure they are installed on the server.
After running docker compose up
, you need to stop the container.
- Execute the command:
docker run -it --rm -v gitea_gitea-config:/etc/gitea busybox sh -c 'cat << EOF >> /etc/gitea/app.ini
[webhook]
ALLOWED_HOST_LIST = *
EOF'
- When setting up Gitea, specify gitea:3000 instead of localhost:3000 as the host. Add the gopher-bot user and configure its token for the repository.
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
- Add the webhook for the repository.
- Set SECRET.
- Set URL to
gopher-bot:8080/hooks
. - Add rights fro PR, PR Synchronize.
- Add the gopher-bot user to the repository.
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
Reload systemd:
systemctl daemon-reload
Add the service to systemd:
systemctl enable gopher-bot