Skip to content

Commit d64b4e9

Browse files
authored
feat: Improvements (#2)
- Use single Application - Update CI/CD - Renovate bot - CLI Improvements
1 parent 89c1893 commit d64b4e9

38 files changed

Lines changed: 1025 additions & 455 deletions

.github/workflows/ci.yml

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
test:
14+
name: Go Tests
15+
runs-on: ubuntu-latest
16+
defaults:
17+
run:
18+
working-directory: cli
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- uses: actions/setup-go@v5
23+
with:
24+
go-version-file: cli/go.mod
25+
cache-dependency-path: cli/go.sum
26+
27+
- name: Run tests
28+
run: go test -race -coverprofile=coverage.out ./...
29+
30+
- name: Upload coverage
31+
uses: actions/upload-artifact@v4
32+
with:
33+
name: coverage
34+
path: cli/coverage.out
35+
36+
lint:
37+
name: Go Lint
38+
runs-on: ubuntu-latest
39+
defaults:
40+
run:
41+
working-directory: cli
42+
steps:
43+
- uses: actions/checkout@v4
44+
45+
- uses: actions/setup-go@v5
46+
with:
47+
go-version-file: cli/go.mod
48+
cache-dependency-path: cli/go.sum
49+
50+
- uses: golangci/golangci-lint-action@v9
51+
with:
52+
working-directory: cli
53+
54+
helm-lint:
55+
name: Helm Lint
56+
runs-on: ubuntu-latest
57+
steps:
58+
- uses: actions/checkout@v4
59+
60+
- uses: azure/setup-helm@v4
61+
62+
- name: Lint all charts
63+
run: |
64+
helm lint apps/
65+
for chart in components/*/; do
66+
echo "Linting $chart..."
67+
if grep -q "^dependencies:" "$chart/Chart.yaml"; then
68+
helm dependency build "$chart"
69+
fi
70+
values_args=""
71+
if [ -f "$chart/values/base.yaml" ]; then
72+
values_args="-f $chart/values/base.yaml"
73+
fi
74+
helm lint "$chart" $values_args
75+
done
76+
77+
helm-validate:
78+
name: Helm Validate Values
79+
runs-on: ubuntu-latest
80+
strategy:
81+
matrix:
82+
environment: [dev, staging, prod]
83+
steps:
84+
- uses: actions/checkout@v4
85+
86+
- uses: azure/setup-helm@v4
87+
88+
- name: Build chart dependencies
89+
run: |
90+
for chart in components/*/; do
91+
if grep -q "^dependencies:" "$chart/Chart.yaml"; then
92+
helm dependency build "$chart"
93+
fi
94+
done
95+
96+
- name: Validate apps values
97+
run: helm template apps/ -f apps/values/${{ matrix.environment }}.yaml
98+
99+
- name: Validate component values
100+
run: |
101+
for chart in components/*/; do
102+
name=$(basename "$chart")
103+
base="$chart/values/base.yaml"
104+
env_file="$chart/values/${{ matrix.environment }}.yaml"
105+
if [ -f "$base" ] && [ -f "$env_file" ]; then
106+
echo "Validating $name for ${{ matrix.environment }}..."
107+
helm template "$chart" -f "$base" -f "$env_file"
108+
fi
109+
done

.github/workflows/release.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,33 @@ jobs:
3636
env:
3737
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3838
39+
build-cli:
40+
name: Build CLI Binaries
41+
runs-on: ubuntu-latest
42+
needs: release
43+
steps:
44+
- uses: actions/checkout@v4
45+
with:
46+
fetch-depth: 0
47+
48+
- uses: actions/setup-go@v5
49+
with:
50+
go-version-file: cli/go.mod
51+
cache-dependency-path: cli/go.sum
52+
53+
- name: Get latest tag
54+
id: tag
55+
run: echo "version=$(git describe --tags --abbrev=0 2>/dev/null || echo '')" >> "$GITHUB_OUTPUT"
56+
57+
- name: Run GoReleaser
58+
if: steps.tag.outputs.version != ''
59+
uses: goreleaser/goreleaser-action@v6
60+
with:
61+
version: latest
62+
args: release --clean
63+
env:
64+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65+
3966
docs-build:
4067
runs-on: ubuntu-latest
4168
needs: release

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ secrets/
1717

1818
# Binaries
1919
cli/cluster-bootstrap
20-
*.enc.yaml
21-
.sops.yaml
2220

2321
# Sops
2422
age-key.txt
2523
repo-ssh-key.pem
2624
.env
25+
test_secrets/*
26+
.sops-test.yaml
2727

2828
# MkDocs
2929
site/
3030
venv
3131

3232
# Node
33-
node_modules/
33+
node_modules/

.goreleaser.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
project_name: cluster-bootstrap
2+
3+
before:
4+
hooks:
5+
- go mod tidy
6+
7+
builds:
8+
- main: ./main.go
9+
dir: cli
10+
binary: cluster-bootstrap
11+
env:
12+
- CGO_ENABLED=0
13+
goos:
14+
- linux
15+
- darwin
16+
goarch:
17+
- amd64
18+
- arm64
19+
ldflags:
20+
- -s -w
21+
22+
archives:
23+
- format: tar.gz
24+
name_template: "{{ .ProjectName }}-{{ .Os }}-{{ .Arch }}"
25+
26+
checksum:
27+
name_template: "checksums.txt"
28+
29+
changelog:
30+
skip: true

.pre-commit-config.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v5.0.0
4+
hooks:
5+
- id: check-yaml
6+
args: ["--allow-multiple-documents"]
7+
exclude: "(cli/testdata/invalid\\.sops\\.yaml$|.*/templates/.*\\.yaml$)"
8+
- id: check-merge-conflict
9+
- id: trailing-whitespace
10+
- id: end-of-file-fixer
11+
- id: detect-private-key
12+
exclude: "secrets\\..*\\.enc\\.yaml$"
13+
14+
- repo: https://github.com/gitleaks/gitleaks
15+
rev: v8.22.1
16+
hooks:
17+
- id: gitleaks
18+
19+
- repo: local
20+
hooks:
21+
- id: go-fmt
22+
name: go fmt
23+
entry: bash -c 'cd cli && go fmt ./...'
24+
language: system
25+
types: [go]
26+
pass_filenames: false
27+
28+
- id: go-vet
29+
name: go vet
30+
entry: bash -c 'cd cli && go vet ./...'
31+
language: system
32+
types: [go]
33+
pass_filenames: false

