Skip to content

Commit 466e4b0

Browse files
Migrate CLI tools to Cobra for richer help and flag handling
Replace the stdlib flag package in both cmd/puppet-ca and cmd/puppet-ca-ctl with github.com/spf13/cobra. The server becomes a single root command with all flags declared via pflag; --cadir is now enforced required by Cobra rather than a manual post-parse check. The control CLI gains a proper subcommand tree with persistent global flags (server-url, ca-cert, client-cert, client-key, verbose) that work before or after the subcommand name. Required flags on each subcommand (--certname, --cadir, etc.) are enforced by Cobra. The fatalf/os.Exit pattern is replaced with error returns through RunE, and checkHTTP now returns an error instead of exiting inline. Replace the multi-stage in-container Go build with a slim runtime image (Dockerfile.run) that COPYs pre-built binaries from bin/. All integration test targets (integ, integCompose, loadCompose, bench, stress) now depend on Build.All first, ensuring the local binary is what gets tested. The original multi-stage Dockerfile is kept for standalone docker-build use cases where Go is not installed locally. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent a7c922e commit 466e4b0

12 files changed

Lines changed: 549 additions & 476 deletions

File tree

Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ COPY --from=builder /puppet-ca-ctl /usr/local/bin/puppet-ca-ctl
3030
USER puppet
3131
EXPOSE 8140
3232

33-
# --cadir : where CA state is stored
34-
# --autosign-config=true : sign all incoming CSRs immediately (dev/test only)
35-
# -v=1 : debug logging
33+
# --cadir : where CA state is stored
34+
# --autosign-config : sign all incoming CSRs immediately (dev/test only)
35+
# --verbosity : debug logging
3636
ENTRYPOINT ["/usr/local/bin/puppet-ca"]
3737
CMD ["--cadir=/etc/puppetlabs/puppet/ssl/ca", \
3838
"--autosign-config=true", \
39-
"-v=1"]
39+
"--verbosity=1"]

Dockerfile.run

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Runtime image built from locally-compiled binaries.
2+
#
3+
# Build the binaries first:
4+
# mage build:all
5+
# # or: go build -o bin/ ./cmd/...
6+
#
7+
# Then build this image:
8+
# podman build -f Dockerfile.run -t puppet-ca:latest .
9+
#
10+
# Integration test targets (mage test:integ, test:integCompose, etc.) handle
11+
# both steps automatically.
12+
13+
FROM quay.io/centos/centos:stream10
14+
15+
# curl: health checks and agent CSR submission
16+
# openssl: CSR generation and cert verification in integration tests
17+
RUN dnf install -y curl openssl && dnf clean all && \
18+
useradd -m puppet && \
19+
mkdir -p /etc/puppetlabs/puppet/ssl/ca /data && \
20+
chown -R puppet:puppet /etc/puppetlabs/puppet /data
21+
22+
COPY bin/puppet-ca /usr/local/bin/puppet-ca
23+
COPY bin/puppet-ca-ctl /usr/local/bin/puppet-ca-ctl
24+
25+
USER puppet
26+
EXPOSE 8140
27+
28+
ENTRYPOINT ["/usr/local/bin/puppet-ca"]
29+
CMD ["--cadir=/etc/puppetlabs/puppet/ssl/ca", \
30+
"--autosign-config=true", \
31+
"--verbosity=1"]

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ mage build:fips # → bin/puppet-ca-fips (GOEXPERIMENT=boringcrypto)
6363
| `--puppet-server` | `""` | Comma-separated CNs granted admin API access (mTLS only) |
6464
| `--daemon` | `false` | Fork to background (not recommended in containers) |
6565
| `--logfile` | `""` | Write JSON logs to this file instead of stderr |
66-
| `-v` | `0` | Verbosity: `0`=Info, `1`=Debug, `2`=Trace |
66+
| `--verbosity` / `-v` | `0` | Verbosity: `0`=Info, `1`=Debug, `2`=Trace |
6767

6868
### Quick start (plain HTTP, auto-bootstrap CA)
6969

@@ -246,7 +246,7 @@ In plain HTTP mode (no TLS), all endpoints are accessible without authentication
246246
--verbose Enable debug logging
247247
```
248248

249-
Global flags must be placed **before** the subcommand name.
249+
Global flags may be placed before or after the subcommand name.
250250

251251
### Subcommands
252252

0 commit comments

Comments
 (0)