Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
|---|---|
Expand Down
18 changes: 17 additions & 1 deletion internal/compose/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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))
}
}
Expand Down
13 changes: 13 additions & 0 deletions internal/compose/ops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down