Skip to content

Commit 8298779

Browse files
committed
feat: Add Docker support for gearbox-agent
- Implemented Docker container support for gearbox-agent, providing an alternative deployment method alongside the existing binary installation. - Created Dockerfile for multi-stage builds, optimizing for size and security. - Added .dockerignore to exclude unnecessary files from the Docker context. - Introduced docker-compose.yml for simplified deployment and configuration. - Updated README and documentation to include Docker installation instructions and usage examples. - Enhanced CI/CD workflows for automated Docker builds and pushes to GitHub Container Registry. - Added health check configuration and non-root user execution for improved security.
1 parent f97e402 commit 8298779

13 files changed

Lines changed: 1426 additions & 7 deletions

File tree

.github/workflows/ci-agent.yml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: CI - Agent
2+
3+
on:
4+
push:
5+
branches: [main, develop]
6+
paths:
7+
- 'gearbox-agent/**'
8+
- '.github/workflows/ci-agent.yml'
9+
pull_request:
10+
branches: [main, develop]
11+
paths:
12+
- 'gearbox-agent/**'
13+
- '.github/workflows/ci-agent.yml'
14+
15+
permissions:
16+
contents: read
17+
18+
jobs:
19+
test:
20+
name: Test
21+
runs-on: ubuntu-latest
22+
defaults:
23+
run:
24+
working-directory: ./gearbox-agent
25+
26+
steps:
27+
- name: Checkout code
28+
uses: actions/checkout@v6
29+
30+
- name: Set up Go
31+
uses: actions/setup-go@v6
32+
with:
33+
go-version: '1.25'
34+
cache-dependency-path: gearbox-agent/go.sum
35+
36+
- name: Download dependencies
37+
run: go mod download
38+
39+
- name: Run tests
40+
run: go test -v -race -coverprofile=coverage.out ./...
41+
42+
- name: Upload coverage to Codecov
43+
uses: codecov/codecov-action@v5
44+
with:
45+
files: ./gearbox-agent/coverage.out
46+
flags: agent-unittests
47+
name: codecov-agent
48+
fail_ci_if_error: false
49+
token: ${{ secrets.CODECOV_TOKEN }}
50+
51+
lint:
52+
name: Lint
53+
runs-on: ubuntu-latest
54+
defaults:
55+
run:
56+
working-directory: ./gearbox-agent
57+
58+
steps:
59+
- name: Checkout code
60+
uses: actions/checkout@v6
61+
62+
- name: Set up Go
63+
uses: actions/setup-go@v6
64+
with:
65+
go-version: '1.25'
66+
cache-dependency-path: gearbox-agent/go.sum
67+
68+
- name: Run golangci-lint
69+
uses: golangci/golangci-lint-action@v9
70+
with:
71+
version: latest
72+
working-directory: ./gearbox-agent
73+
args: --timeout=5m
74+
75+
build:
76+
name: Build
77+
runs-on: ubuntu-latest
78+
defaults:
79+
run:
80+
working-directory: ./gearbox-agent
81+
82+
steps:
83+
- name: Checkout code
84+
uses: actions/checkout@v6
85+
86+
- name: Set up Go
87+
uses: actions/setup-go@v6
88+
with:
89+
go-version: '1.25'
90+
cache-dependency-path: gearbox-agent/go.sum
91+
92+
- name: Download dependencies
93+
run: go mod download
94+
95+
- name: Build binary
96+
run: |
97+
CGO_ENABLED=0 go build \
98+
-ldflags="-s -w -X main.Version=${{ github.ref_name }} -X main.CommitSHA=${{ github.sha }} -X main.BuildDate=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
99+
-o bin/gearbox-agent \
100+
./cmd/gearbox-agent
101+
102+
- name: Upload binary artifact
103+
uses: actions/upload-artifact@v6
104+
with:
105+
name: gearbox-agent-${{ github.sha }}
106+
path: gearbox-agent/bin/gearbox-agent
107+
retention-days: 7

