Skip to content

Commit c28a6cd

Browse files
committed
refactor(galeracheck): add build system
1 parent 61cf86a commit c28a6cd

File tree

7 files changed

+212
-2
lines changed

7 files changed

+212
-2
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: Build and Release galeracheck Debian Package
2+
3+
on:
4+
push:
5+
tags:
6+
- '*-galeracheck'
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
build-and-release:
13+
name: Build Debian Package
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Set up Go
23+
uses: actions/setup-go@v5
24+
with:
25+
go-version: '1.21'
26+
cache: true
27+
28+
- name: Extract version from tag
29+
id: version
30+
run: |
31+
TAG_NAME=${GITHUB_REF#refs/tags/}
32+
VERSION=${TAG_NAME%-galeracheck}
33+
echo "version=$VERSION" >> $GITHUB_OUTPUT
34+
echo "tag=$TAG_NAME" >> $GITHUB_OUTPUT
35+
echo "Building version: $VERSION"
36+
37+
- name: Build galeracheck binary
38+
working-directory: ./galeracheck
39+
run: |
40+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
41+
-ldflags="-w -s -X main.version=${{ steps.version.outputs.version }}" \
42+
-o galeracheck \
43+
.
44+
file galeracheck
45+
./galeracheck -h || true
46+
47+
- name: Install nfpm
48+
run: |
49+
echo "deb [trusted=yes] https://repo.goreleaser.com/apt/ /" | sudo tee /etc/apt/sources.list.d/goreleaser.list
50+
sudo apt-get update
51+
sudo apt-get install -y nfpm
52+
53+
- name: Build Debian package
54+
working-directory: ./galeracheck
55+
env:
56+
VERSION: ${{ steps.version.outputs.version }}
57+
run: |
58+
nfpm package --packager deb --target .
59+
dpkg-deb --contents galeracheck_${VERSION}_amd64.deb
60+
dpkg-deb --info galeracheck_${VERSION}_amd64.deb
61+
62+
- name: Create GitHub Release
63+
uses: softprops/action-gh-release@v1
64+
with:
65+
tag_name: ${{ steps.version.outputs.tag }}
66+
name: galeracheck ${{ steps.version.outputs.version }}
67+
body: |
68+
# galeracheck ${{ steps.version.outputs.version }}
69+
70+
HTTP health check service for Galera Cluster nodes.
71+
72+
## Installation
73+
74+
### Debian/Ubuntu
75+
76+
```bash
77+
wget https://github.com/tanji/mariadb-tools/releases/download/${{ steps.version.outputs.tag }}/galeracheck_${{ steps.version.outputs.version }}_amd64.deb
78+
sudo dpkg -i galeracheck_${{ steps.version.outputs.version }}_amd64.deb
79+
```
80+
81+
### Configure and Start
82+
83+
```bash
84+
# Create MySQL config file
85+
sudo tee /etc/galeracheck/my.cnf > /dev/null << 'CONFIG'
86+
[mysql]
87+
user=monitor
88+
password=yourpassword
89+
socket=/run/mysqld/mysqld.sock
90+
CONFIG
91+
92+
# Enable and start service
93+
sudo systemctl enable galeracheck
94+
sudo systemctl start galeracheck
95+
96+
# Check status
97+
sudo systemctl status galeracheck
98+
curl http://localhost:8000/
99+
```
100+
101+
## Changes
102+
103+
See commit history for details.
104+
draft: false
105+
prerelease: false
106+
files: |
107+
galeracheck/galeracheck_${{ steps.version.outputs.version }}_amd64.deb
108+
109+
- name: Upload package artifact
110+
uses: actions/upload-artifact@v4
111+
with:
112+
name: galeracheck-deb-${{ steps.version.outputs.version }}
113+
path: galeracheck/galeracheck_${{ steps.version.outputs.version }}_amd64.deb
114+
retention-days: 90

galeracheck/galeracheck

8.92 MB
Binary file not shown.

galeracheck/main.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"log"
1111
"net/http"
12+
"os"
1213
osuser "os/user"
1314
"strings"
1415

@@ -18,6 +19,7 @@ import (
1819
)
1920

2021
var (
22+
version = "dev"
2123
cnffile string
2224
port int
2325
sockopt string
@@ -33,18 +35,24 @@ var (
3335
)
3436

3537
func init() {
38+
var versionFlag bool
3639
flag.StringVar(&cnffile, "config", "~/.my.cnf", "MySQL Config file to use")
3740
flag.IntVar(&port, "port", 8000, "TCP port to listen on")
3841
flag.StringVar(&sockopt, "mysql-socket", "/run/mysqld/mysqld.sock", "Path to unix socket of monitored MySQL instance")
3942
flag.StringVar(&hostopt, "mysql-host", "", "Hostname or IP address of monitored MySQL instance")
4043
flag.StringVar(&portopt, "mysql-port", "3306", "Port of monitored MySQL instance")
4144
flag.BoolVar(&awd, "available-when-donor", false, "Available when donor")
4245
flag.BoolVar(&dwr, "disable-when-readonly", false, "Disable when read_only flag is set (desirable when wanting to take a node out of the cluster without desync)")
46+
flag.BoolVar(&versionFlag, "version", false, "Print version and exit")
47+
flag.Parse()
48+
49+
if versionFlag {
50+
fmt.Printf("galeracheck version %s\n", version)
51+
os.Exit(0)
52+
}
4353
}
4454

4555
func main() {
46-
flag.Parse()
47-
4856
usr, _ := osuser.Current()
4957

5058
if strings.Contains(cnffile, "~/") {

galeracheck/my.cnf.example

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Example galeracheck configuration
2+
# Copy to ~/.my.cnf or /etc/galeracheck/my.cnf and customize
3+
4+
[mysql]
5+
user=monitor
6+
password=changeme
7+
socket=/run/mysqld/mysqld.sock
8+
9+
# For TCP connections, use host and port instead of socket:
10+
# host=localhost
11+
# port=3306

galeracheck/nfpm.yaml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: "galeracheck"
2+
arch: "amd64"
3+
platform: "linux"
4+
version: "${VERSION}"
5+
section: "database"
6+
priority: "optional"
7+
maintainer: "tanji <tanji@mariadb.com>"
8+
description: |
9+
HTTP health check service for Galera Cluster nodes
10+
galeracheck is a lightweight HTTP service that monitors the health of a Galera
11+
Cluster node and reports its availability status. Load balancers can poll this
12+
endpoint to determine whether to route traffic to the node.
13+
vendor: "tanji"
14+
homepage: "https://github.com/tanji/mariadb-tools"
15+
license: "Apache-2.0"
16+
17+
depends:
18+
- systemd
19+
20+
contents:
21+
- src: ./galeracheck
22+
dst: /usr/local/bin/galeracheck
23+
file_info:
24+
mode: 0755
25+
26+
- src: ./galeracheck.service
27+
dst: /lib/systemd/system/galeracheck.service
28+
file_info:
29+
mode: 0644
30+
31+
- src: ./README.md
32+
dst: /usr/share/doc/galeracheck/README.md
33+
file_info:
34+
mode: 0644
35+
36+
- src: ./my.cnf.example
37+
dst: /usr/share/doc/galeracheck/my.cnf.example
38+
file_info:
39+
mode: 0644
40+
41+
- dst: /etc/galeracheck
42+
type: dir
43+
file_info:
44+
mode: 0755
45+
46+
scripts:
47+
postinstall: ./scripts/postinstall.sh
48+
preremove: ./scripts/preremove.sh
49+
50+
overrides:
51+
deb:
52+
fields:
53+
Recommends: "mariadb-server | mysql-server"

galeracheck/scripts/postinstall.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
# Post-installation script for galeracheck
3+
4+
if command -v systemctl &> /dev/null; then
5+
systemctl daemon-reload
6+
echo "Systemd daemon reloaded. To enable and start galeracheck:"
7+
echo " systemctl enable galeracheck"
8+
echo " systemctl start galeracheck"
9+
fi
10+
11+
exit 0

galeracheck/scripts/preremove.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
# Pre-removal script for galeracheck
3+
4+
if command -v systemctl &> /dev/null; then
5+
if systemctl is-active --quiet galeracheck; then
6+
systemctl stop galeracheck
7+
fi
8+
if systemctl is-enabled --quiet galeracheck; then
9+
systemctl disable galeracheck
10+
fi
11+
fi
12+
13+
exit 0

0 commit comments

Comments
 (0)