From df7374a1645f72550a7c3dad143cf8a1cee77fbf Mon Sep 17 00:00:00 2001 From: Teg79 Date: Tue, 17 Nov 2026 17:06:43 +0100 Subject: [PATCH 1/4] feat(forge): Forgejo 15 LTS, pinned by digest, in place of Gitea 1.24 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0182yxsfwRowwnxCfgrQwjnA --- .../roles/gitea/templates/docker-compose.yml.j2 | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/platform/ansible/roles/gitea/templates/docker-compose.yml.j2 b/platform/ansible/roles/gitea/templates/docker-compose.yml.j2 index a21d50d..84b95bd 100644 --- a/platform/ansible/roles/gitea/templates/docker-compose.yml.j2 +++ b/platform/ansible/roles/gitea/templates/docker-compose.yml.j2 @@ -7,7 +7,8 @@ # urbforge/urbex. services: gitea: - image: gitea/gitea:1.24 + # Forgejo LTS (urbforge/urbex-cli#112), pinned by digest. + image: codeberg.org/forgejo/forgejo:15.0.11@sha256:5d050e6d623e540923ff54b1c0c7acf41c3f9174a6c7ad515cc0c63d703fcd22 labels: urbex.kind: "platform" urbex.service: "gitea" @@ -18,14 +19,14 @@ services: # By internal name (docs/decisions/0027-service-conventions.md): the # container registry's token endpoint is derived from ROOT_URL, so it # must be reachable from every LXC that pulls images. - - GITEA__server__DOMAIN={{ gitea_url | urlsplit('hostname') }} - - GITEA__server__ROOT_URL={{ gitea_url }}/ - - GITEA__security__INSTALL_LOCK=true - - GITEA__service__DISABLE_REGISTRATION=true - - GITEA__packages__ENABLED=true + - FORGEJO__server__DOMAIN={{ gitea_url | urlsplit('hostname') }} + - FORGEJO__server__ROOT_URL={{ gitea_url }}/ + - FORGEJO__security__INSTALL_LOCK=true + - FORGEJO__service__DISABLE_REGISTRATION=true + - FORGEJO__packages__ENABLED=true # Komodo's webhook listener is on the LAN; Gitea only delivers to # public addresses by default. - - GITEA__webhook__ALLOWED_HOST_LIST=private + - FORGEJO__webhook__ALLOWED_HOST_LIST=private volumes: - gitea-data:/data ports: From d29e6be3aee26ce46d54c48e57fa687ba1c9e8a4 Mon Sep 17 00:00:00 2001 From: Teg79 Date: Tue, 17 Nov 2026 17:09:24 +0100 Subject: [PATCH 2/4] refactor(forge): internal/forge; forge credentials and git.forgeUrl, the Gitea names still read Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0182yxsfwRowwnxCfgrQwjnA --- internal/bootstrap/orchestrator_test.go | 16 ++--- internal/bootstrap/platform.go | 24 ++++---- internal/bootstrap/teardown.go | 6 +- internal/bootstrap/teardown_test.go | 4 +- internal/cli/provision_shared.go | 10 ++-- internal/cli/status_projects.go | 4 +- internal/credentials/credentials.go | 55 ++++++++++++++--- internal/credentials/credentials_test.go | 66 ++++++++++++++++++--- internal/discover/proposal.go | 2 +- internal/{gitea => forge}/client.go | 11 ++-- internal/{gitea => forge}/client_test.go | 2 +- internal/platform/config.go | 12 +++- internal/platform/config_test.go | 25 +++++++- internal/platform/template.go | 2 +- internal/provision/orchestrator.go | 8 +-- internal/provision/orchestrator_test.go | 12 ++-- internal/rollout/rollout.go | 8 +-- internal/rollout/rollout_test.go | 12 ++-- platform/ansible/roles/gitea/tasks/main.yml | 2 +- 19 files changed, 199 insertions(+), 82 deletions(-) rename internal/{gitea => forge}/client.go (97%) rename internal/{gitea => forge}/client_test.go (99%) diff --git a/internal/bootstrap/orchestrator_test.go b/internal/bootstrap/orchestrator_test.go index 8b135c6..420ae35 100644 --- a/internal/bootstrap/orchestrator_test.go +++ b/internal/bootstrap/orchestrator_test.go @@ -41,7 +41,7 @@ func (f *fakeRunner) Run(ctx context.Context, c Command) error { func validConfig() *platform.Config { return &platform.Config{ Domain: "example.com", - Git: platform.GitConfig{GiteaURL: "https://git.example.com", Org: "urbex"}, + Git: platform.GitConfig{ForgeURL: "https://git.example.com", Org: "urbex"}, Proxmox: platform.ProxmoxConfig{ APIURL: "https://proxmox.example.internal:8006/api2/json", Node: "pve", @@ -420,7 +420,7 @@ func TestRun_SetsUpGiteaAndKomodoAndPushesGitOpsRepo(t *testing.T) { } creds := o.Credentials - if creds.GiteaAdminPassword == "" || creds.KomodoDBPassword == "" || creds.KeycloakAdminPassword == "" || creds.TechnitiumAdminPassword == "" { + if creds.ForgeAdminPassword == "" || creds.KomodoDBPassword == "" || creds.KeycloakAdminPassword == "" || creds.TechnitiumAdminPassword == "" { t.Errorf("expected platform secrets to be generated, got %+v", creds) } if creds.TechnitiumToken != "technitium-token" { @@ -443,7 +443,7 @@ func TestRun_SetsUpGiteaAndKomodoAndPushesGitOpsRepo(t *testing.T) { } ansible := runner.calls[2] env := strings.Join(ansible.Env, "\n") - for _, want := range []string{"URBEX_GITEA_ADMIN_PASSWORD=" + creds.GiteaAdminPassword, "URBEX_KOMODO_JWT_SECRET=" + creds.KomodoJWTSecret} { + for _, want := range []string{"URBEX_FORGE_ADMIN_PASSWORD=" + creds.ForgeAdminPassword, "URBEX_KOMODO_JWT_SECRET=" + creds.KomodoJWTSecret} { if !strings.Contains(env, want) { t.Errorf("expected %q in ansible env", want) } @@ -452,10 +452,10 @@ func TestRun_SetsUpGiteaAndKomodoAndPushesGitOpsRepo(t *testing.T) { t.Error("the proxmox token must not be passed to ansible") } - if fp.tokens["urbex-cli"] != creds.GiteaAdminPassword || len(fp.tokens) != 1 { + if fp.tokens["urbex-cli"] != creds.ForgeAdminPassword || len(fp.tokens) != 1 { t.Errorf("expected exactly the cli token, created with the admin password, got %v", fp.tokens) } - if creds.GiteaToken != "token-urbex-cli" || creds.KomodoOnboardingKey != "O_onboarding_O" { + if creds.ForgeToken != "token-urbex-cli" || creds.KomodoOnboardingKey != "O_onboarding_O" { t.Errorf("token/onboarding key not stored in credentials: %+v", creds) } if creds.KomodoAPIKey != "K_key_K" || creds.KomodoAPISecret != "S_secret_S" { @@ -525,18 +525,18 @@ func TestRun_SetsUpGiteaAndKomodoAndPushesGitOpsRepo(t *testing.T) { if !strings.Contains(string(inventory), "gitea_registry: git.urbex.example.com:3000") { t.Errorf("expected gitea_registry in inventory vars:\n%s", inventory) } - if strings.Contains(string(inventory), creds.GiteaAdminPassword) { + if strings.Contains(string(inventory), creds.ForgeAdminPassword) { t.Error("secrets must never be written to the inventory") } // Re-running keeps existing secrets and tokens instead of rotating them. - password, token := creds.GiteaAdminPassword, creds.GiteaToken + password, token := creds.ForgeAdminPassword, creds.ForgeToken technitiumPassword, technitiumToken := creds.TechnitiumAdminPassword, creds.TechnitiumToken fp.tokens, fp.apiKeys, fp.onboardingKeys = nil, 0, 0 if err := o.Run(context.Background(), Options{GitOpsRepoPath: dir}); err != nil { t.Fatalf("second Run: %v", err) } - if creds.GiteaAdminPassword != password || creds.GiteaToken != token || len(fp.tokens) != 0 || fp.apiKeys != 0 || fp.onboardingKeys != 0 { + if creds.ForgeAdminPassword != password || creds.ForgeToken != token || len(fp.tokens) != 0 || fp.apiKeys != 0 || fp.onboardingKeys != 0 { t.Errorf("expected no secret/token rotation on re-run (tokens=%v apiKeys=%d onboardingKeys=%d)", fp.tokens, fp.apiKeys, fp.onboardingKeys) } if creds.TechnitiumAdminPassword != technitiumPassword || creds.TechnitiumToken != technitiumToken { diff --git a/internal/bootstrap/platform.go b/internal/bootstrap/platform.go index e91b6c4..a7538e6 100644 --- a/internal/bootstrap/platform.go +++ b/internal/bootstrap/platform.go @@ -8,7 +8,7 @@ import ( "time" "github.com/urbforge/urbex-cli/internal/credentials" - "github.com/urbforge/urbex-cli/internal/gitea" + "github.com/urbforge/urbex-cli/internal/forge" "github.com/urbforge/urbex-cli/internal/gitsync" "github.com/urbforge/urbex-cli/internal/komodo" "github.com/urbforge/urbex-cli/internal/platform" @@ -214,7 +214,7 @@ type Clients struct { // DefaultClients returns Clients backed by the real HTTP clients and git. func DefaultClients() Clients { return Clients{ - Gitea: func(u, t string) GiteaAPI { return gitea.New(u, t) }, + Gitea: func(u, t string) GiteaAPI { return forge.New(u, t) }, Komodo: func(u, k, s string) KomodoAPI { return komodo.New(u, k, s) }, SyncRepo: SyncRepo, PullRepo: PullRepo, @@ -225,7 +225,7 @@ func DefaultClients() Clients { // ansibleSecretEnv are the secrets the base-service roles read with // lookup('env', ...). ensureSecrets generates any that are missing. var ansibleSecretEnv = []string{ - "URBEX_GITEA_ADMIN_PASSWORD", + "URBEX_FORGE_ADMIN_PASSWORD", "URBEX_KOMODO_ADMIN_PASSWORD", "URBEX_KOMODO_DB_PASSWORD", "URBEX_KOMODO_JWT_SECRET", @@ -290,16 +290,16 @@ func (o *Orchestrator) setupPlatform(ctx context.Context, clients Clients, gitop if err := g.WaitReady(ctx, 3*time.Minute); err != nil { return err } - if creds.GiteaToken == "" { - token, err := g.CreateToken(ctx, GiteaAdminUser, creds.GiteaAdminPassword, "urbex-cli", cliTokenScopes) + if creds.ForgeToken == "" { + token, err := g.CreateToken(ctx, GiteaAdminUser, creds.ForgeAdminPassword, "urbex-cli", cliTokenScopes) if err != nil { return err } - if err := creds.Update(func(c *credentials.Credentials) { c.GiteaToken = token }); err != nil { + if err := creds.Update(func(c *credentials.Credentials) { c.ForgeToken = token }); err != nil { return fmt.Errorf("saving gitea token: %w", err) } } - g = clients.Gitea(ep.GiteaURL, creds.GiteaToken) + g = clients.Gitea(ep.GiteaURL, creds.ForgeToken) if err := g.EnsureOrg(ctx, o.Config.Git.Org); err != nil { return err } @@ -336,10 +336,10 @@ func (o *Orchestrator) setupPlatform(ctx context.Context, clients Clients, gitop return fmt.Errorf("saving komodo onboarding key: %w", err) } } - if err := k.EnsureGitProviderAccount(ctx, internal.Registry, false, GiteaAdminUser, creds.GiteaToken); err != nil { + if err := k.EnsureGitProviderAccount(ctx, internal.Registry, false, GiteaAdminUser, creds.ForgeToken); err != nil { return err } - if err := k.EnsureDockerRegistryAccount(ctx, internal.Registry, GiteaAdminUser, creds.GiteaToken); err != nil { + if err := k.EnsureDockerRegistryAccount(ctx, internal.Registry, GiteaAdminUser, creds.ForgeToken); err != nil { return err } @@ -351,9 +351,11 @@ func (o *Orchestrator) setupPlatform(ctx context.Context, clients Clients, gitop name, value string secret bool }{ + // Named for Gitea still: the Actions of existing platforms read + // them (docs/decisions/0034-forgejo-lts-forge.md). {"URBEX_GITEA_URL", internal.GiteaURL, false}, {"URBEX_GITEA_USER", GiteaAdminUser, false}, - {"URBEX_GITEA_TOKEN", creds.GiteaToken, true}, + {"URBEX_GITEA_TOKEN", creds.ForgeToken, true}, {"URBEX_ORG", o.Config.Git.Org, false}, // Where the reconciler sends its heartbeat and its errors, which // Grafana alerts on. @@ -422,7 +424,7 @@ func (o *Orchestrator) setupPlatform(ctx context.Context, clients Clients, gitop return fmt.Errorf("writing .sops.yaml: %w", err) } - if err := clients.SyncRepo(ctx, gitopsRepoPath, ep.RepoURL(o.Config.Git.Org, GitOpsRepoName), creds.GiteaToken, "urbex bootstrap"); err != nil { + if err := clients.SyncRepo(ctx, gitopsRepoPath, ep.RepoURL(o.Config.Git.Org, GitOpsRepoName), creds.ForgeToken, "urbex bootstrap"); err != nil { return fmt.Errorf("syncing gitops repo: %w", err) } fmt.Fprintf(o.Out, "GitOps repo pushed to %s.\n", ep.RepoURL(o.Config.Git.Org, GitOpsRepoName)) diff --git a/internal/bootstrap/teardown.go b/internal/bootstrap/teardown.go index b89dca3..a71f33c 100644 --- a/internal/bootstrap/teardown.go +++ b/internal/bootstrap/teardown.go @@ -63,8 +63,8 @@ func (o *Orchestrator) Teardown(ctx context.Context, opts TeardownOptions) error o.Progress.Begin(PhaseTeardownCheck) // Gitea has the latest GitOps repo - for the last time. repoURL := ep.RepoURL(o.Config.Git.Org, GitOpsRepoName) - if o.Credentials.GiteaToken != "" { - if err := clients.PullRepo(ctx, opts.GitOpsRepoPath, repoURL, o.Credentials.GiteaToken); err != nil { + if o.Credentials.ForgeToken != "" { + if err := clients.PullRepo(ctx, opts.GitOpsRepoPath, repoURL, o.Credentials.ForgeToken); err != nil { fmt.Fprintf(o.Out, "Warning: could not update the GitOps repo from Gitea (%v); using the local copy.\n", err) } } @@ -77,7 +77,7 @@ func (o *Orchestrator) Teardown(ctx context.Context, opts TeardownOptions) error tfDir := filepath.Join(opts.GitOpsRepoPath, "terraform", "base") var repos []string - if g, ok := clients.Gitea(ep.GiteaURL, o.Credentials.GiteaToken).(repoLister); ok && o.Credentials.GiteaToken != "" { + if g, ok := clients.Gitea(ep.GiteaURL, o.Credentials.ForgeToken).(repoLister); ok && o.Credentials.ForgeToken != "" { repos, _ = g.ListOrgRepos(ctx, o.Config.Git.Org) // best effort: Gitea may already be gone } fmt.Fprintln(o.Out, "This destroys the Urbex platform on Proxmox:") diff --git a/internal/bootstrap/teardown_test.go b/internal/bootstrap/teardown_test.go index 4f89549..c26c03c 100644 --- a/internal/bootstrap/teardown_test.go +++ b/internal/bootstrap/teardown_test.go @@ -44,7 +44,7 @@ func TestTeardown_RefusesWhileProjectEnvironmentsExist(t *testing.T) { func TestTeardown_WithoutYesOnlyReports(t *testing.T) { o, runner, fp := newRunOrchestrator(t, &fakeProxmox{}) - o.Credentials.GiteaToken = "tok" + o.Credentials.ForgeToken = "tok" dir := gitopsRepo(t) err := o.Teardown(context.Background(), TeardownOptions{GitOpsRepoPath: dir}) @@ -86,7 +86,7 @@ func TestTeardown_DestroysBaseServicesAndForgetsGeneratedCredentials(t *testing. if strings.Join(args, ",") != "init,destroy -auto-approve -parallelism=2" { t.Errorf("unexpected terraform calls: %v", args) } - if o.Credentials.KomodoAPIKey != "" || o.Credentials.GiteaToken != "" { + if o.Credentials.KomodoAPIKey != "" || o.Credentials.ForgeToken != "" { t.Error("the generated credentials of the destroyed platform should be forgotten") } if o.Credentials.ProxmoxToken == "" || o.Credentials.AgeKey == "" { diff --git a/internal/cli/provision_shared.go b/internal/cli/provision_shared.go index 7f896e6..8f9466a 100644 --- a/internal/cli/provision_shared.go +++ b/internal/cli/provision_shared.go @@ -15,7 +15,7 @@ import ( "github.com/urbforge/urbex-cli/internal/bootstrap" "github.com/urbforge/urbex-cli/internal/credentials" - "github.com/urbforge/urbex-cli/internal/gitea" + "github.com/urbforge/urbex-cli/internal/forge" "github.com/urbforge/urbex-cli/internal/imageref" "github.com/urbforge/urbex-cli/internal/komodo" "github.com/urbforge/urbex-cli/internal/manifest" @@ -128,10 +128,10 @@ func newProvisionOrchestrator(cmd *cobra.Command, manifestPath, gitopsRepoPath, Out: out, Images: &imageref.Resolver{HTTP: &http.Client{Timeout: 30 * time.Second}}, SyncGitOps: func(ctx context.Context, path, message string) error { - return bootstrap.SyncRepo(ctx, path, ep.RepoURL(cfg.Git.Org, bootstrap.GitOpsRepoName), creds.GiteaToken, message) + return bootstrap.SyncRepo(ctx, path, ep.RepoURL(cfg.Git.Org, bootstrap.GitOpsRepoName), creds.ForgeToken, message) }, RefreshGitOps: func(ctx context.Context, path string) error { - return bootstrap.PullRepo(ctx, path, ep.RepoURL(cfg.Git.Org, bootstrap.GitOpsRepoName), creds.GiteaToken) + return bootstrap.PullRepo(ctx, path, ep.RepoURL(cfg.Git.Org, bootstrap.GitOpsRepoName), creds.ForgeToken) }, } ro := newRollout(cfg, creds, ep, repoDir, out) @@ -160,13 +160,13 @@ func newProvisionOrchestrator(cmd *cobra.Command, manifestPath, gitopsRepoPath, func newRollout(cfg *platform.Config, creds *credentials.Credentials, ep bootstrap.Endpoints, repoDir string, out io.Writer) *rollout.Rollout { internal, _ := bootstrap.InternalEndpointsFor(cfg) // fails only where ep did return &rollout.Rollout{ - Gitea: gitea.New(ep.GiteaURL, creds.GiteaToken), + Gitea: forge.New(ep.GiteaURL, creds.ForgeToken), Komodo: komodo.New(ep.KomodoURL, creds.KomodoAPIKey, creds.KomodoAPISecret), Git: rollout.GitCLI{}, Endpoints: ep, Internal: internal, Org: cfg.Git.Org, - Token: creds.GiteaToken, + Token: creds.ForgeToken, WebhookSecret: creds.KomodoWebhookSecret, RepoDir: repoDir, Out: out, diff --git a/internal/cli/status_projects.go b/internal/cli/status_projects.go index f49fd0d..47e9470 100644 --- a/internal/cli/status_projects.go +++ b/internal/cli/status_projects.go @@ -202,12 +202,12 @@ func quickTunnelRoute(ctx context.Context, ip string) string { // Action commits too, so what status reads is current; on failure it // warns and goes on with the local copy. func refreshForStatus(ctx context.Context, warn func(string), cfg *platform.Config, creds *credentials.Credentials, repoPath string) { - if creds.GiteaToken == "" { + if creds.ForgeToken == "" { return } ep, err := bootstrap.EndpointsFor(cfg) if err == nil { - err = bootstrap.PullRepo(ctx, repoPath, ep.RepoURL(cfg.Git.Org, bootstrap.GitOpsRepoName), creds.GiteaToken) + err = bootstrap.PullRepo(ctx, repoPath, ep.RepoURL(cfg.Git.Org, bootstrap.GitOpsRepoName), creds.ForgeToken) } if err != nil { warn(fmt.Sprintf("could not update the GitOps repo from Gitea: %v - showing the local copy", err)) diff --git a/internal/credentials/credentials.go b/internal/credentials/credentials.go index b3f9889..c139254 100644 --- a/internal/credentials/credentials.go +++ b/internal/credentials/credentials.go @@ -5,7 +5,7 @@ // // Some values are supplied by the user (Proxmox/Cloudflare tokens, age // key); the platform secrets (admin passwords, Komodo API and onboarding -// keys, Gitea token) are generated by urbex bootstrap and persisted to the same file +// keys, the forge's token) are generated by urbex bootstrap and persisted to the same file // via Update. package credentials @@ -29,8 +29,8 @@ type Credentials struct { AgeKey string `yaml:"ageKey,omitempty"` // Generated by urbex bootstrap. - GiteaAdminPassword string `yaml:"giteaAdminPassword,omitempty"` - GiteaToken string `yaml:"giteaToken,omitempty"` + ForgeAdminPassword string `yaml:"forgeAdminPassword,omitempty"` + ForgeToken string `yaml:"forgeToken,omitempty"` KomodoAdminPassword string `yaml:"komodoAdminPassword,omitempty"` KomodoDBPassword string `yaml:"komodoDbPassword,omitempty"` KomodoJWTSecret string `yaml:"komodoJwtSecret,omitempty"` @@ -58,8 +58,8 @@ func (c *Credentials) fields() []struct { {"URBEX_PROXMOX_TOKEN", &c.ProxmoxToken}, {"URBEX_CLOUDFLARE_TOKEN", &c.CloudflareToken}, {"URBEX_AGE_KEY", &c.AgeKey}, - {"URBEX_GITEA_ADMIN_PASSWORD", &c.GiteaAdminPassword}, - {"URBEX_GITEA_TOKEN", &c.GiteaToken}, + {"URBEX_FORGE_ADMIN_PASSWORD", &c.ForgeAdminPassword}, + {"URBEX_FORGE_TOKEN", &c.ForgeToken}, {"URBEX_KOMODO_ADMIN_PASSWORD", &c.KomodoAdminPassword}, {"URBEX_KOMODO_DB_PASSWORD", &c.KomodoDBPassword}, {"URBEX_KOMODO_JWT_SECRET", &c.KomodoJWTSecret}, @@ -75,13 +75,36 @@ func (c *Credentials) fields() []struct { } } +// legacyNames are the names of the forge's credentials before it was +// Forgejo (docs/decisions/0034-forgejo-lts-forge.md in urbforge/urbex): +// still read, from the environment and from credentials.yaml, so that a +// workspace written by urbex 0.1.0 works unchanged. The new names win. +var legacyNames = map[string]struct{ env, key string }{ + "URBEX_FORGE_ADMIN_PASSWORD": {"URBEX_GITEA_ADMIN_PASSWORD", "giteaAdminPassword"}, + "URBEX_FORGE_TOKEN": {"URBEX_GITEA_TOKEN", "giteaToken"}, +} + +// canonical is the current name of the credential whose environment +// variable is name, which may be a legacy one. +func canonical(name string) string { + for current, old := range legacyNames { + if name == old.env { + return current + } + } + return name +} + // Load reads credentials from environment variables first (URBEX_*, see -// fields), then fills in anything still missing from +// fields; legacy names too), then fills in anything still missing from // ~/.urbex/credentials.yaml if that file exists. func Load() (*Credentials, error) { c := &Credentials{} for _, f := range c.fields() { *f.ptr = os.Getenv(f.env) + if old, ok := legacyNames[f.env]; ok && *f.ptr == "" { + *f.ptr = os.Getenv(old.env) + } } path, err := DefaultPath() if err != nil { @@ -138,6 +161,18 @@ func loadFile(path string) (*Credentials, error) { if err := yaml.Unmarshal(data, &c); err != nil { return nil, fmt.Errorf("parsing %s: %w", path, err) } + // The legacy keys fill what the new ones leave empty; the next Update + // writes them under the new keys. + var all map[string]any + if err := yaml.Unmarshal(data, &all); err == nil { + for _, f := range c.fields() { + if old, ok := legacyNames[f.env]; ok && *f.ptr == "" { + if v, ok := all[old.key].(string); ok { + *f.ptr = v + } + } + } + } return &c, nil } @@ -183,6 +218,7 @@ func (c *Credentials) Update(change func(*Credentials)) error { // Get returns the credential whose environment variable is name, or "" // if name isn't a known credential. func (c *Credentials) Get(name string) string { + name = canonical(name) for _, f := range c.fields() { if f.env == name { return *f.ptr @@ -194,6 +230,7 @@ func (c *Credentials) Get(name string) string { // Set sets the credential whose environment variable is name; unknown // names are ignored. func (c *Credentials) Set(name, value string) { + name = canonical(name) for _, f := range c.fields() { if f.env == name { *f.ptr = value @@ -207,7 +244,7 @@ func (c *Credentials) Set(name, value string) { func (c *Credentials) Env(names ...string) []string { want := make(map[string]bool, len(names)) for _, n := range names { - want[n] = true + want[canonical(n)] = true } var env []string for _, f := range c.fields() { @@ -245,7 +282,7 @@ func (c *Credentials) MissingForProvisioning() []string { } // MissingForPlatform reports which bootstrap-generated credentials needed -// to set up and run project rollouts (Gitea, Komodo) are missing - i.e. +// to set up and run project rollouts (the forge, Komodo) are missing - i.e. // whether urbex bootstrap has completed on this machine. func (c *Credentials) MissingForPlatform() []string { var missing []string @@ -253,7 +290,7 @@ func (c *Credentials) MissingForPlatform() []string { env string v string }{ - {"URBEX_GITEA_TOKEN", c.GiteaToken}, + {"URBEX_FORGE_TOKEN", c.ForgeToken}, {"URBEX_KOMODO_API_KEY", c.KomodoAPIKey}, {"URBEX_KOMODO_API_SECRET", c.KomodoAPISecret}, {"URBEX_KOMODO_ONBOARDING_KEY", c.KomodoOnboardingKey}, diff --git a/internal/credentials/credentials_test.go b/internal/credentials/credentials_test.go index 2f6ad81..87eb09e 100644 --- a/internal/credentials/credentials_test.go +++ b/internal/credentials/credentials_test.go @@ -3,6 +3,7 @@ package credentials import ( "os" "path/filepath" + "strings" "testing" ) @@ -12,6 +13,9 @@ func clearEnv(t *testing.T) { "URBEX_PROXMOX_TOKEN", "URBEX_CLOUDFLARE_TOKEN", "URBEX_GITEA_TOKEN", + "URBEX_FORGE_TOKEN", + "URBEX_GITEA_ADMIN_PASSWORD", + "URBEX_FORGE_ADMIN_PASSWORD", "URBEX_AGE_KEY", } { t.Setenv(k, "") @@ -125,18 +129,18 @@ func TestUpdate_PersistsOnlyChangedValuesWithPrivateMode(t *testing.T) { if err != nil { t.Fatalf("Load: %v", err) } - if err := c.Update(func(c *Credentials) { c.GiteaToken = "generated" }); err != nil { + if err := c.Update(func(c *Credentials) { c.ForgeToken = "generated" }); err != nil { t.Fatalf("Update: %v", err) } - if c.GiteaToken != "generated" { - t.Errorf("in-memory GiteaToken = %q, want generated", c.GiteaToken) + if c.ForgeToken != "generated" { + t.Errorf("in-memory ForgeToken = %q, want generated", c.ForgeToken) } onDisk, err := loadFile(path) if err != nil { t.Fatalf("loadFile: %v", err) } - if onDisk.GiteaToken != "generated" || onDisk.AgeKey != "file-age-key" { + if onDisk.ForgeToken != "generated" || onDisk.AgeKey != "file-age-key" { t.Errorf("unexpected file content: %+v", onDisk) } if onDisk.ProxmoxToken != "" { @@ -152,9 +156,9 @@ func TestUpdate_PersistsOnlyChangedValuesWithPrivateMode(t *testing.T) { } func TestEnv_ReturnsOnlyRequestedVariables(t *testing.T) { - c := &Credentials{GiteaAdminPassword: "pw", KomodoDBPassword: "db", ProxmoxToken: "secret"} - got := c.Env("URBEX_GITEA_ADMIN_PASSWORD", "URBEX_KOMODO_DB_PASSWORD") - want := []string{"URBEX_GITEA_ADMIN_PASSWORD=pw", "URBEX_KOMODO_DB_PASSWORD=db"} + c := &Credentials{ForgeAdminPassword: "pw", KomodoDBPassword: "db", ProxmoxToken: "secret"} + got := c.Env("URBEX_FORGE_ADMIN_PASSWORD", "URBEX_KOMODO_DB_PASSWORD") + want := []string{"URBEX_FORGE_ADMIN_PASSWORD=pw", "URBEX_KOMODO_DB_PASSWORD=db"} if len(got) != len(want) || got[0] != want[0] || got[1] != want[1] { t.Errorf("Env = %v, want %v", got, want) } @@ -165,7 +169,7 @@ func TestClearGenerated_KeepsWhatTheUserProvides(t *testing.T) { c := &Credentials{} if err := c.Update(func(c *Credentials) { c.ProxmoxToken, c.AgeKey, c.CloudflareToken = "pve", "age", "cf" - c.GiteaToken, c.KomodoAPIKey, c.GrafanaAdminPassword = "g", "k", "p" + c.ForgeToken, c.KomodoAPIKey, c.GrafanaAdminPassword = "g", "k", "p" }); err != nil { t.Fatal(err) } @@ -181,8 +185,52 @@ func TestClearGenerated_KeepsWhatTheUserProvides(t *testing.T) { if got.ProxmoxToken != "pve" || got.AgeKey != "age" || got.CloudflareToken != "cf" { t.Errorf("provided credentials lost: %+v", got) } - if got.GiteaToken != "" || got.KomodoAPIKey != "" || got.GrafanaAdminPassword != "" { + if got.ForgeToken != "" || got.KomodoAPIKey != "" || got.GrafanaAdminPassword != "" { t.Errorf("generated credentials kept: %+v", got) } } } + +// A workspace written before the forge was Forgejo (ADR-0034) works: the +// legacy names are read, from the file and the environment, the new ones +// win, and the next write moves the file to the new keys. +func TestLoad_LegacyForgeNames(t *testing.T) { + clearEnv(t) + home := t.TempDir() + t.Setenv("HOME", home) + dir := filepath.Join(home, ".urbex") + if err := os.MkdirAll(dir, 0o700); err != nil { + t.Fatal(err) + } + path := filepath.Join(dir, "credentials.yaml") + if err := os.WriteFile(path, []byte("giteaToken: old-token\ngiteaAdminPassword: old-pw\nageKey: k\n"), 0o600); err != nil { + t.Fatal(err) + } + c, err := Load() + if err != nil { + t.Fatal(err) + } + if c.ForgeToken != "old-token" || c.ForgeAdminPassword != "old-pw" { + t.Fatalf("legacy keys not read: %+v", c) + } + if c.Get("URBEX_GITEA_TOKEN") != "old-token" || c.Get("URBEX_FORGE_TOKEN") != "old-token" { + t.Error("Get should answer to both names") + } + + if err := c.Update(func(x *Credentials) { x.KomodoAPIKey = "k2" }); err != nil { + t.Fatal(err) + } + data, _ := os.ReadFile(path) + if got := string(data); !strings.Contains(got, "forgeToken: old-token") || strings.Contains(got, "giteaToken") { + t.Errorf("the file should hold the new keys only, got:\n%s", got) + } + + t.Setenv("URBEX_GITEA_TOKEN", "env-old") + if c, _ := Load(); c.ForgeToken != "env-old" { + t.Errorf("legacy env not read: %q", c.ForgeToken) + } + t.Setenv("URBEX_FORGE_TOKEN", "env-new") + if c, _ := Load(); c.ForgeToken != "env-new" { + t.Errorf("the new env name should win: %q", c.ForgeToken) + } +} diff --git a/internal/discover/proposal.go b/internal/discover/proposal.go index b3c6567..a4d921a 100644 --- a/internal/discover/proposal.go +++ b/internal/discover/proposal.go @@ -22,7 +22,7 @@ func proposal(r *Result) string { w("domain: %s # %s", domain, domainNote) w("") w("git:") - w(" giteaUrl: https://git-urbex.%s", domain) + w(" forgeUrl: https://git-urbex.%s", domain) w(" org: urbex") w("") if cf != nil && cf.ZoneID != "" { diff --git a/internal/gitea/client.go b/internal/forge/client.go similarity index 97% rename from internal/gitea/client.go rename to internal/forge/client.go index 82b1a27..2bc0363 100644 --- a/internal/gitea/client.go +++ b/internal/forge/client.go @@ -1,11 +1,12 @@ -// Package gitea is a minimal Gitea API client covering what urbex needs -// from the Git server it provisions: API tokens, the org that owns every -// urbex-managed repo, the repos themselves (GitOps repo + app repos), and -// lookups in Gitea's container registry. See +// Package forge is a minimal client of the platform's forge - Forgejo +// (docs/decisions/0034-forgejo-lts-forge.md), whose API is Gitea's - +// covering what urbex needs from the Git server it provisions: API tokens, +// the org that owns every urbex-managed repo, the repos themselves (GitOps +// repo + app repos), and lookups in its container registry. See // docs/decisions/0004-gitops-gitea-komodo.md and // docs/decisions/0018-image-build-komodo-gitea-registry.md in // urbforge/urbex. -package gitea +package forge import ( "bytes" diff --git a/internal/gitea/client_test.go b/internal/forge/client_test.go similarity index 99% rename from internal/gitea/client_test.go rename to internal/forge/client_test.go index 843a573..9876ce4 100644 --- a/internal/gitea/client_test.go +++ b/internal/forge/client_test.go @@ -1,4 +1,4 @@ -package gitea +package forge import ( "context" diff --git a/internal/platform/config.go b/internal/platform/config.go index c4d0bf7..144b4e8 100644 --- a/internal/platform/config.go +++ b/internal/platform/config.go @@ -38,9 +38,14 @@ type Share struct { Path string `yaml:"path"` } +// GitConfig is the platform's forge (Forgejo, ADR-0034) and the org of +// its repos. type GitConfig struct { - GiteaURL string `yaml:"giteaUrl"` + ForgeURL string `yaml:"forgeUrl"` Org string `yaml:"org"` + // LegacyGiteaURL is giteaUrl, the key before the forge was Forgejo: + // still read, forgeUrl wins (LoadFile moves it there). + LegacyGiteaURL string `yaml:"giteaUrl,omitempty"` } // CloudflareConfig is where the platform's public endpoints live: the @@ -254,6 +259,9 @@ func LoadFile(path string) (*Config, error) { } func applyDefaults(cfg *Config) { + if cfg.Git.ForgeURL == "" { + cfg.Git.ForgeURL = cfg.Git.LegacyGiteaURL + } if cfg.Proxmox.StoragePool == "" { cfg.Proxmox.StoragePool = "local-lvm" } @@ -301,7 +309,7 @@ func (c *Config) Validate() []string { require(c.Proxmox.SSHPublicKey, "proxmox.sshPublicKey") require(c.Proxmox.Network.CIDR, "proxmox.network.cidr") require(c.Proxmox.Network.Gateway, "proxmox.network.gateway") - require(c.Git.GiteaURL, "git.giteaUrl") + require(c.Git.ForgeURL, "git.forgeUrl") cf := c.Cloudflare if (cf.AccountID == "") != (cf.ZoneID == "") { diff --git a/internal/platform/config_test.go b/internal/platform/config_test.go index 873d9c7..ebdcdbd 100644 --- a/internal/platform/config_test.go +++ b/internal/platform/config_test.go @@ -95,7 +95,7 @@ func TestCloudflareHostnames(t *testing.T) { func TestCloudflareValidation(t *testing.T) { base := func() *Config { - c := &Config{Domain: "d", Git: GitConfig{GiteaURL: "g"}} + c := &Config{Domain: "d", Git: GitConfig{ForgeURL: "g"}} c.Proxmox = ProxmoxConfig{APIURL: "a", Node: "n", LXCTemplate: "t", SSHPublicKey: "k", Network: NetworkConfig{CIDR: "c", Gateway: "g"}} return c } @@ -120,7 +120,7 @@ func TestCloudflareValidation(t *testing.T) { func TestQuickTunnelValidation(t *testing.T) { base := func() *Config { - c := &Config{Domain: "d", Git: GitConfig{GiteaURL: "g"}} + c := &Config{Domain: "d", Git: GitConfig{ForgeURL: "g"}} c.Proxmox = ProxmoxConfig{APIURL: "a", Node: "n", LXCTemplate: "t", SSHPublicKey: "k", Network: NetworkConfig{CIDR: "c", Gateway: "g"}} return c } @@ -248,3 +248,24 @@ func TestTemplate_KeyctlOff(t *testing.T) { t.Error("the template turns keyctl on") } } + +// A platform config written before the forge was Forgejo (ADR-0034) has +// git.giteaUrl: it is read as git.forgeUrl, which wins when both are set. +func TestLoadFile_LegacyGiteaURL(t *testing.T) { + for _, tc := range []struct{ yaml, want string }{ + {"git:\n giteaUrl: https://git.old.example.com\n org: urbex\n", "https://git.old.example.com"}, + {"git:\n forgeUrl: https://git.new.example.com\n giteaUrl: https://git.old.example.com\n", "https://git.new.example.com"}, + } { + path := filepath.Join(t.TempDir(), "urbex.platform.yaml") + if err := os.WriteFile(path, []byte(tc.yaml), 0o644); err != nil { + t.Fatal(err) + } + cfg, err := LoadFile(path) + if err != nil { + t.Fatal(err) + } + if cfg.Git.ForgeURL != tc.want { + t.Errorf("ForgeURL = %q, want %q", cfg.Git.ForgeURL, tc.want) + } + } +} diff --git a/internal/platform/template.go b/internal/platform/template.go index 3048008..49fc280 100644 --- a/internal/platform/template.go +++ b/internal/platform/template.go @@ -5,7 +5,7 @@ import "os" const templateContent = `domain: example.com git: - giteaUrl: https://git.example.com + forgeUrl: https://git.example.com org: urbex # Public endpoints on Cloudflare (optional: leave accountId and zoneId diff --git a/internal/provision/orchestrator.go b/internal/provision/orchestrator.go index eaf7acc..12abeea 100644 --- a/internal/provision/orchestrator.go +++ b/internal/provision/orchestrator.go @@ -27,7 +27,7 @@ import ( "github.com/urbforge/urbex-cli/internal/bootstrap" "github.com/urbforge/urbex-cli/internal/credentials" "github.com/urbforge/urbex-cli/internal/envrepo" - "github.com/urbforge/urbex-cli/internal/gitea" + "github.com/urbforge/urbex-cli/internal/forge" "github.com/urbforge/urbex-cli/internal/imageref" "github.com/urbforge/urbex-cli/internal/manifest" "github.com/urbforge/urbex-cli/internal/materialize" @@ -53,7 +53,7 @@ type Rollouter interface { DeployTelemetry(ctx context.Context, t rollout.Target) error Reconcile(ctx context.Context) error BuildMain(ctx context.Context, project string) error - Releases(ctx context.Context, project string) ([]gitea.Tag, error) + Releases(ctx context.Context, project string) ([]forge.Tag, error) MissingImages(ctx context.Context, project string, services []manifest.Service, version string) ([]string, error) WaitDeployed(ctx context.Context, t rollout.Target, repo envrepo.Repo) ([]rollout.Deployed, error) RemoveEnv(ctx context.Context, t rollout.Target) error @@ -740,7 +740,7 @@ func (o *Orchestrator) Promote(ctx context.Context, gitopsRepoPath string, allow if err != nil { return false, err } - var releases []gitea.Tag + var releases []forge.Tag if len(manifest.Built(o.Manifest.Deployables())) > 0 { if releases, err = o.Rollout.Releases(ctx, o.Manifest.Project); err != nil { return false, err @@ -783,7 +783,7 @@ func (o *Orchestrator) Promote(ctx context.Context, gitopsRepoPath string, allow // releaseOf returns the release a version is: itself if it is one, the // release tagged on that commit if it is a commit. -func releaseOf(version string, releases []gitea.Tag) (string, error) { +func releaseOf(version string, releases []forge.Tag) (string, error) { if v, ok := semver.Parse(version); ok { return v.String(), nil } diff --git a/internal/provision/orchestrator_test.go b/internal/provision/orchestrator_test.go index 01b3f83..e4f0247 100644 --- a/internal/provision/orchestrator_test.go +++ b/internal/provision/orchestrator_test.go @@ -14,7 +14,7 @@ import ( "github.com/urbforge/urbex-cli/internal/allocation" "github.com/urbforge/urbex-cli/internal/credentials" "github.com/urbforge/urbex-cli/internal/envrepo" - "github.com/urbforge/urbex-cli/internal/gitea" + "github.com/urbforge/urbex-cli/internal/forge" "github.com/urbforge/urbex-cli/internal/manifest" "github.com/urbforge/urbex-cli/internal/pgadmin" "github.com/urbforge/urbex-cli/internal/platform" @@ -43,7 +43,7 @@ func (f runnerFunc) Run(_ context.Context, c runner.Command) error { func validPlatformConfig() *platform.Config { return &platform.Config{ Domain: "example.com", - Git: platform.GitConfig{GiteaURL: "https://git.example.com"}, + Git: platform.GitConfig{ForgeURL: "https://git.example.com"}, Proxmox: platform.ProxmoxConfig{ APIURL: "https://proxmox.example.internal:8006/api2/json", Node: "pve", @@ -74,7 +74,7 @@ func validCredentials() *credentials.Credentials { return &credentials.Credentials{ ProxmoxToken: "pve-token", AgeKey: "AGE-SECRET-KEY-13E9XGFYJN5M6PKTQJFHSXX3MCEZS9XT2EA88VFZ3Z3RFA3VHXGGQ6LS0RC", - GiteaToken: "gitea-token", + ForgeToken: "gitea-token", KomodoAPIKey: "K_key_K", KomodoAPISecret: "S_secret_S", KomodoOnboardingKey: "O_onboard_O", @@ -97,7 +97,7 @@ type fakeRollout struct { mainBuilds int // mainVersion is what a build of main sets following environments to. mainVersion string - releases []gitea.Tag + releases []forge.Tag repo *envrepo.Repo services []manifest.Service // pg are the postgres providers' fake servers, by service: one is @@ -167,7 +167,7 @@ func (f *fakeRollout) BuildMain(ctx context.Context, project string) error { return nil } -func (f *fakeRollout) Releases(ctx context.Context, project string) ([]gitea.Tag, error) { +func (f *fakeRollout) Releases(ctx context.Context, project string) ([]forge.Tag, error) { return f.releases, nil } @@ -512,7 +512,7 @@ func TestPromote_PutsTheReleaseStagingRunsInProd(t *testing.T) { } // Once released, promote finds the release by its commit. - ro.releases = []gitea.Tag{ + ro.releases = []forge.Tag{ {Name: "v1.4.1", Commit: "0000000000000000000000000000000000000000"}, {Name: "v1.4.2", Commit: "a1b2c3d4e5f60718293a4b5c6d7e8f9012345678"}, } diff --git a/internal/rollout/rollout.go b/internal/rollout/rollout.go index 156c5de..a8bc9a9 100644 --- a/internal/rollout/rollout.go +++ b/internal/rollout/rollout.go @@ -32,7 +32,7 @@ import ( "github.com/urbforge/urbex-cli/internal/bootstrap" "github.com/urbforge/urbex-cli/internal/envrepo" - "github.com/urbforge/urbex-cli/internal/gitea" + "github.com/urbforge/urbex-cli/internal/forge" "github.com/urbforge/urbex-cli/internal/gitsync" "github.com/urbforge/urbex-cli/internal/imageref" "github.com/urbforge/urbex-cli/internal/komodo" @@ -63,7 +63,7 @@ type Gitea interface { BranchExists(ctx context.Context, owner, repo, branch string) (bool, error) EnsureWebhook(ctx context.Context, owner, repo, targetURL, secret, branchFilter string) error DeleteWebhook(ctx context.Context, owner, repo, targetURL string) error - ListTags(ctx context.Context, owner, repo string) ([]gitea.Tag, error) + ListTags(ctx context.Context, owner, repo string) ([]forge.Tag, error) BranchCommit(ctx context.Context, owner, repo, branch string) (string, error) ResolveCommit(ctx context.Context, owner, repo, ref string) (string, error) CreateTag(ctx context.Context, owner, repo, tag, target, message string) error @@ -503,12 +503,12 @@ func (r *Rollout) DeployTelemetry(ctx context.Context, t Target) error { } // Releases returns the project's releases: its vX.Y.Z tags on Gitea. -func (r *Rollout) Releases(ctx context.Context, project string) ([]gitea.Tag, error) { +func (r *Rollout) Releases(ctx context.Context, project string) ([]forge.Tag, error) { tags, err := r.Gitea.ListTags(ctx, r.Org, project) if err != nil { return nil, err } - var releases []gitea.Tag + var releases []forge.Tag for _, t := range tags { if _, ok := semver.Parse(t.Name); ok && strings.HasPrefix(t.Name, "v") { releases = append(releases, t) diff --git a/internal/rollout/rollout_test.go b/internal/rollout/rollout_test.go index 990e411..76fdc9d 100644 --- a/internal/rollout/rollout_test.go +++ b/internal/rollout/rollout_test.go @@ -16,7 +16,7 @@ import ( "github.com/urbforge/urbex-cli/internal/bootstrap" "github.com/urbforge/urbex-cli/internal/envrepo" - "github.com/urbforge/urbex-cli/internal/gitea" + "github.com/urbforge/urbex-cli/internal/forge" "github.com/urbforge/urbex-cli/internal/komodo" "github.com/urbforge/urbex-cli/internal/manifest" "github.com/urbforge/urbex-cli/internal/semver" @@ -26,7 +26,7 @@ type fakeGitea struct { repos []string branches map[string]bool hooks map[string]string // url -> "secret|filter" - tags []gitea.Tag + tags []forge.Tag images map[string]bool // "name:tag" // imagesAfter makes images appear after that many lookups, as a // build finishing would. @@ -52,11 +52,11 @@ func (f *fakeGitea) DeleteWebhook(ctx context.Context, owner, repo, targetURL st delete(f.hooks, targetURL) return nil } -func (f *fakeGitea) ListTags(ctx context.Context, owner, repo string) ([]gitea.Tag, error) { +func (f *fakeGitea) ListTags(ctx context.Context, owner, repo string) ([]forge.Tag, error) { return f.tags, nil } func (f *fakeGitea) CreateTag(ctx context.Context, owner, repo, tag, target, message string) error { - f.tags = append(f.tags, gitea.Tag{Name: tag, Commit: target}) + f.tags = append(f.tags, forge.Tag{Name: tag, Commit: target}) return nil } func (f *fakeGitea) BranchCommit(ctx context.Context, owner, repo, branch string) (string, error) { @@ -421,7 +421,7 @@ func TestRelease_TagsMainAndWaitsForEveryImage(t *testing.T) { if err := r.Release(context.Background(), "my-app", services(), semver.Version{Major: 1, Minor: 4, Patch: 2}, commit); err != nil { t.Fatalf("Release: %v", err) } - if len(g.tags) != 1 || g.tags[0] != (gitea.Tag{Name: "v1.4.2", Commit: commit}) { + if len(g.tags) != 1 || g.tags[0] != (forge.Tag{Name: "v1.4.2", Commit: commit}) { t.Errorf("expected v1.4.2 tagged on the commit, got %v", g.tags) } if g.lookups <= 3 { @@ -626,7 +626,7 @@ func TestBuildMain_RunsTheReleaseActionAsAPushToMainWould(t *testing.T) { } func TestReleases_OnlyVersionTags(t *testing.T) { - g := &fakeGitea{tags: []gitea.Tag{{Name: "v1.0.0", Commit: "a"}, {Name: "nightly", Commit: "b"}, {Name: "1.1.0", Commit: "c"}, {Name: "v1.2.0-rc.1", Commit: "d"}}} + g := &fakeGitea{tags: []forge.Tag{{Name: "v1.0.0", Commit: "a"}, {Name: "nightly", Commit: "b"}, {Name: "1.1.0", Commit: "c"}, {Name: "v1.2.0-rc.1", Commit: "d"}}} releases, err := newRollout(g, &fakeKomodo{}, &fakeGit{}).Releases(context.Background(), "my-app") if err != nil || len(releases) != 1 || releases[0].Name != "v1.0.0" { t.Errorf("Releases = %v, %v; want only v1.0.0", releases, err) diff --git a/platform/ansible/roles/gitea/tasks/main.yml b/platform/ansible/roles/gitea/tasks/main.yml index 9851634..c715359 100644 --- a/platform/ansible/roles/gitea/tasks/main.yml +++ b/platform/ansible/roles/gitea/tasks/main.yml @@ -42,7 +42,7 @@ command: >- docker compose exec -T -u git gitea gitea admin user create --admin --username {{ gitea_admin_username }} - --password {{ lookup('env', 'URBEX_GITEA_ADMIN_PASSWORD') | quote }} + --password {{ lookup('env', 'URBEX_FORGE_ADMIN_PASSWORD') | quote }} --email {{ gitea_admin_username }}@{{ urbex_domain | default('urbex.local') }} --must-change-password=false args: From 94abe15ec8ceeb38592aeb148f84937e94f524f7 Mon Sep 17 00:00:00 2001 From: Teg79 Date: Tue, 17 Nov 2026 17:10:31 +0100 Subject: [PATCH 3/4] feat(forge): say Forgejo to the user; e2e and layout on the forge names Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0182yxsfwRowwnxCfgrQwjnA --- docs/layout.md | 2 +- e2e/lib.sh | 6 +++--- e2e/run.sh | 4 ++-- internal/bootstrap/endpoints.go | 2 +- internal/bootstrap/endpoints_test.go | 2 +- internal/bootstrap/orchestrator.go | 2 +- internal/bootstrap/phases.go | 4 ++-- internal/bootstrap/platform.go | 2 +- internal/bootstrap/public.go | 4 ++-- internal/bootstrap/teardown.go | 8 ++++---- internal/cli/apply.go | 2 +- internal/cli/status.go | 6 +++--- internal/cli/status_logins_test.go | 2 +- internal/cli/status_projects.go | 2 +- internal/discover/discover_test.go | 2 +- internal/discover/proposal.go | 4 ++-- internal/platform/config.go | 2 +- internal/rollout/rollout.go | 2 +- 18 files changed, 29 insertions(+), 29 deletions(-) diff --git a/docs/layout.md b/docs/layout.md index eca754c..f89e0bd 100644 --- a/docs/layout.md +++ b/docs/layout.md @@ -17,7 +17,7 @@ internal/proxmoxapi/ minimal Proxmox API client (container listing: pre- internal/cloudflare/ minimal Cloudflare API client (tunnel, DNS, Access, Workers) and a fake for tests internal/knownhosts/ the LXCs' SSH host keys in the GitOps repo (state/known_hosts) internal/tfstate/ reconciles Terraform state with the LXCs that exist on Proxmox -internal/gitea/ minimal Gitea API client (tokens, org, repos, webhooks, tags, registry lookups) +internal/forge/ minimal client of the forge, Forgejo (tokens, org, repos, webhooks, tags, registry lookups) internal/komodo/ minimal Komodo v2 API client (keys, accounts, servers, builds, stacks, actions, procedures) internal/gitsync/ git commit/push helpers (GitOps repo, a project's main branch) internal/rollout/ a project's Builds and an environment's Stacks on Komodo; releases; waiting for deploys diff --git a/e2e/lib.sh b/e2e/lib.sh index 8d82a7c..dba37e8 100644 --- a/e2e/lib.sh +++ b/e2e/lib.sh @@ -38,7 +38,7 @@ expect_status() { } gitea_api() { # gitea_api [json] - curl -s -X "$1" "$GITEA/api/v1$2" -H "authorization: token $(cred giteaToken)" \ + curl -s -X "$1" "$GITEA/api/v1$2" -H "authorization: token $(cred forgeToken)" \ -H 'content-type: application/json' ${3:+-d "$3"} } @@ -49,11 +49,11 @@ komodo_names() { # komodo_names } git_remote() { # the app repo's clone URL on Gitea, with credentials - echo "http://urbex-admin:$(cred giteaToken)@$NET.200:3000/urbex/hello.git" + echo "http://urbex-admin:$(cred forgeToken)@$NET.200:3000/urbex/hello.git" } gitops_remote() { # the GitOps repo's clone URL on Gitea, with credentials - echo "http://urbex-admin:$(cred giteaToken)@$NET.200:3000/urbex/gitops.git" + echo "http://urbex-admin:$(cred forgeToken)@$NET.200:3000/urbex/gitops.git" } # push_main : what a developer does on a trunk-based diff --git a/e2e/run.sh b/e2e/run.sh index bca15ec..138902f 100755 --- a/e2e/run.sh +++ b/e2e/run.sh @@ -137,7 +137,7 @@ step "bootstrap: scaffold urbex.platform.yaml" ' cat >"$WORK/gitops/urbex.platform.yaml" < Settings > Authentication), or nobody can log in through Access (Gitea, Komodo, Grafana, ...).") + fmt.Fprintln(o.Out, "Warning: the Cloudflare token can't read Zero Trust login methods; make sure One-time PIN is enabled (Zero Trust > Settings > Authentication), or nobody can log in through Access (Forgejo, Komodo, Grafana, ...).") return nil } if err != nil || ok { diff --git a/internal/bootstrap/teardown.go b/internal/bootstrap/teardown.go index a71f33c..8f67bc3 100644 --- a/internal/bootstrap/teardown.go +++ b/internal/bootstrap/teardown.go @@ -65,7 +65,7 @@ func (o *Orchestrator) Teardown(ctx context.Context, opts TeardownOptions) error repoURL := ep.RepoURL(o.Config.Git.Org, GitOpsRepoName) if o.Credentials.ForgeToken != "" { if err := clients.PullRepo(ctx, opts.GitOpsRepoPath, repoURL, o.Credentials.ForgeToken); err != nil { - fmt.Fprintf(o.Out, "Warning: could not update the GitOps repo from Gitea (%v); using the local copy.\n", err) + fmt.Fprintf(o.Out, "Warning: could not update the GitOps repo from Forgejo (%v); using the local copy.\n", err) } } @@ -83,9 +83,9 @@ func (o *Orchestrator) Teardown(ctx context.Context, opts TeardownOptions) error fmt.Fprintln(o.Out, "This destroys the Urbex platform on Proxmox:") fmt.Fprintf(o.Out, " - the base-service LXCs and their disks: %s\n", strings.Join(baseHostnames(o.Config), ", ")) if len(repos) > 0 { - fmt.Fprintf(o.Out, " - everything on Gitea: %s, and their images - make sure the project repos live elsewhere too\n", strings.Join(repos, ", ")) + fmt.Fprintf(o.Out, " - everything on Forgejo: %s, and their images - make sure the project repos live elsewhere too\n", strings.Join(repos, ", ")) } else { - fmt.Fprintln(o.Out, " - everything on Gitea: every repository and image - make sure the project repos live elsewhere too") + fmt.Fprintln(o.Out, " - everything on Forgejo: every repository and image - make sure the project repos live elsewhere too") } fmt.Fprintln(o.Out, " - Komodo's, Keycloak's and Grafana's configuration and data") if o.Config.Cloudflare.Enabled() { @@ -152,7 +152,7 @@ func (o *Orchestrator) Teardown(ctx context.Context, opts TeardownOptions) error return fmt.Errorf("committing the gitops repo: %w", err) } fmt.Fprintln(o.Out, "Platform destroyed.") - fmt.Fprintf(o.Out, "Keep %s: 'urbex bootstrap' creates a new platform and pushes it to its Gitea.\n", opts.GitOpsRepoPath) + fmt.Fprintf(o.Out, "Keep %s: 'urbex bootstrap' creates a new platform and pushes it to its Forgejo.\n", opts.GitOpsRepoPath) return nil } diff --git a/internal/cli/apply.go b/internal/cli/apply.go index df417ae..7c0c749 100644 --- a/internal/cli/apply.go +++ b/internal/cli/apply.go @@ -86,7 +86,7 @@ by 'urbex bootstrap'). See docs/reference/cli.md in urbforge/urbex.`, cmd.Flags().StringVar(&manifestPath, "file", "urbex.yaml", "path to the app manifest") cmd.Flags().StringVar(&gitopsRepoPath, "gitops-repo", "", "local working directory of the GitOps repo (or set URBEX_GITOPS_REPO)") - cmd.Flags().StringVar(&repoDir, "repo-dir", ".", "path to the app's git repo, used to create the project's main branch on Gitea if it is missing") + cmd.Flags().StringVar(&repoDir, "repo-dir", ".", "path to the app's git repo, used to create the project's main branch on Forgejo if it is missing") cmd.Flags().BoolVar(&deleteData, "delete-data", false, "delete the LXC and the named volumes of an application removed from urbex.yaml") events.Register(cmd) diff --git a/internal/cli/status.go b/internal/cli/status.go index 09145c1..9a118b1 100644 --- a/internal/cli/status.go +++ b/internal/cli/status.go @@ -188,7 +188,7 @@ type loginView struct { func logins(path string) loginsView { return loginsView{CredentialsFile: path, Users: []loginView{ - {"gitea", bootstrap.GiteaAdminUser, "giteaAdminPassword"}, + {"gitea", bootstrap.GiteaAdminUser, "forgeAdminPassword"}, {"komodo", bootstrap.GiteaAdminUser, "komodoAdminPassword"}, {"grafana", "admin", "grafanaAdminPassword"}, {"keycloak", "admin", "keycloakAdminPassword"}, @@ -269,9 +269,9 @@ func runBaseStatus(cmd *cobra.Command, out io.Writer, client status.ProxmoxListe // printLogins lists the platform's admin users and the names of their // passwords in the credentials file at path. func printLogins(out io.Writer, path string) { - fmt.Fprintf(out, "\nLogins: Gitea and Komodo %s, Grafana admin, Keycloak admin, Technitium %s; passwords in %s\n", + fmt.Fprintf(out, "\nLogins: Forgejo and Komodo %s, Grafana admin, Keycloak admin, Technitium %s; passwords in %s\n", bootstrap.GiteaAdminUser, bootstrap.TechnitiumAdminUser, path) - fmt.Fprintln(out, "(giteaAdminPassword, komodoAdminPassword, grafanaAdminPassword, keycloakAdminPassword, technitiumAdminPassword).") + fmt.Fprintln(out, "(forgeAdminPassword, komodoAdminPassword, grafanaAdminPassword, keycloakAdminPassword, technitiumAdminPassword).") } // --- a project environment --------------------------------------------------- diff --git a/internal/cli/status_logins_test.go b/internal/cli/status_logins_test.go index f0cd4fa..1cd281c 100644 --- a/internal/cli/status_logins_test.go +++ b/internal/cli/status_logins_test.go @@ -12,7 +12,7 @@ func TestPrintLogins_ListsTechnitium(t *testing.T) { for _, want := range []string{ "Technitium admin", "technitiumAdminPassword", - "Gitea and Komodo urbex-admin", + "Forgejo and Komodo urbex-admin", "passwords in /Users/me/urbex-work/home/.urbex/credentials.yaml", } { if !strings.Contains(out.String(), want) { diff --git a/internal/cli/status_projects.go b/internal/cli/status_projects.go index 47e9470..0ef4f42 100644 --- a/internal/cli/status_projects.go +++ b/internal/cli/status_projects.go @@ -210,6 +210,6 @@ func refreshForStatus(ctx context.Context, warn func(string), cfg *platform.Conf err = bootstrap.PullRepo(ctx, repoPath, ep.RepoURL(cfg.Git.Org, bootstrap.GitOpsRepoName), creds.ForgeToken) } if err != nil { - warn(fmt.Sprintf("could not update the GitOps repo from Gitea: %v - showing the local copy", err)) + warn(fmt.Sprintf("could not update the GitOps repo from Forgejo: %v - showing the local copy", err)) } } diff --git a/internal/discover/discover_test.go b/internal/discover/discover_test.go index 63a7e28..0d6553a 100644 --- a/internal/discover/discover_test.go +++ b/internal/discover/discover_test.go @@ -126,7 +126,7 @@ func TestRun_Lab(t *testing.T) { if cfg.Proxmox.Network.BaseHostOffset != 206 || cfg.Proxmox.Pool != "urbex" || !cfg.Proxmox.Insecure || cfg.Cloudflare.ZoneID != "z1" || cfg.Proxmox.SSHPublicKey != "ssh-ed25519 AAAA urbex" { t.Errorf("config = %+v", cfg.Proxmox) } - if !strings.Contains(r.Proposal, "FILL IN: who may open Gitea and Komodo") { + if !strings.Contains(r.Proposal, "FILL IN: who may open Forgejo and Komodo") { t.Errorf("the Access emails should be marked to fill in:\n%s", r.Proposal) } } diff --git a/internal/discover/proposal.go b/internal/discover/proposal.go index a4d921a..fe250e0 100644 --- a/internal/discover/proposal.go +++ b/internal/discover/proposal.go @@ -26,11 +26,11 @@ func proposal(r *Result) string { w(" org: urbex") w("") if cf != nil && cf.ZoneID != "" { - w("cloudflare: # public HTTPS on %s; Gitea and Komodo behind Cloudflare Access", domain) + w("cloudflare: # public HTTPS on %s; Forgejo and Komodo behind Cloudflare Access", domain) w(" accountId: %s", cf.AccountID) w(" zoneId: %s", cf.ZoneID) w(" access:") - w(" emails: [you@example.com] # FILL IN: who may open Gitea and Komodo (a one-time PIN goes to the address)") + w(" emails: [you@example.com] # FILL IN: who may open Forgejo and Komodo (a one-time PIN goes to the address)") w("") } else { w("# No Cloudflare: everything stays on the LAN. For public addresses without") diff --git a/internal/platform/config.go b/internal/platform/config.go index 144b4e8..f14f8b2 100644 --- a/internal/platform/config.go +++ b/internal/platform/config.go @@ -319,7 +319,7 @@ func (c *Config) Validate() []string { errs = append(errs, "cloudflare.hostnames must be flat or nested") } if cf.Enabled() && len(cf.Access.Emails) == 0 { - errs = append(errs, "cloudflare.access.emails is required: who may reach Gitea and Komodo through Cloudflare Access") + errs = append(errs, "cloudflare.access.emails is required: who may reach Forgejo and Komodo through Cloudflare Access") } for _, f := range c.DNS.Forwarders { if net.ParseIP(f) == nil { diff --git a/internal/rollout/rollout.go b/internal/rollout/rollout.go index a8bc9a9..87fc1e7 100644 --- a/internal/rollout/rollout.go +++ b/internal/rollout/rollout.go @@ -292,7 +292,7 @@ func (r *Rollout) ensureTrunk(ctx context.Context, project string) error { if err := r.Git.Push(ctx, r.RepoDir, url, r.Token, "HEAD:refs/heads/"+bootstrap.TrunkBranch); err != nil { return fmt.Errorf("creating branch %s on gitea from %s: %w", bootstrap.TrunkBranch, r.RepoDir, err) } - fmt.Fprintf(r.Out, "Created %s/%s on Gitea with branch %s from the local HEAD.\n", r.Org, project, bootstrap.TrunkBranch) + fmt.Fprintf(r.Out, "Created %s/%s on Forgejo with branch %s from the local HEAD.\n", r.Org, project, bootstrap.TrunkBranch) return nil } From 3e2c83899d73bb5a715ae23d469293495c1296ce Mon Sep 17 00:00:00 2001 From: Teg79 Date: Tue, 17 Nov 2026 17:15:09 +0100 Subject: [PATCH 4/4] test(e2e): the progress and status checks say Forgejo Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0182yxsfwRowwnxCfgrQwjnA --- e2e/run.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/run.sh b/e2e/run.sh index 138902f..5fd61ac 100755 --- a/e2e/run.sh +++ b/e2e/run.sh @@ -233,7 +233,7 @@ step "bootstrap again: idempotent" ' # Proxmox, and there is no Cloudflare. urbex status --progress | tee /tmp/progress.txt grep -q "^urbex bootstrap: done in" /tmp/progress.txt || fail "status --progress should show the bootstrap done" - grep -q "✓ Install Gitea and Komodo" /tmp/progress.txt || fail "status --progress should show the parallel play done" + grep -q "✓ Install Forgejo and Komodo" /tmp/progress.txt || fail "status --progress should show the parallel play done" grep -q "skipped: no Cloudflare" /tmp/progress.txt || fail "status --progress should show Cloudflare skipped" echo "ok: second bootstrap changed nothing"' @@ -260,7 +260,7 @@ step "apply staging: it follows main, and runs main's head right away" ' # users browsers reach Keycloak at, not how a service reaches it. ! grep -rnE "([0-9]{1,3}[.]){3}[0-9]{1,3}" /work/gitops/environments | grep -v KEYCLOAK_ISSUER || fail "the environments in the gitops repo hold addresses, not names" grep -q "image: git.urbex.urbex.test:3000/urbex/hello-api" /work/gitops/environments/staging/hello/api/compose.yaml || fail "the image should come from the registry by name" - urbex status | grep -F "Gitea" | grep -F "http://git.urbex.urbex.test:3000" | grep -F "http://$NET.200:3000" | grep -qv "(missing)\|(points to" || fail "status should show gitea by internal name and LAN address, with its record" + urbex status | grep -F "Forgejo" | grep -F "http://git.urbex.urbex.test:3000" | grep -F "http://$NET.200:3000" | grep -qv "(missing)\|(points to" || fail "status should show gitea by internal name and LAN address, with its record" echo "ok: staging follows main"' step "a push to main is deployed to staging, with no command" '