.github/workflows/docker-agent.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Docker Build and Push - Agent
2+
3+
on:
4+
push:
5+
branches: [main]
6+
tags:
7+
- 'v*'
8+
paths:
9+
- 'gearbox-agent/**'
10+
- '.github/workflows/docker-agent.yml'
11+
pull_request:
12+
branches: [main]
13+
paths:
14+
- 'gearbox-agent/**'
15+
- '.github/workflows/docker-agent.yml'
16+
17+
env:
18+
REGISTRY: ghcr.io
19+
IMAGE_NAME: ${{ github.repository }}/gearbox-agent
20+
21+
permissions:
22+
contents: read
23+
packages: write
24+
attestations: write
25+
id-token: write
26+
27+
jobs:
28+
build-and-push:
29+
name: Build and Push Docker Image
30+
runs-on: ubuntu-latest
31+
32+
steps:
33+
- name: Checkout code
34+
uses: actions/checkout@v6
35+
36+
- name: Set up QEMU
37+
uses: docker/setup-qemu-action@v3
38+
39+
- name: Set up Docker Buildx
40+
uses: docker/setup-buildx-action@v3
41+
42+
- name: Log in to Container Registry
43+
if: github.event_name != 'pull_request'
44+
uses: docker/login-action@v3
45+
with:
46+
registry: ${{ env.REGISTRY }}
47+
username: ${{ github.actor }}
48+
password: ${{ secrets.GITHUB_TOKEN }}
49+
50+
- name: Extract metadata
51+
id: meta
52+
uses: docker/metadata-action@v5
53+
with:
54+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
55+
tags: |
56+
type=ref,event=branch
57+
type=ref,event=pr
58+
type=semver,pattern={{version}}
59+
type=semver,pattern={{major}}.{{minor}}
60+
type=semver,pattern={{major}}
61+
type=sha,prefix=sha-
62+
type=raw,value=latest,enable={{is_default_branch}}
63+
64+
- name: Build and push Docker image
65+
id: build
66+
uses: docker/build-push-action@v6
67+
with:
68+
context: ./gearbox-agent
69+
push: ${{ github.event_name != 'pull_request' }}
70+
tags: ${{ steps.meta.outputs.tags }}
71+
labels: ${{ steps.meta.outputs.labels }}
72+
cache-from: type=gha
73+
cache-to: type=gha,mode=max
74+
build-args: |
75+
VERSION=${{ github.ref_name }}
76+
COMMIT_SHA=${{ github.sha }}
77+
BUILD_DATE=${{ github.event.repository.updated_at }}
78+
platforms: linux/amd64,linux/arm64
79+
80+
- name: Generate artifact attestation
81+
# Attestations only work on public repos or org-owned private repos
82+
if: github.event_name != 'pull_request' && !github.event.repository.private
83+
uses: actions/attest-build-provenance@v3
84+
with:
85+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
86+
subject-digest: ${{ steps.build.outputs.digest }}
87+
push-to-registry: true

.github/workflows/docker.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@ on:
55
branches: [main]
66
tags:
77
- 'v*'
8+
paths:
9+
- 'gearbox/**'
10+
- '.github/workflows/docker.yml'
811
pull_request:
912
branches: [main]
13+
paths:
14+
- 'gearbox/**'
15+
- '.github/workflows/docker.yml'
1016

1117
env:
1218
REGISTRY: ghcr.io
13-
IMAGE_NAME: ${{ github.repository }}/haproxy-monitor
19+
IMAGE_NAME: ${{ github.repository }}/gearbox
1420

1521
permissions:
1622
contents: read
@@ -69,6 +75,7 @@ jobs:
6975
VERSION=${{ github.ref_name }}
7076
COMMIT_SHA=${{ github.sha }}
7177
BUILD_DATE=${{ github.event.repository.updated_at }}
78+
platforms: linux/amd64,linux/arm64
7279

7380
- name: Generate artifact attestation
7481
# Attestations only work on public repos or org-owned private repos

README.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,32 @@ Visit `http://localhost:3000`
4747

4848
### Running the Agent
4949

