Files
homelabstack/apply-compose.ps1
T
ginnoir bb46b1c10e feat: migrate stack to Portainer git-managed, rename project to valhalla-lab
- Rename project from htpc-download-box to valhalla-lab (directory + dc alias)
- Remove portainer and watchtower from compose; run standalone outside managed stack
  to prevent self-termination during Portainer-triggered redeployments
- Add portainer_proxy external network shared by caddy and standalone portainer
  so Caddy can route to Portainer via Docker DNS without them being in the same stack
- Carve out POST /api/stacks/webhooks/* in Caddyfile so Portainer webhooks can
  reach through the internal_only guard without exposing the full UI
- Update apply-compose.ps1 and sync-prod.ps1 paths from htpc-download-box to valhalla-lab
2026-06-03 23:09:53 -05:00

56 lines
1.9 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
param(
[switch]$Compose,
[switch]$Caddy,
[switch]$EnvFile
)
$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"
# Default (no flags): push everything.
if (-not $Compose -and -not $Caddy -and -not $EnvFile) {
$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'"
}
Write-Host "Done."