refactor: use official golangci-lint image for lint stage
All checks were successful
check / check (push) Successful in 1m15s

Restructure Dockerfile to match upaas/dnswatcher pattern:
- Separate lint stage using golangci/golangci-lint:v2.1.6 image
- Builder stage for tests and compilation (no lint dependency)
- Add fmt-check Makefile target
- Decouple test from lint in Makefile (lint runs in its own stage)
- Run gofmt on all files
- docker build verified passing locally
This commit is contained in:
clawbot
2026-03-10 12:36:19 -07:00
parent 9be6e2a4eb
commit f8e8eec43d
12 changed files with 42 additions and 52 deletions

View File

@@ -1,57 +1,44 @@
# Build stage # Lint stage — fast feedback on formatting and lint issues
FROM golang:1.24-alpine AS builder # golangci/golangci-lint:v2.1.6
FROM golangci/golangci-lint:v2.1.6 AS lint
# Install build dependencies WORKDIR /src
RUN apk add --no-cache \
gcc \
musl-dev \
make \
git \
gnupg
# Set working directory
WORKDIR /build
# Copy go mod files
COPY go.mod go.sum ./ COPY go.mod go.sum ./
# Download dependencies
RUN go mod download RUN go mod download
# Copy source code
COPY . . COPY . .
# Install golangci-lint for checks (binary install to avoid Go version constraints) RUN make fmt-check
RUN wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.1.6 RUN make lint
# Run all checks (lint, vet, test, build) # Build stage — tests and compilation
RUN make check FROM golang:1.24-alpine AS builder
# Build the final binary with version info # Force BuildKit to run the lint stage
RUN CGO_ENABLED=1 go build -v -o secret cmd/secret/main.go COPY --from=lint /src/go.sum /dev/null
RUN apk add --no-cache gcc musl-dev make git gnupg
WORKDIR /build
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN make test
RUN CGO_ENABLED=1 go build -v -ldflags "-X 'git.eeqj.de/sneak/secret/internal/cli.Version=0.1.0' -X 'git.eeqj.de/sneak/secret/internal/cli.GitCommit=$(git rev-parse HEAD)'" -o secret cmd/secret/main.go
# Runtime stage # Runtime stage
FROM alpine:latest FROM alpine:latest
# Install runtime dependencies RUN apk add --no-cache ca-certificates gnupg
RUN apk add --no-cache \
ca-certificates \
gnupg
# Create non-root user
RUN adduser -D -s /bin/sh secret RUN adduser -D -s /bin/sh secret
# Copy binary from builder
COPY --from=builder /build/secret /usr/local/bin/secret COPY --from=builder /build/secret /usr/local/bin/secret
# Ensure binary is executable
RUN chmod +x /usr/local/bin/secret RUN chmod +x /usr/local/bin/secret
# Switch to non-root user
USER secret USER secret
# Set working directory
WORKDIR /home/secret WORKDIR /home/secret
# Set entrypoint
ENTRYPOINT ["secret"] ENTRYPOINT ["secret"]

View File

@@ -17,7 +17,7 @@ build: ./secret
vet: vet:
go vet ./... go vet ./...
test: lint vet test: vet
go test ./... || go test -v ./... go test ./... || go test -v ./...
fmt: fmt:
@@ -26,7 +26,7 @@ fmt:
lint: lint:
golangci-lint run --timeout 5m golangci-lint run --timeout 5m
check: build test check: build lint test
# Build Docker container # Build Docker container
docker: docker:
@@ -42,3 +42,6 @@ clean:
install: ./secret install: ./secret
cp ./secret $(HOME)/bin/secret cp ./secret $(HOME)/bin/secret
fmt-check:
@test -z "$$(gofmt -l .)" || (echo "Files need formatting:" && gofmt -l . && exit 1)

View File

