Files
homelabstack/apply-compose.ps1
T
ginnoir 1ed7e93298 feat: add GitHub Actions runner workflow and fix portainer network race
- portainer-compose.yml: moves portainer from standalone container to
  compose-managed, giving the portainer_proxy network a compose owner.
  This ensures the network is reliably created before the main stack
  on fresh installs or after Docker state is wiped.
- .github/workflows/deploy.yml: self-hosted runner on valhalla runs
  dc pull + up on push to main, and hot-reloads Caddyfile.
- apply-compose.ps1: adds -Portainer flag to manage portainer-compose.yml.
2026-06-04 14:06:02 -05:00

66 lines
2.4 KiB
PowerShell

# Push .env, Caddyfile, and docker-compose.yml to valhalla, then apply them
# to the live Docker stack.
#
# On valhalla, `dc` is aliased (in ~/.bashrc) to:
# docker compose -f ~/valhalla-lab/docker-compose.yml --env-file ~/valhalla-lab/.env
# It's a shell alias, so we invoke it over SSH with `bash -ic` to load it.
#
# Usage (flags combine; no flags = push & apply all three):
# powershell -File apply-compose.ps1 # .env + Caddyfile + compose
# powershell -File apply-compose.ps1 -EnvFile # .env only
# powershell -File apply-compose.ps1 -Caddy # Caddyfile only + hot-reload Caddy
# powershell -File apply-compose.ps1 -Compose # docker-compose.yml only + pull + up -d
# powershell -File apply-compose.ps1 -Portainer # portainer-compose.yml only + up -d
param(
[switch]$Compose,
[switch]$Caddy,
[switch]$EnvFile,
[switch]$Portainer
)
$ErrorActionPreference = "Stop"
# Make a non-zero exit from scp/ssh abort the script instead of silently continuing.
$PSNativeCommandUseErrorActionPreference = $true
$server = "ginnoir@valhalla"
$composeLocal = Join-Path $PSScriptRoot "docker-compose.yml"
$caddyLocal = Join-Path $PSScriptRoot "Caddyfile"
$envLocal = Join-Path $PSScriptRoot ".env"
$portainerLocal = Join-Path $PSScriptRoot "portainer-compose.yml"
# Default (no flags): push everything.
if (-not $Compose -and -not $Caddy -and -not $EnvFile -and -not $Portainer) {
$EnvFile = $true; $Caddy = $true; $Compose = $true
}
if ($EnvFile) {
Write-Host "Pushing .env ..."
scp $envLocal "${server}:~/valhalla-lab/.env"
}
if ($Caddy) {
Write-Host "Pushing Caddyfile ..."
scp $caddyLocal "${server}:/config/caddy/Caddyfile"
Write-Host "Reloading Caddy ..."
ssh $server "bash -ic 'dc exec caddy caddy reload --config /etc/caddy/Caddyfile'"
}
if ($Compose) {
Write-Host "Pushing docker-compose.yml ..."
scp $composeLocal "${server}:~/valhalla-lab/docker-compose.yml"
Write-Host "Pulling latest images ..."
ssh $server "bash -ic 'dc pull'"
Write-Host "Applying compose changes (recreates only changed containers) ..."
ssh $server "bash -ic 'dc up -d'"
}
if ($Portainer) {
Write-Host "Pushing portainer-compose.yml ..."
scp $portainerLocal "${server}:~/valhalla-lab/portainer-compose.yml"
Write-Host "Applying portainer compose ..."
ssh $server "docker compose -f ~/valhalla-lab/portainer-compose.yml up -d"
}
Write-Host "Done."