Simplify Vault start on Windows
Some checks failed
Test / tests (darwin-amd64) (push) Successful in 21s
Test / tests (linux-amd64) (push) Successful in 26s
Run Gosec / tests (push) Successful in 51s
Test / tests (linux-arm64) (push) Successful in 3m3s
Test / tests (windows-amd64) (push) Failing after 6m24s

This commit is contained in:
2025-09-09 16:29:58 +02:00
parent d7a9ac2968
commit e3752ce910
3 changed files with 46 additions and 135 deletions

View File

@@ -73,6 +73,11 @@ jobs:
VAULT_SKIP_VERIFY: "true" VAULT_SKIP_VERIFY: "true"
run: | run: |
.\script\vault-setup.ps1 .\script\vault-setup.ps1
artifacts:
paths:
- vault.pid
- vault.out.log
- vault.err.log
- name: Vet - name: Vet
run: go vet -v ./... run: go vet -v ./...

View File

@@ -1,92 +1,31 @@
# Create directories Write-Host "Starting Vault dev server..."
New-Item -ItemType Directory -Path ".\vault-data" -Force -ErrorAction SilentlyContinue $vaultProc = Start-Process vault `
New-Item -ItemType Directory -Path ".\vault-logs" -Force -ErrorAction SilentlyContinue -ArgumentList "server -dev -dev-tls" `
-RedirectStandardOutput "vault.out.log" `
# Start Vault server -RedirectStandardError "vault.err.log" `
$vaultArgs = @( -WindowStyle Hidden `
"server", -PassThru
"-dev", $vaultPid = $vaultProc.Id
"-dev-tls", Write-Host "Vault started with PID $vaultPid"
"-dev-root-token-id=root", Set-Content -Path vault.pid -Value $vaultPid
"-dev-listen-address=127.0.0.1:8200",
"-log-level=debug",
"-log-file=.\vault-logs\vault.log"
)
Write-Output "✅ Starting Vault server..."
$vaultJob = Start-Job -Name "VaultServer" -ScriptBlock {
param($Args)
& ".\vault.exe" $Args
} -ArgumentList $vaultArgs
# Wait a moment for the job to start # Wait a moment for the job to start
Start-Sleep -Seconds 2 Start-Sleep -Seconds 2
# Get the actual process ID from the job # Wait until Vault is ready
$vaultProcess = Get-Process -Name "vault" -ErrorAction SilentlyContinue | Select-Object -First 1 $maxRetries = 15
if ($vaultProcess) { $ok = $false
$vaultProcess.Id | Out-File -FilePath "vault-pid.txt" for ($i=0; $i -lt $maxRetries; $i++) {
Write-Output "✅ Vault process started with PID: $($vaultProcess.Id)"
} else {
Write-Output "❌ Could not find Vault process"
# Show logs
Write-Output "=== LOG (last 20 lines) ==="
Get-Content ".\vault-logs\vault.log" -ErrorAction SilentlyContinue | Select-Object -Last 20
exit 1
}
# Wait for Vault to become ready using port check
$timeout = 30
$counter = 0
$isReady = $false
$vaultPort = 8200
Write-Output "🕐 Waiting for Vault to start on port $vaultPort..."
while ($counter -lt $timeout) {
# Check if process is still running
if (-not (Get-Process -Id $vaultPid -ErrorAction SilentlyContinue)) {
Write-Output "❌ Vault process died unexpectedly!"
break
}
# Check if port is listening
try { try {
$tcpClient = New-Object System.Net.Sockets.TcpClient Invoke-RestMethod -UseBasicParsing -SkipCertificateCheck https://127.0.0.1:8200/v1/sys/health | Out-Null
$asyncResult = $tcpClient.BeginConnect("127.0.0.1", $vaultPort, $null, $null) $ok = $true
$wait = $asyncResult.AsyncWaitHandle.WaitOne(1000, $false) break
if ($wait) {
$tcpClient.EndConnect($asyncResult)
$tcpClient.Close()
$isReady = $true
Write-Output "✅ Vault server is listening on port $vaultPort!"
break
}
$tcpClient.Close()
} catch { } catch {
# Port not ready yet Start-Sleep -Seconds 2
} }
Write-Output "🕐 Waiting for Vault to start... ($counter/$timeout)"
Start-Sleep -Seconds 1
$counter++
} }
if (-not $ok) {
if (-not $isReady) { Write-Error "Vault did not become ready in time"
Write-Output "❌ Vault server failed to start within $timeout seconds" Exit 1
# Show process status
Write-Output "=== PROCESS STATUS ==="
Get-Process -Id $vaultPid -ErrorAction SilentlyContinue | Format-List *
# Show logs
Write-Output "=== LOG (last 20 lines) ==="
Get-Content ".\vault-logs\vault.log" -ErrorAction SilentlyContinue | Select-Object -Last 20
# Cleanup
Stop-Process -Id $vaultPid -Force -ErrorAction SilentlyContinue
exit 1
} }
Write-Host "Vault is up and running."
Write-Output "✅ Vault server started successfully!"

View File

@@ -1,55 +1,22 @@
if (Test-Path "vault.pid") {
$vaultPid = Get-Content "vault.pid"
Write-Host "Stopping Vault process $vaultPid"
Stop-Process -Id $vaultPid -Force
Remove-Item "vault-pid" -Force
} else {
Write-Host "No PID file found, Vault may not have started."
}
# Function to display logs # Function to display logs
function Show-VaultLogs { if (Test-Path "vault.out.log") {
Write-Output "=== VAULT SERVER STDOUT (last 50 lines) ===" Write-Output "=== VAULT SERVER STDOUT (last 25 lines) ==="
Get-Content "vault-logs/stdout.log" -ErrorAction SilentlyContinue | Select-Object -Last 50 Get-Content "vault.out.log" -ErrorAction SilentlyContinue | Select-Object -Last 25
Write-Output "=== VAULT SERVER STDERR (last 50 lines) ===" } else {
Get-Content "vault-logs/stderr.log" -ErrorAction SilentlyContinue | Select-Object -Last 50 Write-Output "No Vault output log found!"
} }
if (Test-Path "vault.err.log") {
# Read PID from file (Gitea alternative to env vars) Write-Output "=== VAULT SERVER STDERR (last 25 lines) ==="
$vaultPid = $null Get-Content "vault.err.log" -ErrorAction SilentlyContinue | Select-Object -Last 25
if (Test-Path "vault-pid.txt") { } else {
$vaultPid = Get-Content "vault-pid.txt" -Raw Write-Output "No Vault error log found!"
Write-Output "✅ Found Vault PID: $vaultPid"
} }
# Check if previous steps failed
$previousStepFailed = $false
if ("${{ steps.start-vault.outcome }}" -eq "failure") {
$previousStepFailed = $true
Write-Output "❌ Vault startup step failed"
}
# Stop the Vault process if we have a PID
if ($vaultPid -and ($vaultPid -ne '')) {
if ($previousStepFailed) {
Write-Output "❌ Previous step failed, showing Vault logs:"
Show-VaultLogs
}
# Stop the Vault process
try {
Stop-Process -Id $vaultPid -Force -ErrorAction Stop
Write-Output "✅ Stopped Vault process $vaultPid"
} catch {
Write-Warning "❌ Failed to stop process $vaultPid: $($_.Exception.Message)"
}
}
# Clean up any remaining Vault processes
$vaultProcesses = Get-Process -Name "vault" -ErrorAction SilentlyContinue
if ($vaultProcesses) {
Write-Output "✅ Found additional Vault processes, stopping them..."
$vaultProcesses | Stop-Process -Force -ErrorAction SilentlyContinue
}
# Always show logs if we're in a failure state
if ($previousStepFailed -or "${{ job.status }}" -eq "failure") {
Write-Output "❌ Job failed, showing final Vault logs:"
Show-VaultLogs
}
# Cleanup PID file
if (Test-Path "vault-pid.txt") {
Remove-Item "vault-pid.txt" -Force
}