Skip to content

Commit

Permalink
refactor: remove the deprecated local dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald committed Jan 7, 2023
1 parent 3401f49 commit 601d240
Show file tree
Hide file tree
Showing 107 changed files with 95 additions and 6,397 deletions.
3 changes: 1 addition & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ orbs:
commands:
npm_install:
description: |
Installs npm packages for root, core, and dashboard and loads and saves the caches as appropriate
Installs npm packages and loads and saves the caches as appropriate
parameters:
context:
description: Set this to vm if installing in a VM, to avoid conflicting caches with the docker runs
Expand Down Expand Up @@ -257,7 +257,6 @@ jobs:
# Save the built output for future
- cli/build/
- core/build/
- dashboard/build/
- static/
# TODO: see if we can make this somewhat more specific
- sdk/
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ gulpfile.js
*.tsbuildinfo
build/
dist/
static/dashboard/
static/**/.garden-version

#debug files
Expand Down
7 changes: 2 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ The project code is composed of several components, most of which are written in
| `bin` | Executable commands, to use for development. _Note that you need to build the project before these work._ |
| `cli` | The Garden CLI package, which composes code from different packages into the final CLI executable. |
| `core` | The bulk of the Garden code and tests live here. |
| `dashboard` | The Garden web dashboard, which is bundled with the CLI. |
| `docs` | Markdown documentation, which is used to generate [docs.garden.io](https://docs.garden.io). _Note that the reference docs are auto-generated, and should not be edited by hand!._ |
| `examples` | Various Garden example projects. |
| `images` | Supporting container images, used by e.g. the `kubernetes` provider. |
Expand Down Expand Up @@ -75,7 +74,7 @@ If you are an [asdf](https://asdf-vm.com/) user, running `./scripts/install-asdf

### Step 4: Bootstrap project

Install Node modules for the root package, and the `dashboard` and `core` packages:
Install Node modules for the root package, and `core` package:

```sh
yarn install # To install root dependencies
Expand All @@ -101,7 +100,7 @@ Before running Garden for the first time, you need to do an initial build by run
yarn build
```

from the root directory. This ensures that the dashboard is built and ready to serve and that version files are in place.
from the root directory.

### Developing

Expand All @@ -121,8 +120,6 @@ alias g='garden'
alias k='kubectl'
```

For developing the dashboard, please refer to the [dashboard docs](./dashboard/README.md).

### Formatting

We use [Prettier](https://prettier.io) for automated formatting. We highly recommend installing the appropriate plugin for your editor to automate formatting as you work on your code. You can also run `yarn run fix-format` to fix formatting across the codebase.
Expand Down
1 change: 0 additions & 1 deletion RELEASE_PROCESS.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ To make a new release, set your current working directory to the garden root dir
- On a **Windows** machine, run `garden deploy --dev vote --env remote` in the `vote` example project.
- If there are any issues with syncing, consider changing the `services[].devMode.sync[].mode` value(s) to `one-way-replica` and restarting Garden.
- Change a file in the `vote` service and verify that the code synchronization was successful.
- Open the dashboard, verify that the initial page loads without errors.
4. You might need to include some additional commits here. For example, if any other fix(es) should be included from `main`, or if there are any test failures. In that case ypou need a new pre-release:
- Checkout to the most recent pre-release branch, e.g. `1.2.3-0`, and cherry-pick the appropriate commits from `main`.
- Run `./scripts/release.ts prerelease` - it will generate a new pre-release `1.2.3-1`.
Expand Down
2 changes: 1 addition & 1 deletion core/src/analytics/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ export class AnalyticsHandler {
}

/**
* Tracks an Api call generated from within the Dashboard.
* Tracks an API call sent to the core server.
*
* @param {string} method The HTTP method of the request
* @param {string} path The path of the request
Expand Down
35 changes: 6 additions & 29 deletions core/src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import { AnalyticsHandler } from "../analytics/analytics"
import { BufferedEventStream, ConnectBufferedEventStreamParams } from "../cloud/buffered-event-stream"
import { defaultDotIgnoreFile } from "../util/fs"
import type { GardenProcess } from "../db/entities/garden-process"
import { DashboardEventStream } from "../server/dashboard-event-stream"
import { CoreEventStream } from "../server/core-event-stream"
import { GardenPluginReference } from "../plugin/plugin"
import { renderError } from "../logger/renderers"
import { CloudApi } from "../cloud/api"
Expand Down Expand Up @@ -303,7 +303,7 @@ ${renderCommands(commands)}
}
})

const dashboardEventStream = new DashboardEventStream({ log, sessionId })
const coreEventStream = new CoreEventStream({ log, sessionId })

const commandInfo = {
name: command.getFullName(),
Expand Down Expand Up @@ -382,10 +382,10 @@ ${renderCommands(commands)}
})
}

// Connect the dashboard event streamer (making sure it doesn't stream to the local server)
// Connect the core server event streamer (making sure it doesn't stream to the local server)
const commandServerUrl = command.server?.getUrl() || undefined
dashboardEventStream.connect({ garden, ignoreHost: commandServerUrl, streamEvents, streamLogEntries })
const runningServers = await dashboardEventStream.updateTargets()
coreEventStream.connect({ garden, ignoreHost: commandServerUrl, streamEvents, streamLogEntries })
await coreEventStream.updateTargets()

if (cloudApi && !cloudApi.sessionRegistered && command.streamEvents) {
// Note: If a config change during a watch-mode command's execution results in the resolved environment
Expand Down Expand Up @@ -426,29 +426,6 @@ ${renderCommands(commands)}
`
footerLog.setState(msg)
}

// TODO: "Tone down" dashboard link when connected to Garden Cloud.
if (persistent && command.server) {
// If there is an explicit `garden dashboard` process running for the current project+env, and a server
// is started in this Command, we show the URL to the external dashboard. Otherwise the built-in one.

// Note: Lazy-loading for startup performance
const { GardenProcess: GP } = require("../db/entities/garden-process")

const dashboardProcess = GP.getDashboardProcess(runningServers, {
projectRoot: garden.projectRoot,
projectName: garden.projectName,
environmentName: garden.environmentName,
namespace: garden.namespace,
})

let url: string | undefined
if (dashboardProcess) {
url = `${dashboardProcess.serverHost}?key=${dashboardProcess.serverAuthKey}`
}

command.server.showUrl(url)
}
}