README.md

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ Online documentation available at [Cluster Boostrap Docs](https://user-cube.gith
1919
- `helm` (for local template testing)
2020
- `sops` and `age` (for secrets encryption/decryption)
2121
- `go` 1.25+ (to build the CLI)
22-
- `task` (task runner for CLI development)
22+
- `task` ([Task runner](https://taskfile.dev/))
23+
- `pre-commit` ([pre-commit hooks](https://pre-commit.com/))
2324
- SSH private key with read access to this repo
2425

2526
## Quick Start
2627

2728
### 1. Build the CLI
2829

2930
```bash
30-
cd cli
3131
task build
3232
```
3333

@@ -67,14 +67,16 @@ kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath='{.data.pas
6767
```
6868
CLI bootstrap → ArgoCD + App of Apps (root Application)
6969
70-
apps/ (Helm chart generating Application CRs)
70+
apps/ (Helm chart with dynamic template)
7171
7272
components/argocd/ (self-managed ArgoCD)
7373
components/xxx/ (other components)
7474
```
7575

7676
ArgoCD manages itself — changes pushed to this repo are automatically synced.
7777

78+
The `apps/` chart uses a **single dynamic template** that iterates over a `components` map defined in `apps/values.yaml`. Adding a new component requires only a new entry in the values — no template files to create or copy.
79+
7880
## Components
7981

8082
| Component | Namespace | Sync Wave | Description |
@@ -96,10 +98,58 @@ ArgoCD manages itself — changes pushed to this repo are automatically synced.
9698
| `init` | Interactive setup for SOPS config and encrypted secrets files |
9799
| `vault-token` | Store Vault root token as Kubernetes secret |
98100

101+
## Development
102+
103+
### Setup
104+
105+
```bash
106+
pre-commit install
107+
```
108+
109+
### Available tasks
110+
111+
Run `task --list` to see all available tasks. The most common ones:
112+
113+
```bash
114+
task test # Run Go tests with coverage
115+
task lint # Run golangci-lint
116+
task helm-lint # Lint Helm charts with templates
117+
task fmt # Format Go source files
118+
task vet # Run Go vet
119+
task docs-serve # Serve MkDocs documentation locally
120+
```
121+
122+
### Secrets example
123+
124+
`secrets.example.enc.yaml` contains the expected secrets structure. To create a new environment:
125+
126+
```bash
127+
cp secrets.example.enc.yaml secrets.myenv.enc.yaml
128+
sops --encrypt --in-place secrets.myenv.enc.yaml
129+
```
130+
131+
Or use the CLI interactively: `./cli/cluster-bootstrap init myenv`
132+
133+
To use a custom `.sops.yaml` path, set `SOPS_CONFIG` in your `.env`:
134+
135+
```bash
136+
SOPS_CONFIG=/path/to/custom/.sops.yaml
137+
```
138+
99139
## Environments
100140

101141
| Environment | Values File | Description |
102142
|-------------|-------------|-------------|
103143
| dev | `apps/values/dev.yaml` | Local/development clusters, minimal resources |
104144
| staging | `apps/values/staging.yaml` | Pre-production, moderate resources |
105145
| prod | `apps/values/prod.yaml` | Production, HA configuration |
146+
147+
Environment files only need to set the `environment` key. Component defaults (namespace, sync wave, syncOptions, etc.) are defined in `apps/values.yaml`. To disable a component per environment:
148+
149+
```yaml
150+
# apps/values/dev.yaml
151+
environment: dev
152+
components:
153+
trivy-operator:
154+
enabled: false
155+
```

Taskfile.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
version: "3"
2+
3+
includes:
4+
cli:
5+
taskfile: cli/Taskfile.yml
6+
dir: cli
7+
8+
tasks:
9+
build:
10+
desc: Build the CLI binary
11+
cmds:
12+
- task: cli:build
13+
14+
test:
15+
desc: Run Go tests with coverage
16+
dir: cli
17+
cmds:
18+
- go test -cover ./...
19+
20+
lint:
21+
desc: Run golangci-lint on the CLI
22+
dir: cli
23+
cmds:
24+
- golangci-lint run ./...
25+
26+
fmt:
27+
desc: Format Go source files
28+
cmds:
29+
- task: cli:fmt
30+
31+
vet:
32+
desc: Run Go vet
33+
cmds:
34+
- task: cli:vet
35+
36+
helm-lint:
37+
desc: Lint all Helm charts that contain templates
38+
cmds:
39+
- helm lint apps/
40+
- helm lint components/argocd-repo-secret/
41+
- helm lint components/vault/
42+
43+
docs-serve:
44+
desc: Serve MkDocs documentation locally
45+
cmds:
46+
- mkdocs serve

0 commit comments

Comments
 (0)