From 3a7dfd5aff09ad076192c200b435ded3bb5da1e6 Mon Sep 17 00:00:00 2001 From: "nate@necloud.us" Date: Wed, 13 Aug 2025 19:14:02 -0400 Subject: [PATCH] Add Docker build script --- docker-build.ps1 | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 docker-build.ps1 diff --git a/docker-build.ps1 b/docker-build.ps1 new file mode 100644 index 0000000..fef805d --- /dev/null +++ b/docker-build.ps1 @@ -0,0 +1,51 @@ +# PowerShell script to build and push Docker image for Spelling Practice App + +# Set variables +$IMAGE_NAME = "ghcr.io/nmemmert/spelling" +$VERSION = (Get-Content -Path "version.json" | ConvertFrom-Json).version + +Write-Host "๐Ÿ”จ Building Docker image ${IMAGE_NAME}:${VERSION}..." -ForegroundColor Cyan + +# Build the image +docker build -t ${IMAGE_NAME}:${VERSION} -t ${IMAGE_NAME}:latest . + +Write-Host "โœ… Build completed." -ForegroundColor Green +Write-Host "๐Ÿงช Testing the image..." -ForegroundColor Cyan + +# Run container for testing +docker run --name spelling-test -d -p 3001:3000 ${IMAGE_NAME}:${VERSION} + +# Wait for container to start +Start-Sleep -Seconds 5 + +# Test health endpoint +try { + $response = Invoke-WebRequest -Uri "http://localhost:3001/health" -UseBasicParsing + if ($response.StatusCode -eq 200) { + Write-Host "โœ… Health check passed!" -ForegroundColor Green + } else { + Write-Host "โŒ Health check failed with status $($response.StatusCode)" -ForegroundColor Red + docker logs spelling-test + docker stop spelling-test + docker rm spelling-test + exit 1 + } +} catch { + Write-Host "โŒ Health check failed: $_" -ForegroundColor Red + docker logs spelling-test + docker stop spelling-test + docker rm spelling-test + exit 1 +} + +# Stop and remove test container +docker stop spelling-test +docker rm spelling-test + +Write-Host "๐Ÿ“ค Pushing image to GitHub Container Registry..." -ForegroundColor Cyan +docker push ${IMAGE_NAME}:${VERSION} +docker push ${IMAGE_NAME}:latest + +Write-Host "๐Ÿš€ Successfully built and pushed ${IMAGE_NAME}:${VERSION}" -ForegroundColor Green +Write-Host "Press any key to exit..." +$null = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")