Skip to content

Commit f7d15f9

Browse files
committed
Dependency update, linting, API compression
1 parent fad69a4 commit f7d15f9

12 files changed

Lines changed: 371 additions & 174 deletions

File tree

.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.DS_Store
2+
*.idea
3+
*.log
4+
.github/*
5+
bin/*
6+
build/*

.github/workflows/docker.yml

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,36 @@
11
name: Docker
2+
23
on: push
34

45
jobs:
56
push:
67
name: Build and Release Docker Image
78
runs-on: ubuntu-latest
9+
810
steps:
911
- name: Checkout Repo
1012
uses: actions/checkout@v4
1113

1214
- name: Setup Image Name
1315
run: |
14-
echo "IMAGE_ID=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}
16+
echo "IMAGE_ID=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV}
17+
18+
- name: Extract branch name
19+
id: extract_branch
20+
run: |
21+
BRANCH_NAME=${GITHUB_REF#refs/heads/}
22+
echo "BRANCH_NAME=${BRANCH_NAME}" >> ${GITHUB_ENV}
23+
24+
- name: Set Docker Tags
25+
id: set_tags
26+
run: |
27+
if [ "${{ env.BRANCH_NAME }}" == "main" ]; then
28+
echo "CACHETAGS=ghcr.io/${{ env.IMAGE_ID }}:buildcache" >> ${GITHUB_ENV}
29+
echo "TAGS=ghcr.io/${{ env.IMAGE_ID }}:dev" >> ${GITHUB_ENV}
30+
else
31+
echo "CACHETAGS=ghcr.io/${{ env.IMAGE_ID }}:${{ env.BRANCH_NAME }}buildcache" >> ${GITHUB_ENV}
32+
echo "TAGS=ghcr.io/${{ env.IMAGE_ID }}:${{ env.BRANCH_NAME }}" >> ${GITHUB_ENV}
33+
fi
1534
1635
- name: Login to GitHub Packages
1736
uses: docker/login-action@v3
@@ -20,20 +39,15 @@ jobs:
2039
username: ${{ github.actor }}
2140
password: ${{ secrets.GITHUB_TOKEN }}
2241

23-
- name: Docker Metadata
24-
id: meta
25-
uses: docker/metadata-action@v5
26-
with:
27-
images: |
28-
ghcr.io/${{ env.IMAGE_ID }}
29-
tags: |
30-
type=raw,value=dev
31-
32-
- name: Build and push to GitHub Packages
33-
id: docker_build
34-
uses: docker/build-push-action@v2
42+
- name: Set up Docker Buildx
43+
uses: docker/setup-buildx-action@v3
44+
45+
- name: Build and push server Docker image
46+
uses: docker/build-push-action@v5
3547
with:
48+
context: .
49+
file: Dockerfile
3650
push: true
37-
tags: |
38-
ghcr.io/${{ env.IMAGE_ID }}:dev
39-
${{ steps.meta.outputs.tags }}
51+
tags: ${{ env.TAGS }}
52+
cache-from: type=registry,ref=${{ env.CACHETAGS }}
53+
cache-to: type=registry,ref=${{ env.CACHETAGS }},mode=max

Dockerfile

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
1-
FROM golang:1.23.1-alpine3.20 AS build
1+
FROM golang:1.24-alpine3.21 AS build
22

33
RUN apk add git make \
4-
&& apk cache clean \
5-
&& go install github.com/dkorunic/betteralign/cmd/betteralign@latest
4+
&& apk cache clean
65

7-
COPY . /go/src/github.com/globalcyberalliance/domain-security-scanner/
6+
WORKDIR /src
87

9-
WORKDIR /go/src/github.com/globalcyberalliance/domain-security-scanner/
8+
# Install setup dependencies (e.g. betteralign)
9+
COPY Makefile ./
10+
RUN make setup
11+
12+
# Cache Go modules and local vendored dependencies needed for replacements
13+
COPY go.mod go.sum ./
14+
RUN go mod download
15+
16+
COPY . /src
1017

1118
RUN make
1219

1320
FROM scratch
1421

15-
COPY --from=build /go/src/github.com/globalcyberalliance/domain-security-scanner/bin/dss /dss
22+
COPY --from=build /src/bin/dss /usr/bin/dss
1623
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
1724

18-
ENTRYPOINT [ "/dss" ]
25+
WORKDIR /app
26+
27+
EXPOSE 8080
28+
29+
ENTRYPOINT ["dss"]
30+
31+
CMD ["serve", "api"]

Makefile

Lines changed: 98 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,145 @@
1-
PROJECT := github.com/globalcyberalliance/domain-security-scanner/v3
2-
GO := $(shell which go 2>/dev/null)
1+
# Project configuration.
2+
PROJECT := github.com/globalcyberalliance/domain-security-scanner/v3
3+
CGO_ENABLED := 0
4+
5+
# Tool paths.
6+
GO := $(shell which go 2>/dev/null)
37
GOFIELDALIGNMENT := $(shell which betteralign 2>/dev/null)
4-
GOFUMPT := $(shell which gofumpt 2>/dev/null)
5-
GOLINTER := $(shell which golangci-lint 2>/dev/null)
6-
GONILAWAY := $(shell which nilaway 2>/dev/null)
7-
GO_BENCH_FLAGS := -short -bench=. -benchmem
8-
GO_BENCH := $(GO) test $(GO_BENCH_FLAGS)
9-
GO_BUILD := CGO_ENABLED=0 $(GO) build -ldflags "-s -w" -trimpath
10-
GO_FORMAT := $(GOFUMPT) -w
11-
GO_OPTIMIZE := $(GOFIELDALIGNMENT) -fix
12-
GO_TEST := $(GO) test -v -short
13-
GO_TIDY := $(GO) mod tidy
14-
TARGETS := bin/dss
8+
GOFUMPT := $(shell which gofumpt 2>/dev/null)
9+
GOLINTER := $(shell which golangci-lint 2>/dev/null)
10+
GONILAWAY := $(shell which nilaway 2>/dev/null)
11+
12+
# Build configuration.
13+
GO_PRIVATE := GOPRIVATE=github.com/globalcyberalliance
14+
BUILD_FLAGS := -ldflags "-s -w" -trimpath
15+
16+
# Common build variables.
17+
GO_BUILD_BASE := $(GO_PRIVATE) CGO_ENABLED=$(CGO_ENABLED)
18+
GO_BUILD := $(GO_BUILD_BASE) $(GO) build $(BUILD_FLAGS)
19+
20+
# Other tool commands.
21+
GO_FORMAT := $(GOFUMPT) -w
22+
GO_OPTIMIZE := $(GOFIELDALIGNMENT) -fix
23+
GO_TEST := $(GO) test -v -short
24+
GO_TIDY := $(GO) mod tidy
1525

26+
# Build targets.
27+
TARGETS := bin/dss
28+
29+
# Default target.
1630
all: check-dependencies prepare optimize $(TARGETS) clean
1731

32+
# Development build (no optimization).
1833
dev: prepare $(TARGETS)
1934

35+
# Pattern rule for building binaries.
2036
bin/%: $(shell find . -name "*.go" -type f)
2137
@echo "Building $@..."
2238
@if [ "$(MAKECMDGOALS)" != "dev" ]; then \
23-
cd build && $(GO_BUILD) -o ../$@ $(PROJECT)/cmd/$*; \
24-
else \
25-
$(GO_BUILD) -o $@ $(PROJECT)/cmd/$*; \
26-
fi
39+
cd build && $(GO_BUILD) -o ../$@ $(PROJECT)/cmd/$*; \
40+
else \
41+
$(GO_BUILD) -o $@ $(PROJECT)/cmd/$*; \
42+
fi
2743

44+
# Dependency checks.
2845
check-dependencies:
2946
@echo "Checking dependencies..."
30-
@if [ -z "${GO}" ]; then \
31-
echo "Cannot find 'go' in your $$PATH"; \
47+
@if [ -z "$(GO)" ]; then \
48+
echo "Error: Cannot find 'go' in your PATH"; \
3249
exit 1; \
3350
fi
34-
@if [ -z "${GOFIELDALIGNMENT}" ]; then \
35-
echo "Cannot find 'betteralign' in your $$PATH"; \
51+
@if [ -z "$(GOFIELDALIGNMENT)" ]; then \
52+
echo "Error: Cannot find 'betteralign' in your PATH"; \
3653
exit 1; \
3754
fi
3855

56+
# Cleanup tasks.
3957
clean:
4058
@echo "Cleaning temporary build directory..."
4159
@rm -rf build
4260

61+
clean-all: clean
62+
@echo "Cleaning all build artifacts..."
63+
@rm -rf bin
64+
65+
# Code formatting and optimization.
4366
format:
44-
@if [ -z "${GOFUMPT}" ]; then \
45-
echo "Cannot find 'gofumpt' in your $$PATH"; \
67+
@if [ -z "$(GOFUMPT)" ]; then \
68+
echo "Error: Cannot find 'gofumpt' in your PATH"; \
4669
exit 1; \
4770
fi
4871
@echo "Formatting code..."
4972
@$(GO_FORMAT) $(PWD)
5073

5174
lint:
52-
@if [ -z "${GOLINTER}" ]; then \
53-
echo "Cannot find 'golangci-lint' in your $$PATH"; \
75+
@if [ -z "$(GOLINTER)" ]; then \
76+
echo "Error: Cannot find 'golangci-lint' in your PATH"; \
5477
exit 1; \
5578
fi
5679
@echo "Running linter..."
5780
@$(GOLINTER) run ./...
5881

59-
nil:
60-
@if [ -z "${GONILAWAY}" ]; then \
61-
echo "Cannot find 'nilaway' in your $$PATH"; \
82+
lint-fix:
83+
@if [ -z "$(GOLINTER)" ]; then \
84+
echo "Error: Cannot find 'golangci-lint' in your PATH"; \
85+
exit 1; \
86+
fi
87+
@echo "Running linter with autofix..."
88+
@$(GOLINTER) run --fix ./...
89+
90+
nil-check:
91+
@if [ -z "$(GONILAWAY)" ]; then \
92+
echo "Error: Cannot find 'nilaway' in your PATH"; \
6293
exit 1; \
6394
fi
6495
@echo "Running nilaway..."
6596
@$(GONILAWAY) ./...
6697

6798
optimize:
6899
@echo "Creating temporary build directory..."
69-
@cp -r cmd go.* pkg ./build/
100+
@cp -r cmd go.* pkg build/
70101
@echo "Optimizing struct field alignment..."
71102
@cd build && $(GO_OPTIMIZE) ./... > /dev/null 2>&1 || true
72103

104+
# Preparation tasks.
73105
prepare:
74106
@echo "Cleaning previous builds..."
75107
@rm -rf bin build
76108
@mkdir -p bin build
77-
@$(GO_TIDY)
109+
@$(GO_TIDY)
110+
111+
# Development setup.
112+
setup:
113+
@echo "Installing development dependencies..."
114+
@$(GO) install github.com/dkorunic/betteralign/cmd/betteralign@latest
115+
@$(GO) install mvdan.cc/gofumpt@latest
116+
@$(GO) install go.uber.org/nilaway/cmd/nilaway@latest
117+
@$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
118+
119+
# Testing.
120+
test:
121+
@echo "Running tests..."
122+
@$(GO_TEST) ./...
123+
124+
benchmark:
125+
@echo "Running benchmarks..."
126+
@$(GO) test -short -bench=. -benchmem ./...
127+
128+
# Help target.
129+
help:
130+
@echo "Available targets:"
131+
@echo " all - Build optimized binaries (default)"
132+
@echo " dev - Build development binaries (no optimization)"
133+
@echo " clean - Remove temporary build directory"
134+
@echo " clean-all - Remove all build artifacts"
135+
@echo " format - Format Go code"
136+
@echo " lint - Run linter"
137+
@echo " lint-fix - Run linter with autofix"
138+
@echo " nil-check - Run nilaway null pointer analysis"
139+
@echo " test - Run tests"
140+
@echo " benchmark - Run benchmarks"
141+
@echo " setup - Install development dependencies"
142+
@echo " help - Show this help message"
143+
144+
# Declare phony targets.
145+
.PHONY: all dev clean clean-all format lint lint-fix nil-check optimize prepare setup test benchmark help check-dependencies

cmd/dss/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var (
2626
Use: "dss",
2727
Short: "Scan a domain's DNS records.",
2828
Long: "Scan a domain's DNS records.\nhttps://github.com/globalcyberalliance/domain-security-scanner",
29-
Version: "3.0.17",
29+
Version: "3.0.18",
3030
PersistentPreRun: func(cmd *cobra.Command, args []string) {
3131
var logWriter io.Writer
3232

go.mod

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,39 @@ module github.com/globalcyberalliance/domain-security-scanner/v3
33
go 1.23.1
44

55
require (
6-
github.com/danielgtaylor/huma/v2 v2.28.0
6+
github.com/danielgtaylor/huma/v2 v2.33.0
77
github.com/emersion/go-imap v1.2.1
8-
github.com/go-chi/chi/v5 v5.2.0
8+
github.com/go-chi/chi/v5 v5.2.2
99
github.com/go-chi/cors v1.2.1
10-
github.com/go-chi/httprate v0.14.1
11-
github.com/goccy/go-json v0.10.4
12-
github.com/miekg/dns v1.1.62
13-
github.com/panjf2000/ants/v2 v2.11.0
10+
github.com/go-chi/httprate v0.15.0
11+
github.com/goccy/go-json v0.10.5
12+
github.com/klauspost/compress v1.18.0
13+
github.com/miekg/dns v1.1.66
14+
github.com/panjf2000/ants/v2 v2.11.3
1415
github.com/pkg/errors v0.9.1
15-
github.com/rs/zerolog v1.33.0
16-
github.com/spf13/cast v1.7.1
17-
github.com/spf13/cobra v1.8.1
16+
github.com/rs/zerolog v1.34.0
17+
github.com/spf13/cast v1.9.2
18+
github.com/spf13/cobra v1.9.1
1819
github.com/stretchr/testify v1.10.0
19-
github.com/wneessen/go-mail v0.6.1
20+
github.com/wneessen/go-mail v0.6.2
2021
gopkg.in/yaml.v3 v3.0.1
2122
)
2223

2324
require (
24-
github.com/cespare/xxhash/v2 v2.3.0 // indirect
2525
github.com/davecgh/go-spew v1.1.1 // indirect
2626
github.com/emersion/go-sasl v0.0.0-20241020182733-b788ff22d5a6 // indirect
2727
github.com/inconshreveable/mousetrap v1.1.0 // indirect
28+
github.com/klauspost/cpuid/v2 v2.2.11 // indirect
2829
github.com/mattn/go-colorable v0.1.14 // indirect
2930
github.com/mattn/go-isatty v0.0.20 // indirect
3031
github.com/pmezard/go-difflib v1.0.0 // indirect
31-
github.com/spf13/pflag v1.0.5 // indirect
32-
golang.org/x/crypto v0.35.0 // indirect
33-
golang.org/x/mod v0.22.0 // indirect
34-
golang.org/x/net v0.36.0 // indirect
35-
golang.org/x/sync v0.11.0 // indirect
36-
golang.org/x/sys v0.30.0 // indirect
37-
golang.org/x/text v0.22.0 // indirect
38-
golang.org/x/tools v0.29.0 // indirect
32+
github.com/spf13/pflag v1.0.6 // indirect
33+
github.com/zeebo/xxh3 v1.0.2 // indirect
34+
golang.org/x/crypto v0.39.0 // indirect
35+
golang.org/x/mod v0.25.0 // indirect
36+
golang.org/x/net v0.41.0 // indirect
37+
golang.org/x/sync v0.15.0 // indirect
38+
golang.org/x/sys v0.33.0 // indirect
39+
golang.org/x/text v0.26.0 // indirect
40+
golang.org/x/tools v0.34.0 // indirect
3941
)

0 commit comments

Comments
 (0)