Skip to content
Open
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ workflow refuses a tag whose version has no entry here.

## [Unreleased]

### Fixed

- `urbex bootstrap` refuses a platform created by urbex 0.1.0, whose forge
is still Gitea: Forgejo can't open Gitea 1.24's database, and starting it
there left the forge down. Nothing is changed; the message says how to
start the platform again on Forgejo (see Upgrading).

## [0.1.0] - 2026-11-17

The first preview release: urbex as binaries for Linux and macOS (amd64,
Expand Down
55 changes: 55 additions & 0 deletions internal/bootstrap/forgeguard.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package bootstrap

import (
"errors"
"fmt"
"io/fs"
"os"
"path/filepath"
"regexp"
"strings"
)

// forgeComposeCopy is the forge's compose file as its LXC runs it, copied
// into the GitOps repo by every bootstrap (the gitea role), 0.1.0's
// included.
var forgeComposeCopy = filepath.Join(PlatformStacksDir, "gitea", "compose.yaml")

// giteaImage matches the forge image of a platform created by urbex
// 0.1.0: Gitea, which Forgejo replaced (ADR-0034).
var giteaImage = regexp.MustCompile(`(?m)^\s*image:\s*(docker\.io/)?gitea/gitea[:@]\S*`)

// ErrPlatformRunsGitea is returned by Run on a platform whose forge is
// still Gitea: Forgejo can't open the database of Gitea 1.23 and later.
var ErrPlatformRunsGitea = errors.New("the platform's forge is Gitea")

// refuseGiteaPlatform stops a bootstrap that would start Forgejo on
// Gitea's data (urbforge/urbex-cli#116): Forgejo refuses a database
// migrated by Gitea past 1.22 and exits, and the forge stays down.
// It reads only the GitOps repo; nothing has been changed yet.
func refuseGiteaPlatform(gitopsRepoPath string) error {
data, err := os.ReadFile(filepath.Join(gitopsRepoPath, forgeComposeCopy))
if errors.Is(err, fs.ErrNotExist) {
return nil
}
if err != nil {
return err
}
m := giteaImage.Find(data)
if m == nil {
return nil
}
return fmt.Errorf(`%w (%s, in %s): this platform was created by urbex 0.1.0.
This urbex runs Forgejo, which can't read the database of Gitea 1.24, so it
won't touch the forge or anything else on this platform. To move to this
release, start the platform again:

urbex destroy <env> # in each project, for each environment (teardown requires it);
# the applications' named volumes go with their LXCs: back them up first
urbex teardown # the platform and its LXCs, Gitea's repositories with them
urbex bootstrap # a new platform, on Forgejo

then push your projects' repositories again from your clones and 'urbex apply'
their environments. Or keep using urbex 0.1.0 on this platform.
See "Upgrading" in the CHANGELOG (0.2.0)`, ErrPlatformRunsGitea, strings.TrimSpace(regexp.MustCompile(`\s+`).ReplaceAllString(string(m), " ")), forgeComposeCopy)
}
6 changes: 6 additions & 0 deletions internal/bootstrap/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"net/http"
"os"
"path/filepath"
"slices"
"time"

"github.com/urbforge/urbex-cli/internal/credentials"
Expand Down Expand Up @@ -102,6 +103,11 @@ func (o *Orchestrator) Run(ctx context.Context, opts Options) error {
}
fmt.Fprintf(o.Out, "Base services already present on Proxmox: %v\n", alreadyPresent)
fmt.Fprintf(o.Out, "Base services to provision: %v\n", toCreate)
if slices.Contains(alreadyPresent, Hostname("gitea")) {
if err := refuseGiteaPlatform(opts.GitOpsRepoPath); err != nil {
return err
}
}

ips, prefixLen, err := allocateIPs(o.Config)
if err != nil {
Expand Down
51 changes: 51 additions & 0 deletions internal/bootstrap/orchestrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,3 +588,54 @@ func (k *fakeKomodo) TagResource(ctx context.Context, kind, name string, tags ..
k.f.tags[kind+" "+name] = tags
return nil
}

// A platform created by urbex 0.1.0 runs Gitea 1.24, whose database
// Forgejo can't open (urbforge/urbex-cli#116): bootstrap refuses before
// it changes anything, and says how to move on.
func TestRun_RefusesAPlatformStillOnGitea(t *testing.T) {
dir := t.TempDir()
for _, f := range []string{"terraform/base/terraform.tfstate", "platform/gitea/compose.yaml"} {
if err := os.MkdirAll(filepath.Dir(filepath.Join(dir, f)), 0o755); err != nil {
t.Fatal(err)
}
}
os.WriteFile(filepath.Join(dir, "terraform/base/terraform.tfstate"), []byte("{}"), 0o644)
compose := "services:\n gitea:\n image: gitea/gitea:1.24\n restart: unless-stopped\n"
os.WriteFile(filepath.Join(dir, "platform/gitea/compose.yaml"), []byte(compose), 0o644)

o, runner, _ := newRunOrchestrator(t, &fakeProxmox{hostnames: []string{"urbex-gitea", "urbex-komodo"}})
err := o.Run(context.Background(), Options{GitOpsRepoPath: dir})
if !errors.Is(err, ErrPlatformRunsGitea) {
t.Fatalf("Run: %v, want ErrPlatformRunsGitea", err)
}
for _, want := range []string{"gitea/gitea:1.24", "urbex 0.1.0", "urbex teardown", "urbex destroy", "back them up", "Upgrading"} {
if !strings.Contains(err.Error(), want) {
t.Errorf("the error doesn't say %q:\n%v", want, err)
}
}
if len(runner.calls) != 0 {
t.Errorf("ran %v before refusing", runner.calls)
}
if _, err := os.Stat(filepath.Join(dir, "ansible")); err == nil {
t.Error("materialized the assets before refusing")
}

// The same platform on Forgejo goes on.
os.WriteFile(filepath.Join(dir, "platform/gitea/compose.yaml"), []byte("services:\n gitea:\n image: codeberg.org/forgejo/forgejo:15.0.11@sha256:5d05\n"), 0o644)
if err := refuseGiteaPlatform(dir); err != nil {
t.Errorf("a Forgejo platform refused: %v", err)
}
// So does a platform without the copy (a new one).
if err := refuseGiteaPlatform(t.TempDir()); err != nil {
t.Errorf("no compose copy refused: %v", err)
}
if err := refuseGiteaPlatform(dir + "/nope"); err != nil {
t.Error(err)
}
for _, img := range []string{"docker.io/gitea/gitea:1.24", "gitea/gitea@sha256:abcd"} {
os.WriteFile(filepath.Join(dir, "platform/gitea/compose.yaml"), []byte("services:\n gitea:\n image: "+img+"\n"), 0o644)
if !errors.Is(refuseGiteaPlatform(dir), ErrPlatformRunsGitea) {
t.Errorf("%s not refused", img)
}
}
}