if (cloudApi) {
Expand Down Expand Up @@ -535,7 +512,7 @@ ${renderCommands(commands)}
throw err
} finally {
if (!result.restartRequired) {
await dashboardEventStream.close()
await coreEventStream.close()
await command.server?.close()
cloudApi?.close()
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/commands/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { UnlinkCommand } from "./unlink/unlink"
import { UpdateRemoteCommand } from "./update-remote/update-remote"
import { ValidateCommand } from "./validate"
import { ExecCommand } from "./exec"
import { DashboardCommand } from "./dashboard"
import { ServeCommand } from "./serve"
import { OptionsCommand } from "./options"
import { ConfigCommand } from "./config/config"
import { PluginsCommand } from "./plugins"
Expand Down Expand Up @@ -58,7 +58,7 @@ export const getCoreCommands = (): (Command | CommandGroup)[] => [
new PublishCommand(),
new RunCommand(),
new ScanCommand(),
new DashboardCommand(),
new ServeCommand(),
new SelfUpdateCommand(),
new SetCommand(),
new TestCommand(),
Expand Down
38 changes: 18 additions & 20 deletions core/src/commands/dashboard.ts → core/src/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,41 @@ import chalk = require("chalk")
import { Garden } from "../garden"
import { processActions } from "../process"

export const defaultDashboardPort = 9700
export const defaultServerPort = 9700

const dashboardArgs = {}
const serveArgs = {}

const dashboardOpts = {
const serveOpts = {
port: new IntegerParameter({
help: `The port number for the Garden dashboard to listen on.`,
defaultValue: defaultDashboardPort,
help: `The port number for the server to listen on.`,
defaultValue: defaultServerPort,
}),
}

type Args = typeof dashboardArgs
type Opts = typeof dashboardOpts
type Args = typeof serveArgs
type Opts = typeof serveOpts

export class DashboardCommand extends Command<Args, Opts> {
name = "dashboard"
aliases = ["serve"]
help = "Starts the Garden dashboard for the current project and environment."
export class ServeCommand extends Command<Args, Opts> {
name = "serve"
aliases = ["dashboard"]
help = "Starts the Garden Core API server for the current project and environment."

cliOnly = true
streamEvents = true
hidden = true
private garden?: Garden

description = dedent`
Starts the Garden dashboard for the current project, and your selected environment+namespace. The dashboard can be used to monitor your Garden project, look at logs, provider-specific dashboard pages and more.
Starts the Garden Core API servier for the current project, and your selected environment+namespace.
The dashboard will receive and display updates from other Garden processes that you run with the same Garden project, environment and namespace.
Note: You must currently run one dashboard per-environment and namespace.
Note: You must currently run one server per environment and namespace.
`

arguments = dashboardArgs
options = dashboardOpts
arguments = serveArgs
options = serveOpts

printHeader({ headerLog }) {
printHeader(headerLog, "Dashboard", "bar_chart")
printHeader(headerLog, "Server", "bar_chart")
}

terminate() {
Expand All @@ -70,7 +69,7 @@ export class DashboardCommand extends Command<Args, Opts> {
if (err.errno === "EADDRINUSE" && err.port === opts.port) {
log.error({
msg: dedent`
Port ${opts.port} is already in use, possibly by another dashboard process.
Port ${opts.port} is already in use, possibly by another Garden server process.
Either terminate the other process, or choose another port using the --port parameter.
`,
})
Expand Down Expand Up @@ -106,7 +105,6 @@ export class DashboardCommand extends Command<Args, Opts> {
skipWatch: allActions,
skipWatchModules: allModules,
changeHandler: async () => [],
overRideWatchStatusLine: "Dashboard running...",
})

return {}
Expand Down
2 changes: 0 additions & 2 deletions core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ export const GLOBAL_CONFIG_FILENAME = "global-config.yml"
export const GARDEN_CORE_ROOT = isPkg ? resolve(process.execPath, "..") : resolve(__dirname, "..", "..")
export const GARDEN_CLI_ROOT = isPkg ? resolve(process.execPath, "..") : resolve(GARDEN_CORE_ROOT, "..", "cli")
export const STATIC_DIR = isPkg ? resolve(process.execPath, "..", "static") : resolve(GARDEN_CORE_ROOT, "..", "static")
// We symlink to it the built dashboard to the core static directory during dev, and copy it there for dist builds
export const DASHBOARD_STATIC_DIR = join(STATIC_DIR, "dashboard")
export const DEFAULT_GARDEN_DIR_NAME = ".garden"
export const LOGS_DIR_NAME = "logs"
export const GARDEN_GLOBAL_PATH = join(homedir(), DEFAULT_GARDEN_DIR_NAME)
Expand Down
8 changes: 4 additions & 4 deletions core/src/db/entities/garden-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { partition, find, isMatch } from "lodash"

/**
* Each GardenProcess entry maps to a running Garden process. We use this to keep track of active processes,
* and to allow one process to find another, e.g. a running dashboard process for a project/env.
* and to allow one process to find another, e.g. a running server process for a project/env.
*/
@Entity()
export class GardenProcess extends GardenEntity {
Expand Down Expand Up @@ -87,12 +87,12 @@ export class GardenProcess extends GardenEntity {
}

/**
* Finds a running dashboard process for the given project, environment and namespace, returns undefined otherwise.
* Finds a running server process for the given project, environment and namespace, returns undefined otherwise.
*
* @param runningProcesses - List of running processes, as returned by `getActiveProcesses()`
* @param scope - Project information to match on
*/
static getDashboardProcess(
static getServerProcess(
runningProcesses: GardenProcess[],
scope: {
projectRoot: string
Expand All @@ -103,7 +103,7 @@ export class GardenProcess extends GardenEntity {
): GardenProcess | undefined {
return find(
runningProcesses,
(p) => !!p.serverHost && !!p.serverAuthKey && isMatch(p, { ...scope, command: "dashboard", persistent: true })
(p) => !!p.serverHost && !!p.serverAuthKey && isMatch(p, { ...scope, command: "serve", persistent: true })
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ import { isEqual } from "lodash"
const targetUpdateIntervalMsec = 1000

@Profile()
export class DashboardEventStream extends BufferedEventStream {
export class CoreEventStream extends BufferedEventStream {
protected intervalMsec = 250

private targetPollIntervalId?: NodeJS.Timeout
private ignoreHost: string | undefined

connect(params: ConnectBufferedEventStreamParams & { ignoreHost?: string }) {
// Need this so the dashboard command doesn't try to send events to itself.
// Need this so the serve command doesn't try to send events to itself.
// We can't ignore by PID because we wouldn't be able to unit test easily.
this.ignoreHost = params.ignoreHost
super.connect(params)
}

/**
* Updates the list of active dashboard servers to stream events to.
* Updates the list of active servers to stream events to.
* Returns the list of Garden processes matching the current project/env that are active servers.
*/
async updateTargets() {
Expand Down Expand Up @@ -59,7 +59,7 @@ export class DashboardEventStream extends BufferedEventStream {

// Notify of updates
if (this.garden && !isEqual(currentHosts, newHosts)) {
this.log.debug(`Updated list of running dashboard servers: ${servers.map((p) => p.serverHost).join(", ")}`)
this.log.debug(`Updated list of running servers: ${servers.map((p) => p.serverHost).join(", ")}`)

this.garden.events.emit("serversUpdated", {
servers: servers.map((p) => ({
Expand All @@ -74,7 +74,7 @@ export class DashboardEventStream extends BufferedEventStream {
}

/**
* Poll for running dashboard servers
* Poll for running servers
*/
startInterval() {
super.startInterval()
Expand Down
Loading

0 comments on commit 601d240

Please sign in to comment.