Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ RUN go mod download
COPY . .

# Version build argument
ARG VERSION=dev
ARG VERSION=1.0.0

# Build the binary with optimizations for linux/amd64
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags="-w -s -X main.Version=${VERSION}" \
-ldflags="-w -s -X github.com/kljama/netscan/internal/version.Version=${VERSION}" \
-o netscan \
Comment on lines 18 to 24

Copilot AI Mar 26, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defaulting the Docker build ARG VERSION to 1.0.0 will stamp images built without an explicit --build-arg VERSION=... as 1.0.0, which can be misleading in dev/CI. Consider defaulting this back to dev (or unknown) and passing the real version explicitly for release builds.

Copilot uses AI. Check for mistakes.
./cmd/netscan

Expand Down
2 changes: 1 addition & 1 deletion MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -1388,7 +1388,7 @@ netscan exposes HTTP health check endpoints for monitoring, container orchestrat
| Field | Type | Description |
|-------|------|-------------|
| `status` | string | Overall service health: `"healthy"` (all systems operational), `"degraded"` (InfluxDB unreachable but monitoring continues), or `"unhealthy"` (critical failure) |
| `version` | string | Application version string (currently hardcoded `"1.0.0"`, TODO: inject at build time) |
| `version` | string | Application version string (injected at build time via ldflags) |
| `uptime` | string | Human-readable time since service started (e.g., `"2h15m30s"`) |
Comment on lines 1390 to 1392

Copilot AI Mar 26, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section correctly notes that the health version field is injected via ldflags, but elsewhere in MANUAL.md the manual build instructions still reference -X main.Version=.... That command should be updated to -X github.com/kljama/netscan/internal/version.Version=... (and ideally keep the same dev fallback) so the documentation stays consistent with the new version package.

Copilot uses AI. Check for mistakes.
| `device_count` | int | Total number of devices currently managed by StateManager |
| `snmp_suspended_devices` | int | Number of devices currently suspended by SNMP circuit breaker |
Expand Down
3 changes: 2 additions & 1 deletion cmd/netscan/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/kljama/netscan/internal/influx"
"github.com/kljama/netscan/internal/state"
"github.com/kljama/netscan/internal/version"
"github.com/rs/zerolog/log"
)

Expand Down Expand Up @@ -113,7 +114,7 @@ func (hs *HealthServer) GetHealthMetrics() HealthResponse {

return HealthResponse{
Status: status,
Version: Version,
Version: version.Version,
Uptime: time.Since(hs.startTime).String(),
DeviceCount: hs.stateMgr.Count(),
SNMPSuspendedDevices: hs.stateMgr.GetSNMPSuspendedCount(),
Expand Down
10 changes: 9 additions & 1 deletion cmd/netscan/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"flag"
"fmt"
"os"
"os/signal"
"runtime"
Expand All @@ -17,18 +18,25 @@ import (
"github.com/kljama/netscan/internal/logger"
"github.com/kljama/netscan/internal/monitoring"
"github.com/kljama/netscan/internal/state"
"github.com/kljama/netscan/internal/version"
"github.com/rs/zerolog/log"
"golang.org/x/time/rate"
)

func main() {
configPath := flag.String("config", "config.yml", "Path to configuration file")
showVersion := flag.Bool("version", false, "Print version and exit")
flag.Parse()

if *showVersion {
fmt.Printf("netscan version %s\n", version.Version)
return
}

// Initialize structured logging
logger.Setup(false) // Set to true for debug mode

log.Info().Msg("netscan starting up...")
log.Info().Str("version", version.Version).Msg("netscan starting up...")
cfg, err := config.LoadConfig(*configPath)
if err != nil {
log.Fatal().Err(err).Msg("failed to load config")
Expand Down
4 changes: 2 additions & 2 deletions deploy/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ build_binary() {

# Get version info
local version
version=$(git describe --tags --always --dirty 2>/dev/null || echo "dev")
version=$(git describe --tags --always --dirty 2>/dev/null || echo "1.0.0")

Copilot AI Mar 26, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git describe fallback was changed to 1.0.0; if the repo has no tags (or git metadata isn’t available), the binary will be stamped as 1.0.0 even though it’s not a release build. Prefer a fallback like dev/unknown and reserve 1.0.0 for explicit release/tag builds.

Suggested change
version=$(git describe --tags --always --dirty 2>/dev/null || echo "1.0.0")
version=$(git describe --tags --always --dirty 2>/dev/null || echo "dev")

Copilot uses AI. Check for mistakes.
log_info "Building version: $version"

if ! go build -ldflags "-X main.Version=$version" -o "$BINARY" ./cmd/netscan; then
if ! go build -ldflags "-X github.com/kljama/netscan/internal/version.Version=$version" -o "$BINARY" ./cmd/netscan; then
error_exit "Failed to build netscan binary"
fi

Expand Down
2 changes: 1 addition & 1 deletion cmd/netscan/version.go → internal/version/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package version

// Version is the application version.
// It is set at build time using -ldflags.
Expand Down
4 changes: 2 additions & 2 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ BINARY=netscan
cd "$PROJECT_ROOT"

# Determine version
VERSION=$(git describe --tags --always --dirty 2>/dev/null || echo "dev")
VERSION=$(git describe --tags --always --dirty 2>/dev/null || echo "1.0.0")
echo "Building version: $VERSION"
Comment on lines 14 to 16

Copilot AI Mar 26, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fallback when git describe fails was changed from dev to 1.0.0, which will incorrectly label untagged/local builds as a released version. Consider keeping the fallback as dev (or similar) and only using 1.0.0 when building an actual release/tag.

Copilot uses AI. Check for mistakes.

# Build the binary
Expand All @@ -22,6 +22,6 @@ if [ -f "$BINARY" ]; then
fi

echo "Building netscan..."
go build -ldflags "-X main.Version=$VERSION" -o $BINARY ./cmd/netscan
go build -ldflags "-X github.com/kljama/netscan/internal/version.Version=$VERSION" -o $BINARY ./cmd/netscan

echo "Build complete: $BINARY"
Loading