diff --git a/Dockerfile b/Dockerfile index 81de087..b654200 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,20 @@ FROM golang:1.26-alpine AS build WORKDIR /src -COPY go.mod ./ + +# Keep dependency resolution deterministic. Do NOT run `go mod tidy` before +# source files are present: it can remove required modules because no packages +# are visible yet. +COPY go.mod go.sum ./ RUN go mod download + COPY cmd ./cmd COPY internal ./internal + +# Fail early with a useful message if a repository/.dockerignore rule ever +# drops the application's internal data package from the build context. +RUN test -f /src/internal/data/store.go \ + && test -f /src/internal/data/schema.sql + RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/neuralhunt ./cmd/server \ && CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/neuralhunt-client ./cmd/client diff --git a/go.mod b/go.mod index 88b2824..1dcd9df 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module neuralhunt -go 1.23.0 +go 1.26 require ( github.com/go-chi/chi/v5 v5.2.1 diff --git a/run-load.ps1 b/run-load.ps1 index 10938a1..5167247 100644 --- a/run-load.ps1 +++ b/run-load.ps1 @@ -1,45 +1,45 @@ -param( - [switch]$NoEnv -) - -$ErrorActionPreference = "Stop" -Set-StrictMode -Version Latest - -$ProjectRoot = $PSScriptRoot -Set-Location $ProjectRoot - -function Import-DotEnv { - param([Parameter(Mandatory = $true)][string]$Path) - - Get-Content -LiteralPath $Path | ForEach-Object { - $line = $_.Trim() - if (-not $line -or $line.StartsWith("#")) { return } - - $parts = $line.Split("=", 2) - if ($parts.Count -ne 2) { return } - - $name = $parts[0].Trim() - $value = $parts[1].Trim() - if (-not $name) { return } - - if (($value.StartsWith('"') -and $value.EndsWith('"')) -or - ($value.StartsWith("'") -and $value.EndsWith("'"))) { - $value = $value.Substring(1, $value.Length - 2) - } - - [Environment]::SetEnvironmentVariable($name, $value, "Process") - } -} - -if (-not $NoEnv) { - $envFile = Join-Path $ProjectRoot ".env" - if (Test-Path -LiteralPath $envFile) { - Import-DotEnv -Path $envFile - } - else { - Write-Warning ".env nicht gefunden. Es werden vorhandene Umgebungsvariablen und Programm-Defaults verwendet." - } -} - -go run ./cmd/loadtest -exit $LASTEXITCODE +param( + [switch]$NoEnv +) + +$ErrorActionPreference = "Stop" +Set-StrictMode -Version Latest + +$ProjectRoot = $PSScriptRoot +Set-Location $ProjectRoot + +function Import-DotEnv { + param([Parameter(Mandatory = $true)][string]$Path) + + Get-Content -LiteralPath $Path | ForEach-Object { + $line = $_.Trim() + if (-not $line -or $line.StartsWith("#")) { return } + + $parts = $line.Split("=", 2) + if ($parts.Count -ne 2) { return } + + $name = $parts[0].Trim() + $value = $parts[1].Trim() + if (-not $name) { return } + + if (($value.StartsWith('"') -and $value.EndsWith('"')) -or + ($value.StartsWith("'") -and $value.EndsWith("'"))) { + $value = $value.Substring(1, $value.Length - 2) + } + + [Environment]::SetEnvironmentVariable($name, $value, "Process") + } +} + +if (-not $NoEnv) { + $envFile = Join-Path $ProjectRoot ".env" + if (Test-Path -LiteralPath $envFile) { + Import-DotEnv -Path $envFile + } + else { + Write-Warning ".env nicht gefunden. Es werden vorhandene Umgebungsvariablen und Programm-Defaults verwendet." + } +} + +go run ./cmd/loadtest +exit $LASTEXITCODE