50+
#### Binary Installation
51+
5052
```bash
5153
cd gearbox-agent
5254
make build
5355
./bin/gearbox-agent
5456
```
5557

56-
Agent runs on `https://localhost:8405`
58+
#### Docker Installation
59+
60+
```bash
61+
# Using Docker
62+
docker run -d \
63+
--name gearbox-agent \
64+
-p 8405:8405 \
65+
-v gearbox-agent-data:/var/lib/gearbox-agent \
66+
ghcr.io/sarg3nt/gearbox/gearbox-agent:latest
67+
68+
# Using Docker Compose
69+
cd gearbox-agent
70+
docker-compose up -d
71+
```
72+
73+
Agent runs on <https://localhost:8405>
74+
75+
See [gearbox-agent/README.md](gearbox-agent/README.md) for installation options and [gearbox-agent/docs/docker.md](gearbox-agent/docs/docker.md) for Docker-specific configuration.
5776

5877
## Architecture
5978

@@ -256,16 +275,18 @@ You are free to:
256275
- Host and use an **unmodified version** of the software for free
257276

258277
### What you cannot do
278+
259279
You may not:
260280

261281
- Offer the software as a hosted or managed service where the software itself is
262282
the primary value being sold
263283
- Rebrand, resell, or offer it as a competing commercial product or service
264284

265285
### Commercial use
286+
266287
If you wish to offer this software (or a modified version of it) as a managed or
267-
hosted service, commercial licensing is available.
268-
Please contact **dave@sarg3.net** for more information.
288+
hosted service, commercial licensing is available.
289+
Please contact <dave@sarg3.net> for more information.
269290

270291
This license is designed to be friendly to internal enterprise use while
271292
protecting the project from being resold or rebranded as a competing service.

docs/getting-started.md

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,24 @@ The dashboard will be available at `http://localhost:3000`
3737

3838
### Step 2: Install Gearbox Agent on Your Box
3939

40-
On the server or workstation you want to monitor:
40+
Choose the installation method that works best for your environment:
41+
42+
#### Option A: Docker Installation (Recommended)
43+
44+
The easiest way to get started with minimal dependencies:
45+
46+
```bash
47+
# Pull the latest image
48+
docker pull ghcr.io/sarg3nt/gearbox/gearbox-agent:latest
49+
50+
# Or use Docker Compose (see Step 5 for docker-compose.yml example)
51+
```
52+
53+
See [gearbox-agent/docs/docker.md](../gearbox-agent/docs/docker.md) for complete Docker setup guide.
54+
55+
#### Option B: Binary Installation
56+
57+
For traditional systemd-based deployments:
4158

4259
```bash
4360
# Clone the repository
@@ -82,6 +99,47 @@ port: 8405
8299
83100
### Step 5: Start the Agent
84101
102+
#### If Using Docker
103+
104+
**Using docker run:**
105+
106+
```bash
107+
docker run -d \
108+
--name gearbox-agent \
109+
-p 8405:8405 \
110+
-v gearbox-agent-data:/var/lib/gearbox-agent \
111+
-e HAPROXY_AGENT_LOG_LEVEL=info \
112+
ghcr.io/sarg3nt/gearbox/gearbox-agent:latest
113+
```
114+
115+
**Using Docker Compose:**
116+
117+
Create `docker-compose.yml`:
118+
119+
```yaml
120+
version: '3.8'
121+
122+
services:
123+
gearbox-agent:
124+
image: ghcr.io/sarg3nt/gearbox/gearbox-agent:latest
125+
container_name: gearbox-agent
126+
restart: unless-stopped
127+
ports:
128+
- "8405:8405"
129+
volumes:
130+
- ./data:/var/lib/gearbox-agent
131+
environment:
132+
- HAPROXY_AGENT_LOG_LEVEL=info
133+
```
134+
135+
Then start:
136+
137+
```bash
138+
docker-compose up -d
139+
```
140+
141+
#### If Using Binary
142+
85143
```bash
86144
# Start the agent
87145
cd gearbox-agent

0 commit comments

Comments
 (0)