db4f1ba6fc
Revised the section on building and running Docker images to include a recommended PowerShell script for publishing to a Docker registry. Added detailed options and examples for using the script, while maintaining the manual build instructions for flexibility. This update improves clarity and usability for developers deploying the application.
173 lines
4.7 KiB
PowerShell
173 lines
4.7 KiB
PowerShell
#!/usr/bin/env pwsh
|
|
<#
|
|
.SYNOPSIS
|
|
Builds and publishes the TSA Chapter Organizer Docker image to the registry.
|
|
|
|
.DESCRIPTION
|
|
This script builds the Docker image from the WebApp Dockerfile and pushes it
|
|
to the Docker registry at docker-registry.kolpacksoftware.com.
|
|
|
|
.PARAMETER Tag
|
|
The tag to use for the Docker image. Defaults to "latest".
|
|
|
|
.PARAMETER Registry
|
|
The Docker registry URL. Defaults to "docker-registry.kolpacksoftware.com".
|
|
|
|
.PARAMETER ImageName
|
|
The name of the Docker image. Defaults to "tsa-chapter-organizer".
|
|
|
|
.PARAMETER BuildConfiguration
|
|
The build configuration to use. Defaults to "Release".
|
|
|
|
.EXAMPLE
|
|
.\publish-docker.ps1
|
|
|
|
.EXAMPLE
|
|
.\publish-docker.ps1 -Tag "v1.0.0"
|
|
|
|
.EXAMPLE
|
|
.\publish-docker.ps1 -Tag "latest" -Registry "docker-registry.kolpacksoftware.com"
|
|
#>
|
|
|
|
param(
|
|
[string]$Tag = "latest",
|
|
[string]$Registry = "docker-registry.kolpacksoftware.com",
|
|
[string]$ImageName = "tsa-chapter-organizer",
|
|
[string]$BuildConfiguration = "Release"
|
|
)
|
|
|
|
$ErrorActionPreference = "Continue"
|
|
|
|
# Colors for output
|
|
function Write-Info {
|
|
param([string]$Message)
|
|
Write-Host $Message -ForegroundColor Cyan
|
|
}
|
|
|
|
function Write-Success {
|
|
param([string]$Message)
|
|
Write-Host $Message -ForegroundColor Green
|
|
}
|
|
|
|
function Write-ErrorMsg {
|
|
param([string]$Message)
|
|
Write-Host $Message -ForegroundColor Red
|
|
}
|
|
|
|
function Write-WarningMsg {
|
|
param([string]$Message)
|
|
Write-Host $Message -ForegroundColor Yellow
|
|
}
|
|
|
|
# Check if Docker is available
|
|
Write-Info "Checking Docker installation..."
|
|
try {
|
|
$dockerVersion = docker --version
|
|
Write-Success "Docker found: $dockerVersion"
|
|
} catch {
|
|
Write-ErrorMsg "Docker is not installed or not in PATH. Please install Docker Desktop."
|
|
exit 1
|
|
}
|
|
|
|
# Check if Docker daemon is running
|
|
Write-Info "Checking Docker daemon..."
|
|
try {
|
|
docker info | Out-Null
|
|
Write-Success "Docker daemon is running"
|
|
} catch {
|
|
Write-ErrorMsg "Docker daemon is not running. Please start Docker Desktop."
|
|
exit 1
|
|
}
|
|
|
|
# Set up paths
|
|
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$rootPath = $scriptPath
|
|
$dockerfilePath = Join-Path $rootPath "WebApp\Dockerfile"
|
|
|
|
# Verify Dockerfile exists
|
|
if (-not (Test-Path $dockerfilePath)) {
|
|
Write-ErrorMsg "Dockerfile not found at: $dockerfilePath"
|
|
exit 1
|
|
}
|
|
|
|
# Build image names
|
|
$localImageName = "${ImageName}:${Tag}"
|
|
$registryImageName = "${Registry}/${ImageName}:${Tag}"
|
|
|
|
Write-Info "========================================="
|
|
Write-Info "Docker Build and Publish Script"
|
|
Write-Info "========================================="
|
|
Write-Info "Local Image: $localImageName"
|
|
Write-Info "Registry Image: $registryImageName"
|
|
Write-Info "Build Config: $BuildConfiguration"
|
|
Write-Info "========================================="
|
|
Write-Host ""
|
|
|
|
# Step 1: Build the Docker image
|
|
Write-Info "Step 1: Building Docker image..."
|
|
Write-Info "Building from: $rootPath"
|
|
Write-Info "Dockerfile: $dockerfilePath"
|
|
Write-Host ""
|
|
|
|
$buildArgs = @(
|
|
"build",
|
|
"-f", $dockerfilePath,
|
|
"-t", $localImageName,
|
|
"--build-arg", "BUILD_CONFIGURATION=$BuildConfiguration",
|
|
$rootPath
|
|
)
|
|
& docker $buildArgs
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-ErrorMsg "[ERROR] Docker build failed with exit code $LASTEXITCODE"
|
|
exit 1
|
|
}
|
|
Write-Success "[OK] Docker image built successfully: $localImageName"
|
|
|
|
Write-Host ""
|
|
|
|
# Step 2: Tag the image for the registry
|
|
Write-Info "Step 2: Tagging image for registry..."
|
|
docker tag $localImageName $registryImageName
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-ErrorMsg "[ERROR] Docker tag failed with exit code $LASTEXITCODE"
|
|
exit 1
|
|
}
|
|
Write-Success "[OK] Image tagged successfully: $registryImageName"
|
|
|
|
Write-Host ""
|
|
|
|
# Step 3: Push to registry
|
|
Write-Info "Step 3: Pushing image to registry..."
|
|
Write-Info "Registry: $Registry"
|
|
Write-Host ""
|
|
|
|
docker push $registryImageName
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-ErrorMsg "[ERROR] Docker push failed with exit code $LASTEXITCODE"
|
|
Write-WarningMsg "Make sure you are logged in to the registry:"
|
|
Write-WarningMsg " docker login $Registry"
|
|
exit 1
|
|
}
|
|
Write-Success "[OK] Image pushed successfully to registry"
|
|
|
|
Write-Host ""
|
|
Write-Info "========================================="
|
|
Write-Success "[OK] Build and publish completed successfully!"
|
|
Write-Info "========================================="
|
|
Write-Info "Image available at: $registryImageName"
|
|
Write-Host ""
|
|
|
|
# Get image digest if available
|
|
$null = docker inspect $registryImageName --format '{{.RepoDigests}}' 2>&1
|
|
if ($LASTEXITCODE -eq 0) {
|
|
$imageInfo = docker inspect $registryImageName --format '{{.RepoDigests}}'
|
|
if ($imageInfo) {
|
|
Write-Info "Image digest: $imageInfo"
|
|
}
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Info "You can now pull this image with:"
|
|
Write-Host " docker pull $registryImageName" -ForegroundColor Gray
|