mirror of
https://github.com/kellymichels/zscripts-token-savers
synced 2026-10-06 07:08:17 +00:00
* fix(zdeploy): build docker stacks that come from a Dockerfile Mirrors the fix in the private scripts repo; the code is identical in both, only the config differs. The docker kind ran `docker compose pull` then `docker compose up -d`. That is right for a stack of published images and wrong for one built from a Dockerfile in the tree, where there is nothing to pull. `up -d` builds only when the image is MISSING, so the first deploy works and every one after it uploads the new code, starts the old image, and reports success. A project opts into building with deploy.build, which runs `docker compose build --pull` so the base image is refreshed at the same time. Stacks that pull are unaffected. The example config documents the flag on the docker project, next to the existing note about startApp, because the failure is silent and nobody goes looking for a setting they do not know exists. CHECKSUMS.txt regenerated, since two covered scripts changed. 286 tests pass, 1 skipped. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * fix(checksums): hash the scripts as git checks them out, not as a tool wrote them CI failed on the two files this branch touches while the same suite passed here. The manifest was right about the wrong bytes. .gitattributes pins *.ps1 to eol=crlf, and its comment says why: it makes these files byte-identical on every platform, which is what lets CHECKSUMS.txt hold one hash per file rather than one per OS. The edit that added Get-DockerImageStep was applied by a script that wrote LF, so the working copy stopped matching the pin. zchecksums then faithfully recorded the LF hashes, and every checkout that honours .gitattributes - including CI - disagreed. Nothing was wrong with the committed content: git normalises on the way in, so the objects were always correct. Only the local working copy and the manifest taken from it were off. Re-materialised both files through git so they carry the endings the attribute pins, then regenerated the manifest from those. 286 tests pass, 1 skipped. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
83 lines
3.5 KiB
PowerShell
83 lines
3.5 KiB
PowerShell
# How a docker stack gets its images, and the deploy that shipped nothing.
|
|
#
|
|
# Invoke-Pester .\tests
|
|
#
|
|
# `docker compose pull` is right for a stack of published images - Prometheus,
|
|
# Grafana, docker-mailserver - and wrong for one built from a Dockerfile in the
|
|
# tree, where there is nothing to pull.
|
|
#
|
|
# The trap is what happens after. `docker compose up -d` builds only when the
|
|
# image is MISSING, so the first deploy of a build-from-source stack works and
|
|
# every one after it uploads the new code, starts the OLD image, and reports
|
|
# success. Green deploy, healthy container, and the change is not in it. That
|
|
# is the failure this helper exists to prevent, and it is worse than an error
|
|
# because nothing about it looks wrong.
|
|
#
|
|
# ZHelpers.ps1 is dot-sourced rather than zdeploy.ps1: zdeploy executes its
|
|
# main flow on load, helpers only define functions.
|
|
|
|
BeforeAll {
|
|
. (Join-Path (Split-Path -Parent $PSScriptRoot) "ZHelpers.ps1")
|
|
|
|
function New-Proj { param($Build)
|
|
if ($null -eq $Build) { return [pscustomobject]@{ deploy = [pscustomobject]@{ gitPull = $true } } }
|
|
return [pscustomobject]@{ deploy = [pscustomobject]@{ build = $Build } }
|
|
}
|
|
}
|
|
|
|
Describe 'Get-DockerImageStep - build here, or pull from a registry' {
|
|
|
|
It 'pulls by default, so every existing docker stack is unaffected' {
|
|
$step = Get-DockerImageStep -Proj (New-Proj $null) -RemotePath '/home/u/stack/x'
|
|
$step.Command | Should -BeLike '*docker compose pull*'
|
|
$step.Command | Should -Not -BeLike '*build*'
|
|
}
|
|
|
|
It 'pulls for a project with no deploy block at all' {
|
|
$step = Get-DockerImageStep -Proj ([pscustomobject]@{}) -RemotePath '/home/u/stack/x'
|
|
$step.Command | Should -BeLike '*docker compose pull*'
|
|
}
|
|
|
|
It 'builds when the project asks to be built' {
|
|
$step = Get-DockerImageStep -Proj (New-Proj $true) -RemotePath '/home/u/stack/x'
|
|
$step.Command | Should -BeLike '*docker compose build*'
|
|
$step.Command | Should -Not -BeLike '*compose pull*'
|
|
}
|
|
|
|
It 'still pulls when build is explicitly false' {
|
|
$step = Get-DockerImageStep -Proj (New-Proj $false) -RemotePath '/home/u/stack/x'
|
|
$step.Command | Should -BeLike '*docker compose pull*'
|
|
}
|
|
|
|
It 'refreshes the base image on a build, so a rebuild is not pinned to the first one' {
|
|
$step = Get-DockerImageStep -Proj (New-Proj $true) -RemotePath '/home/u/stack/x'
|
|
$step.Command | Should -BeLike '*--pull*'
|
|
}
|
|
|
|
It 'runs in the project directory: <Build>' -ForEach @(
|
|
@{ Build = $true }
|
|
@{ Build = $false }
|
|
) {
|
|
$step = Get-DockerImageStep -Proj (New-Proj $Build) -RemotePath '/home/u/stack/ablecamera'
|
|
$step.Command | Should -BeLike 'cd /home/u/stack/ablecamera &&*'
|
|
}
|
|
|
|
It 'labels the step with what it actually does: <Build>' -ForEach @(
|
|
@{ Build = $true; Expected = 'docker compose build' }
|
|
@{ Build = $false; Expected = 'docker compose pull' }
|
|
) {
|
|
(Get-DockerImageStep -Proj (New-Proj $Build) -RemotePath '/x').Label | Should -Be $Expected
|
|
}
|
|
}
|
|
|
|
Describe 'the docker deploy uses it' {
|
|
|
|
It 'no longer hardcodes compose pull' {
|
|
$text = Get-Content -Raw (Join-Path (Split-Path -Parent $PSScriptRoot) "zdeploy.ps1")
|
|
$body = $text.Substring($text.IndexOf('function Invoke-DockerDeploy'))
|
|
$body = $body.Substring(0, $body.IndexOf('function Invoke-ZTokensPublish'))
|
|
$body | Should -Match 'Get-DockerImageStep'
|
|
$body | Should -Not -Match '"docker compose pull"'
|
|
}
|
|
}
|