Building
Prerequisites
Section titled “Prerequisites”- Go 1.24 or later
- Docker (for Docker image builds)
- golangci-lint (for linting)
Building
Section titled “Building”# Clone the repositorygit clone https://github.com/jmrplens/cs-routeros-bouncer.gitcd cs-routeros-bouncer
# Buildgo build -o cs-routeros-bouncer ./cmd/cs-routeros-bouncerWith version information:
go build -ldflags "-X main.version=1.3.0 -X main.commit=$(git rev-parse HEAD) -X main.date=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \ -o cs-routeros-bouncer ./cmd/cs-routeros-bouncerdocker build -t cs-routeros-bouncer:local .Build for different architectures:
# ARM64 (e.g., Raspberry Pi 4, Apple Silicon)GOOS=linux GOARCH=arm64 go build -o cs-routeros-bouncer-arm64 ./cmd/cs-routeros-bouncer
# ARMv7 (e.g., Raspberry Pi 3)GOOS=linux GOARCH=arm GOARM=7 go build -o cs-routeros-bouncer-armv7 ./cmd/cs-routeros-bouncer
# AMD64GOOS=linux GOARCH=amd64 go build -o cs-routeros-bouncer-amd64 ./cmd/cs-routeros-bouncerTesting
Section titled “Testing”# Run all testsgo test ./...
# With verbose outputgo test -v ./...
# With coveragego test -coverprofile=coverage.out ./...go tool cover -html=coverage.outRun a specific package:
go test -v ./internal/config/...go test -v ./internal/routeros/...go test -v ./internal/metrics/...# Generate coverage reportgo test -coverprofile=coverage.out -covermode=atomic ./...
# View coverage in browsergo tool cover -html=coverage.out -o coverage.html
# Check coverage percentagego tool cover -func=coverage.out | tail -1Functional tests run against a real MikroTik router. They are skipped by default.
FUNCTIONAL_TEST=1 \ MIKROTIK_HOST="192.168.0.1:8728" \ MIKROTIK_USER="crowdsec" \ MIKROTIK_PASS="your-password" \ go test -v ./internal/routeros/... -run TestFunctionalLinting
Section titled “Linting”# Install golangci-lintgo install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
# Run lintergolangci-lint run
# Run with auto-fixgolangci-lint run --fix
# Go vetgo vet ./...The project uses .golangci.yml for linter configuration.
| Workflow | Trigger | Purpose |
|---|---|---|
test.yml | Push, PR | Run tests and linting |
release.yml | Tag push | Build binaries, Docker images, create GitHub release |
docker.yml | Push to main | Build and push Docker image to GHCR |
Release process
Section titled “Release process”-
Update version in code
-
Create and push a git tag
Terminal window git tag v1.3.0git push origin v1.3.0 -
GitHub Actions automatically:
- Builds binaries for linux/amd64, linux/arm64, linux/arm/v7
- Builds and pushes Docker images (multi-arch)
- Creates a GitHub release with binaries attached
Development workflow
Section titled “Development workflow”-
Create a feature branch
Terminal window git checkout -b feat/my-feature -
Make changes and test
Terminal window go test ./...golangci-lint run -
Commit with a conventional message
Terminal window git commit -m "feat: add new feature" -
Push and create PR