From e47da53e6c42f73fb8f8c1cc910ad0a7beb3c1b4 Mon Sep 17 00:00:00 2001 From: "Ronald A. Richardson" Date: Thu, 3 Dec 2026 18:06:38 +0800 Subject: [PATCH] fix(install-fleetbase): run the installer from the CLI again (v2.0.1) 2.0.0 turned flb install-fleetbase into a stub that printed a pointer to npx @fleetbase/installer and exited 1, which broke the documented install: npm install -g @fleetbase/cli && flb install-fleetbase. The command is back with the same flags. The wizard stays in @fleetbase/installer, now a dependency of the CLI and loaded only when the command runs. CI publishes the installer before the CLI, to npm and to GitHub Packages. --- .github/workflows/ci.yml | 25 ++++++++++++---- README.md | 22 ++++++++++++-- RELEASE.md | 30 +++++++------------ package-lock.json | 5 ++-- package.json | 3 +- packages/installer/README.md | 3 +- src/commands/install-fleetbase.ts | 44 +++++++++++++++++++++++++++ src/commands/legacy.ts | 12 -------- src/installer-module.d.ts | 9 ++++++ src/program.ts | 3 +- test/unit/install-fleetbase.test.ts | 46 +++++++++++++++++++++++++++++ 11 files changed, 158 insertions(+), 44 deletions(-) create mode 100644 src/commands/install-fleetbase.ts create mode 100644 src/installer-module.d.ts create mode 100644 test/unit/install-fleetbase.test.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f9824f7..adb350f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -137,11 +137,8 @@ jobs: - name: Install dependencies run: npm ci - - name: Publish @fleetbase/cli - run: npm publish --access public --tag ${{ contains(github.ref_name, '-') && 'next' || 'latest' }} - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} - + # The installer first: @fleetbase/cli depends on it (`flb install-fleetbase`), so the CLI must + # never reach npm while the installer version it needs is missing. - name: Publish @fleetbase/installer when its version is new run: | version=$(node -p "require('./packages/installer/package.json').version") @@ -153,6 +150,11 @@ jobs: env: NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} + - name: Publish @fleetbase/cli + run: npm publish --access public --tag ${{ contains(github.ref_name, '-') && 'next' || 'latest' }} + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} + github_publish: needs: [test, e2e] runs-on: ubuntu-latest @@ -172,6 +174,19 @@ jobs: - name: Install dependencies run: npm ci + # Same order as npm: with the @fleetbase scope pointed at GitHub Packages, the CLI's + # dependency on the installer is resolved here too. + - name: Publish @fleetbase/installer to GitHub Packages when its version is new + run: | + version=$(node -p "require('./packages/installer/package.json').version") + if npm view "@fleetbase/installer@$version" version >/dev/null 2>&1; then + echo "@fleetbase/installer@$version is already on GitHub Packages" + else + npm publish -w @fleetbase/installer + fi + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Publish to GitHub Packages run: npm publish env: diff --git a/README.md b/README.md index e95fd70..f963823 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,25 @@ npm install -g @fleetbase/cli flb --help ``` -Requires Node.js 20.10 or later. Installing Fleetbase itself moved to its own package: -`npx @fleetbase/installer` (see [packages/installer](packages/installer)). +Requires Node.js 20.10 or later. + +## Install Fleetbase + +```bash +npm install -g @fleetbase/cli +flb install-fleetbase +``` + +The setup wizard clones Fleetbase, asks for the host, environment, database, mail and storage +settings, and starts it with Docker. It needs Docker, Docker Compose v2 and Git. For CI, pass the +flags and `--non-interactive`: + +```bash +flb install-fleetbase --directory ./fleetbase --environment production --host fleet.example.com --non-interactive +``` + +The wizard is the [`@fleetbase/installer`](packages/installer) package, so `npx @fleetbase/installer` +runs the same thing without installing the CLI. ## Quick start: publish an extension @@ -51,6 +68,7 @@ price and permissions are published as soon as their checks pass. | `flb instance register --path \|--docker` | Registers the instance itself: mints a code and pipes it to `php artisan registry:register --code-stdin`, so the instance token stays in the instance's encrypted settings. Without a target (or with `--store-token`) the CLI exchanges the code and keeps the token in the config file. Registering an instance again rotates it on the service rather than creating a second one: the instance (or, with `--store-token`, the config entry for the same `--path` or `--host`) sends its current token, the service also matches the same host in the same organization, and the instance keeps its id, installs and licence seats with a new token ("Re-registered …"). Under Octane the new registration applies to the running workers without a reload | | `flb instance status\|updates\|list\|forget` | The instance as the service sees it, its licences and available updates | | `flb install [@version]` / `flb update` / `flb uninstall` | Runs `php artisan registry:install\|update\|uninstall` on an instance (`--path` or `--docker [service]`) and follows the job | +| `flb install-fleetbase [--directory] [--environment] [--host] [--app-name] [--non-interactive]` | Installs Fleetbase itself with Docker through the setup wizard ([`@fleetbase/installer`](packages/installer)) | | `flb doctor [--path\|--docker]` | Config, registry connectivity, token validity and scopes, instances, local tools, the instance's installer | | `flb config list\|get\|set\|unset\|path` | `registry` and `organization` defaults | diff --git a/RELEASE.md b/RELEASE.md index 58c2516..2a794fc 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,23 +1,15 @@ -> v2.0.0 ~ "CLI v2 for the Fleetbase Extensions Registry" +> v2.0.1 ~ "flb install-fleetbase is back" --- -## What's New -- Rewritten in TypeScript against the Registry Service API (`/v1`). Same package (`@fleetbase/cli`) and binary (`flb`). -- `flb login` / `logout` / `whoami`, `flb register` / `verify`, `flb token create|list|revoke`: scoped, expiring personal tokens. -- `flb init` scaffolds from fleetbase/starter-extension with your organization's package names, PHP namespace and an `extension.json` with `compat` ranges. -- `flb build` writes the engine tarball, the Composer api archive and, with `--prebuilt --console `, the prebuilt engine dist from ember-core's `build-engine-release`; `flb bump` keeps the three manifests on one version. -- `flb publish [--channel beta] [--submit]` creates the listing, uploads the release and streams the registry checks; `flb release status|submit|withdraw|yank|list` follow it through review. -- Trusted publishing from GitHub Actions: `flb publish` exchanges the job's OIDC token for a short-lived, publish-only token when a trusted publisher is configured on the listing. The composite action `fleetbase/fleetbase-cli/action@v2` installs the CLI, publishes and exposes the release id, version and status. -- `flb search`, `flb info`: the public catalog. -- `flb listing list|show|update|categories`: complete the catalog listing from the terminal. -- `extension.json` can carry the catalog listing in a `listing` block (subtitle, description or a Markdown file, category, tags, languages, icon, hosting, copyright, links). `flb publish` applies it on every publish, trusted publishing included; the registry then shows those fields read-only in Studio. `flb listing pull` writes an existing listing into the block. -- `flb instance code|register|status|updates`: instance registration from a server shell; `register --path|--docker` hands the code to the instance (`registry:register`) so its token never leaves it. -- `flb install|update|uninstall` run registry-bridge's queued installer (`php artisan registry:*`) locally or in a docker compose service and follow the job. -- `flb doctor` checks config, token, connectivity, instances and local tools. +## Fixed +- `flb install-fleetbase` installs Fleetbase again. In 2.0.0 it only printed a pointer to `npx @fleetbase/installer` and exited with an error, which broke the documented install: `npm install -g @fleetbase/cli && flb install-fleetbase`. +- The wizard itself is the `@fleetbase/installer` package, now a dependency of the CLI. `flb install-fleetbase` takes the same flags (`--directory`, `--environment`, `--host`, `--app-name`, `--non-interactive`), and `npx @fleetbase/installer` still runs it without the CLI. --- -## Breaking changes -- `install-fleetbase` moved to its own package: `npx @fleetbase/installer`. -- Removed: `set-auth` (use `flb login --token`), `scaffold` (now `init`), `bundle` / `bundle-upload` (`build` / `publish`), `generate-token` (`token create`), `resend-verification` (`verify --resend`), `unpublish` (`release yank`), `version-bump` (`bump`). The old names print what replaced them. -- Tokens live only in `~/.fleetbase/config.json` (mode 600); nothing is written to `.npmrc` or `auth.json`. Tokens from 0.0.x are not accepted by the Registry Service: run `flb login`. -- Requires Node.js 20.10 or later. +## Release +- `@fleetbase/installer` is published before `@fleetbase/cli`, to npm and to GitHub Packages, so the CLI never points at a version that is not there. + +--- +## Need help? +- [GitHub Discussions](https://github.com/fleetbase/fleetbase/discussions) +- [Discord](https://discord.gg/HnTqQ6zAVn) diff --git a/package-lock.json b/package-lock.json index 1f4fa29..523b39b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,17 +1,18 @@ { "name": "@fleetbase/cli", - "version": "2.0.0", + "version": "2.0.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@fleetbase/cli", - "version": "2.0.0", + "version": "2.0.1", "license": "AGPL-3.0-or-later", "workspaces": [ "packages/*" ], "dependencies": { + "@fleetbase/installer": "^0.1.0", "commander": "^14.0.3", "enquirer": "^2.4.1", "picocolors": "^1.1.1", diff --git a/package.json b/package.json index 4c712eb..2a25b65 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fleetbase/cli", - "version": "2.0.0", + "version": "2.0.1", "description": "Fleetbase CLI: publish extensions to the Fleetbase Extensions Registry and manage installs on your instances", "repository": "https://github.com/fleetbase/fleetbase-cli", "license": "AGPL-3.0-or-later", @@ -35,6 +35,7 @@ "prepack": "npm run clean && npm run build" }, "dependencies": { + "@fleetbase/installer": "^0.1.0", "commander": "^14.0.3", "enquirer": "^2.4.1", "picocolors": "^1.1.1", diff --git a/packages/installer/README.md b/packages/installer/README.md index ce34f20..8e2adaf 100644 --- a/packages/installer/README.md +++ b/packages/installer/README.md @@ -46,5 +46,4 @@ These match the fleetbase repo's `scripts/docker-install.sh`. To turn authentica Restart the containers after editing `.env`. The socket's allowed origins (`SOCKETCLUSTER_OPTIONS`) are still written to `docker-compose.override.yml`. -This was `flb install-fleetbase` in `@fleetbase/cli` up to 0.0.7. The CLI now only covers -the extensions registry; `flb install-fleetbase` prints a pointer here. +`flb install-fleetbase` in `@fleetbase/cli` runs this package with the same flags. diff --git a/src/commands/install-fleetbase.ts b/src/commands/install-fleetbase.ts new file mode 100644 index 0000000..e6d18e4 --- /dev/null +++ b/src/commands/install-fleetbase.ts @@ -0,0 +1,44 @@ +import type { Command } from 'commander'; + +/** What `@fleetbase/installer` reads from its options. */ +export interface InstallFleetbaseOptions { + host?: string; + environment?: string; + directory?: string; + appName?: string; + nonInteractive?: boolean; +} + +type Wizard = (options: InstallFleetbaseOptions) => Promise; + +/** + * The wizard lives in `@fleetbase/installer` (also `npx @fleetbase/installer`). It is loaded + * only when the command runs: nothing else in the CLI needs it. + */ +async function loadWizard(): Promise { + const module = (await import('@fleetbase/installer')) as { installFleetbaseCommand?: Wizard; default?: { installFleetbaseCommand?: Wizard } }; + const wizard = module.installFleetbaseCommand ?? module.default?.installFleetbaseCommand; + if (typeof wizard !== 'function') { + throw new Error('@fleetbase/installer did not load. Reinstall the CLI, or run `npx @fleetbase/installer`.'); + } + return wizard; +} + +/** + * `flb install-fleetbase`: installs Fleetbase itself with Docker. The same flags as + * `npx @fleetbase/installer`, which this runs. + */ +export function register(program: Command): void { + program + .command('install-fleetbase') + .description('Install Fleetbase with Docker through the setup wizard (same as `npx @fleetbase/installer`)') + .option('--host ', 'Host or IP address to bind to (default: localhost)') + .option('--environment ', 'Environment: development or production (default: development)') + .option('--directory ', 'Installation directory (default: current directory)') + .option('--app-name ', 'Application name (default: Fleetbase)') + .option('--non-interactive', 'Skip every prompt; use flags and safe defaults (useful for CI/CD)') + .action(async (options: InstallFleetbaseOptions) => { + const wizard = await loadWizard(); + await wizard(options); + }); +} diff --git a/src/commands/legacy.ts b/src/commands/legacy.ts index db14acb..ea8124a 100644 --- a/src/commands/legacy.ts +++ b/src/commands/legacy.ts @@ -16,18 +16,6 @@ const MOVED: [string, string][] = [ ]; export function register(program: Command): void { - program - .command('install-fleetbase', { hidden: true }) - .description('Moved to @fleetbase/installer') - .allowUnknownOption() - .allowExcessArguments() - .action(() => { - log.error('install-fleetbase moved out of the CLI into its own package.'); - log.info('Run it with:'); - log.info(' npx @fleetbase/installer [--directory ] [--environment development|production] [--non-interactive]'); - process.exitCode = 1; - }); - for (const [name, replacement] of MOVED) { program .command(name, { hidden: true }) diff --git a/src/installer-module.d.ts b/src/installer-module.d.ts new file mode 100644 index 0000000..8d4e1ca --- /dev/null +++ b/src/installer-module.d.ts @@ -0,0 +1,9 @@ +declare module '@fleetbase/installer' { + export function installFleetbaseCommand(options: { + host?: string; + environment?: string; + directory?: string; + appName?: string; + nonInteractive?: boolean; + }): Promise; +} diff --git a/src/program.ts b/src/program.ts index 6c94521..4552fe3 100644 --- a/src/program.ts +++ b/src/program.ts @@ -11,6 +11,7 @@ import * as catalog from './commands/catalog.js'; import * as config from './commands/config.js'; import * as doctor from './commands/doctor.js'; import * as init from './commands/init.js'; +import * as installFleetbase from './commands/install-fleetbase.js'; import * as installer from './commands/installer.js'; import * as instance from './commands/instance.js'; import * as legacy from './commands/legacy.js'; @@ -29,7 +30,7 @@ export function createProgram(): Command { .showHelpAfterError('(run with --help for usage)') .configureHelp({ sortSubcommands: false }); - for (const module of [auth, token, init, build, bump, publish, release, listing, catalog, instance, installer, doctor, config, legacy]) { + for (const module of [auth, token, init, build, bump, publish, release, listing, catalog, instance, installer, installFleetbase, doctor, config, legacy]) { module.register(program); } return program; diff --git a/test/unit/install-fleetbase.test.ts b/test/unit/install-fleetbase.test.ts new file mode 100644 index 0000000..5f2175d --- /dev/null +++ b/test/unit/install-fleetbase.test.ts @@ -0,0 +1,46 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest'; + +const wizard = vi.fn(async () => {}); + +vi.mock('@fleetbase/installer', () => ({ installFleetbaseCommand: wizard })); + +const { createProgram, main } = await import('../../src/program.js'); + +describe('flb install-fleetbase', () => { + beforeEach(() => { + wizard.mockClear(); + process.exitCode = undefined; + }); + + it('is a listed command with the installer flags', () => { + const command = createProgram().commands.find((item) => item.name() === 'install-fleetbase'); + + expect(command).toBeDefined(); + expect(createProgram().helpInformation()).toContain('install-fleetbase'); + expect(command!.options.map((option) => option.long)).toEqual(['--host', '--environment', '--directory', '--app-name', '--non-interactive']); + }); + + it('runs the installer wizard with the flags it was given', async () => { + const code = await main(['node', 'flb', 'install-fleetbase', '--directory', './fleetbase', '--environment', 'production', '--host', 'fleet.example.com', '--app-name', 'Acme', '--non-interactive']); + + expect(code).toBe(0); + expect(wizard).toHaveBeenCalledTimes(1); + expect(wizard).toHaveBeenCalledWith({ directory: './fleetbase', environment: 'production', host: 'fleet.example.com', appName: 'Acme', nonInteractive: true }); + }); + + it('runs the wizard with no flags, for the interactive install', async () => { + const code = await main(['node', 'flb', 'install-fleetbase']); + + expect(code).toBe(0); + expect(wizard).toHaveBeenCalledWith({}); + }); +}); + +describe('the real @fleetbase/installer', () => { + it('exports the wizard the command calls', async () => { + const installer = await vi.importActual>('@fleetbase/installer'); + const exported = installer.installFleetbaseCommand ?? (installer.default as Record | undefined)?.installFleetbaseCommand; + + expect(typeof exported).toBe('function'); + }); +});