@@ -1,10 +1,10 @@
package cli package cli
import ( import (
"log"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"log"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings" "strings"

View File

@@ -1,8 +1,8 @@
package cli package cli
import ( import (
"log"
"fmt" "fmt"
"log"
"log/slog" "log/slog"
"os" "os"
"path/filepath" "path/filepath"

View File

@@ -2285,6 +2285,7 @@ func verifyFileExists(t *testing.T, path string) {
} }
// verifyFileNotExists checks if a file does not exist at the given path // verifyFileNotExists checks if a file does not exist at the given path
//
//nolint:unused // kept for future use //nolint:unused // kept for future use
func verifyFileNotExists(t *testing.T, path string) { func verifyFileNotExists(t *testing.T, path string) {
t.Helper() t.Helper()

View File

@@ -1,10 +1,10 @@
package cli package cli
import ( import (
"log"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"log"
"path/filepath" "path/filepath"
"strings" "strings"

View File

@@ -1,9 +1,9 @@
package cli package cli
import ( import (
"log"
"encoding/json" "encoding/json"
"fmt" "fmt"
"log"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"

View File

@@ -1,9 +1,9 @@
package cli package cli
import ( import (
"log"
"encoding/json" "encoding/json"
"fmt" "fmt"
"log"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"

View File

@@ -1,8 +1,8 @@
package cli package cli
import ( import (
"log"
"fmt" "fmt"
"log"
"path/filepath" "path/filepath"
"strings" "strings"
"text/tabwriter" "text/tabwriter"

View File

@@ -26,12 +26,12 @@ type realVault struct {
func (v *realVault) GetDirectory() (string, error) { func (v *realVault) GetDirectory() (string, error) {
return filepath.Join(v.stateDir, "vaults.d", v.name), nil return filepath.Join(v.stateDir, "vaults.d", v.name), nil
} }
func (v *realVault) GetName() string { return v.name } func (v *realVault) GetName() string { return v.name }
func (v *realVault) GetFilesystem() afero.Fs { return v.fs } func (v *realVault) GetFilesystem() afero.Fs { return v.fs }
// Unused by getLongTermPrivateKey — these satisfy VaultInterface. // Unused by getLongTermPrivateKey — these satisfy VaultInterface.
func (v *realVault) AddSecret(string, *memguard.LockedBuffer, bool) error { panic("not used") } func (v *realVault) AddSecret(string, *memguard.LockedBuffer, bool) error { panic("not used") }
func (v *realVault) GetCurrentUnlocker() (Unlocker, error) { panic("not used") } func (v *realVault) GetCurrentUnlocker() (Unlocker, error) { panic("not used") }
func (v *realVault) CreatePassphraseUnlocker(*memguard.LockedBuffer) (*PassphraseUnlocker, error) { func (v *realVault) CreatePassphraseUnlocker(*memguard.LockedBuffer) (*PassphraseUnlocker, error) {
panic("not used") panic("not used")
} }

View File

@@ -284,11 +284,11 @@ func TestSecretNameValidation(t *testing.T) {
{"valid/path/name", true}, {"valid/path/name", true},
{"123valid", true}, {"123valid", true},
{"", false}, {"", false},
{"Valid-Upper-Name", true}, // uppercase allowed {"Valid-Upper-Name", true}, // uppercase allowed
{"2025-11-21-ber1app1-vaultik-test-bucket-AKI", true}, // real-world uppercase key ID {"2025-11-21-ber1app1-vaultik-test-bucket-AKI", true}, // real-world uppercase key ID
{"MixedCase/Path/Name", true}, // mixed case with path {"MixedCase/Path/Name", true}, // mixed case with path
{"invalid name", false}, // space not allowed {"invalid name", false}, // space not allowed
{"invalid@name", false}, // @ not allowed {"invalid@name", false}, // @ not allowed
} }
for _, test := range tests { for _, test := range tests {

View File

@@ -154,4 +154,3 @@ func TestValidateGPGKeyID(t *testing.T) {
}) })
} }
} }