|
| 1 | +# Development Guide |
| 2 | + |
| 3 | +This document explains how to set up your local development environment for gh-ost. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- **Go 1.23+** – [Install Go](https://golang.org/doc/install) |
| 8 | +- **MySQL 5.7+ or 8.0+** – for integration tests |
| 9 | +- **Docker & Docker Compose** – for running replica-based tests |
| 10 | +- **golangci-lint** – for linting (optional, also runs in CI) |
| 11 | + |
| 12 | +## Getting Started |
| 13 | + |
| 14 | +### 1. Clone the repository |
| 15 | + |
| 16 | +```bash |
| 17 | +git clone https://github.com/scutuatua-crypto/gh-ost.git |
| 18 | +cd gh-ost |
| 19 | +``` |
| 20 | + |
| 21 | +### 2. Install dependencies |
| 22 | + |
| 23 | +```bash |
| 24 | +go mod download |
| 25 | +``` |
| 26 | + |
| 27 | +### 3. Build the binary |
| 28 | + |
| 29 | +```bash |
| 30 | +make build |
| 31 | +# Binary is placed in ./bin/gh-ost |
| 32 | +``` |
| 33 | + |
| 34 | +### 4. Run unit tests |
| 35 | + |
| 36 | +```bash |
| 37 | +make test |
| 38 | +``` |
| 39 | + |
| 40 | +### 5. Run linting |
| 41 | + |
| 42 | +Install golangci-lint: |
| 43 | + |
| 44 | +```bash |
| 45 | +go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest |
| 46 | +``` |
| 47 | + |
| 48 | +Then run: |
| 49 | + |
| 50 | +```bash |
| 51 | +make lint |
| 52 | +``` |
| 53 | + |
| 54 | +## Using the Makefile |
| 55 | + |
| 56 | +The repository ships with a `Makefile` for common tasks: |
| 57 | + |
| 58 | +| Target | Description | |
| 59 | +|----------------|----------------------------------------------| |
| 60 | +| `make build` | Compile the gh-ost binary into `./bin/` | |
| 61 | +| `make test` | Run unit tests with coverage | |
| 62 | +| `make lint` | Run golangci-lint static analysis | |
| 63 | +| `make fmt` | Format all Go source files with `gofmt -s` | |
| 64 | +| `make vet` | Run `go vet` on all packages | |
| 65 | +| `make clean` | Remove build artifacts | |
| 66 | +| `make deps` | Download and tidy Go modules | |
| 67 | +| `make cibuild` | Full CI build (format, build, test) | |
| 68 | + |
| 69 | +## Running Replica Integration Tests |
| 70 | + |
| 71 | +Integration tests spin up a MySQL primary + replica using Docker Compose. |
| 72 | + |
| 73 | +### Using Docker Compose directly |
| 74 | + |
| 75 | +```bash |
| 76 | +# Start the test environment |
| 77 | +docker compose up -d |
| 78 | + |
| 79 | +# Run the tests |
| 80 | +bash test.sh |
| 81 | + |
| 82 | +# Tear down |
| 83 | +docker compose down |
| 84 | +``` |
| 85 | + |
| 86 | +### Using the helper script |
| 87 | + |
| 88 | +```bash |
| 89 | +script/docker-gh-ost-replica-tests |
| 90 | +``` |
| 91 | + |
| 92 | +## Code Structure |
| 93 | + |
| 94 | +``` |
| 95 | +. |
| 96 | +├── go/ |
| 97 | +│ ├── base/ – Core types, context, configuration |
| 98 | +│ ├── binlog/ – Binlog reader / DML event handling |
| 99 | +│ ├── cmd/ – Main entry point |
| 100 | +│ ├── logic/ – Migration orchestration (migrator, applier, inspector, throttler…) |
| 101 | +│ ├── mysql/ – MySQL binlog utilities and instance inspection |
| 102 | +│ └── sql/ – SQL parsing and query building |
| 103 | +├── localtests/ – Shell-based local integration tests |
| 104 | +├── resources/ – Packaging resources (systemd units, etc.) |
| 105 | +├── script/ – CI and development helper scripts |
| 106 | +└── vendor/ – Vendored Go dependencies |
| 107 | +``` |
| 108 | + |
| 109 | +## Code Style |
| 110 | + |
| 111 | +- Follow the official [Effective Go](https://golang.org/doc/effective_go) guidelines. |
| 112 | +- Run `make fmt` before committing to ensure consistent formatting. |
| 113 | +- All new code must pass `go vet` and `golangci-lint`. |
| 114 | + |
| 115 | +## Pre-commit Hooks (optional) |
| 116 | + |
| 117 | +Install [pre-commit](https://pre-commit.com/) and set up the hooks: |
| 118 | + |
| 119 | +```bash |
| 120 | +pip install pre-commit |
| 121 | +pre-commit install |
| 122 | +``` |
| 123 | + |
| 124 | +The hooks will automatically check formatting and run `go vet` on every commit. |
| 125 | + |
| 126 | +## Submitting Changes |
| 127 | + |
| 128 | +Please read [CONTRIBUTING.md](.github/CONTRIBUTING.md) before opening a pull request. |
0 commit comments