diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f1481b..b2ad5bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,9 @@ - **`AF_CHART` names the chart to install from on Kubernetes**: a chart folder or `.tgz`, such as a test build or a copy for an air-gapped cluster, or a mirror's address, in place of the published chart. Installs and upgrades both use it. +- **Upgrading to a release candidate on Docker and Podman**: with `AF_APP_IMAGE` naming a + candidate's image, an upgrade with `--version 7.9.0` takes the app's `7.9.0-rc.1538.38` as that + version, where it rolled back saying the app reported another one. ### Changed diff --git a/README.md b/README.md index b7823f8..a939a55 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ Run `ansibleforms-installer --help` to see every flag. - **Where:** `/usr/local/bin` for root, else `~/.local/bin`. - **With sudo:** give its full path, as sudo's `secure_path` often leaves out `/usr/local/bin`. - **Another chart:** on Kubernetes, `AF_CHART` names a chart folder, a `.tgz` or a mirror's address. +- **A release candidate:** on Docker and Podman, `--version 7.9.0` with its images in `AF_APP_IMAGE`, `AF_RUNNER_IMAGE` and `AF_RTE_IMAGE`. | Command | What it does | |---|---| diff --git a/internal/compose/ops.go b/internal/compose/ops.go index cb151ac..d5faca0 100644 --- a/internal/compose/ops.go +++ b/internal/compose/ops.go @@ -41,6 +41,22 @@ func backupDir(st *state.State) string { const dumpScript = `MYSQL_PWD="$MYSQL_ROOT_PASSWORD" mysqldump -uroot --single-transaction --routines --triggers --set-gtid-purged=OFF --add-drop-database --databases AnsibleForms` const restoreScript = `MYSQL_PWD="$MYSQL_ROOT_PASSWORD" mysql -uroot` +// isVersion tells whether the version the app reports after an upgrade is the one it went to: +// that version, or a release candidate of it (7.9.0-rc.1538.38 for 7.9.0) when AF_APP_IMAGE +// names the image, as it does to try a candidate before its release. +// +// Args: +// +// got: the version the app reports. +// want: the version upgraded to (7.9.0). +// +// Returns: +// +// True when it is that version. +func isVersion(got, want string) bool { + return got == want || os.Getenv("AF_APP_IMAGE") != "" && strings.HasPrefix(got, want+"-rc.") +} + // Backup dumps a controller's database and keeps a copy of its compose file and .env. // // Args: @@ -309,7 +325,7 @@ func Upgrade(ctx context.Context, st *state.State, to string, prep *Prep) (*Undo if err != nil { return undo, err } - if got != "" && got != to { + if got != "" && !isVersion(got, to) { return undo, errors.New(i18n.T("compose.wrongVersion", "got", got, "want", to)) } } diff --git a/internal/compose/ops_test.go b/internal/compose/ops_test.go index a513111..3eefd5b 100644 --- a/internal/compose/ops_test.go +++ b/internal/compose/ops_test.go @@ -25,6 +25,19 @@ func folder(t *testing.T, files map[string]string) string { return dir } +// the version an upgrade checks: the one it went to, or a release candidate of it only with +// AF_APP_IMAGE naming the image +func TestIsVersion(t *testing.T) { + t.Setenv("AF_APP_IMAGE", "") + if !isVersion("7.9.0", "7.9.0") || isVersion("7.9.0-rc.1538.38", "7.9.0") || isVersion("7.8.0", "7.9.0") { + t.Error("without AF_APP_IMAGE") + } + t.Setenv("AF_APP_IMAGE", "ghcr.io/ansibleforms/ansibleforms:7.9.0-rc.1538.38") + if !isVersion("7.9.0-rc.1538.38", "7.9.0") || isVersion("7.9.0-rc.1", "7.9.1") || isVersion("7.9.0-beta", "7.9.0") { + t.Error("with AF_APP_IMAGE") + } +} + // a project taken over from docker-compose.yaml has it renamed docker-compose.yml, and the // compose files compose would not read moved aside: the upgrade's file is then the one read func TestRepoComposeName(t *testing.T) {