Skip to content

Latest commit

 

History

History
388 lines (282 loc) · 24.1 KB

environment.md

File metadata and controls

388 lines (282 loc) · 24.1 KB

Development Environment Setup

This guide covers setting up a local development environment for FleetMDM — Flamingo's fork of the open-source Fleet device management platform, extended for the OpenFrame unified MSP ecosystem. It is a polyglot repository: a Go backend (cmd/fleet, server/), a React/TypeScript web console (frontend/), the fleetctl CLI, a Chrome-extension agent (ee/fleetd-chrome/), an Android agent module (android/), and a Sails-based marketing site (website/). For the full component map, see ../../reference/architecture/overview.md and ../../reference/architecture/ecosystem.md.

This document focuses on tooling, IDE configuration, and environment variables. For day-to-day workflows (running the server, building the frontend, running tests), see ./local-development.md.

At a Glance

Area Primary Tooling
Backend Go 1.26.6 (see go.mod), golangci-lint, Delve debugger
Frontend Node ^24.10.0, Yarn >=1.22.21 (see package.json), Webpack, Storybook
Chrome extension Node/TypeScript, Webpack (see ee/fleetd-chrome/package.json)
Android agent Kotlin, Gradle, ktlint, detekt (see android/app/build.gradle.kts)
Marketing site Node ^20.18, Sails (see website/package.json)
Editor Visual Studio Code (repo ships .vscode/ config)
Containers Docker Compose (docker-compose.yml and variants)

Required Development Tools

Go Toolchain

The server, fleetctl, and most CLI tools (cmd/fleet, cmd/fleetctl, tools/dibble) are Go modules. The root go.mod pins:

module github.com/fleetdm/fleet/v4
go 1.26.6

Install a matching Go toolchain (1.26.x) before building. The repository also contains independent Go modules that must be understood when working across directories:

  • handbook/go.mod — declares module fleetdm-handbook, deliberately excluded from the main module's published zip.
  • website/go.mod — declares module fleetdm-website, same reasoning.
  • third_party/goval-dictionary/go.mod — a vendored vulnerability-dictionary tool with its own go 1.26.4 toolchain and .golangci.yml.
  • third_party/vuln-check/go.mod — a dummy module that exists only so Dependabot/govulncheck can scan versions of dependencies that have been inlined (copied) into Fleet's own tree (NanoMDM, SCEP, goose, etc.). It is never compiled into the fleet binary.
  • tools/dibble/go.mod — a standalone CLI module (github.com/fleetdm/fleet/v4/tools/dibble) that replaces the parent module with the local checkout, so it can only be built from inside this repository.

When building or testing the server, use the build tags declared in the editor configs below (full,fts5) — omitting them will produce a binary missing SQLite full-text-search support used by osquery-derived queries.

Linting: golangci-lint is configured at the repo root via .golangci.yml (version "2" schema). It enables depguard, forbidigo, gosec, gocritic, govet, revive, staticcheck, errcheck, and more, with per-path exclusions (for example, migration files are exempted from depguard). Run it before pushing Go changes; the same linter runs in the .pre-commit-config.yaml hook (golangci-lint rev v2.11.3).

Node.js and Yarn (Frontend)

The root package.json declares:

"engines": {
  "node": "^24.10.0",
  "yarn": ">=1.22.21"
}

Use a Node version manager to match ^24.10.0 exactly — the frontend build (Webpack 5, Babel, TypeScript 6.0.2) is sensitive to Node major-version drift. Key scripts defined in package.json:

# Lint frontend TS/JS
yarn lint

# Check Prettier formatting
yarn prettier:check

# Run the Jest test suite
yarn test

# Run Jest in CI mode with coverage
yarn test:ci

# Start Storybook for component development
yarn storybook

# Build the static Storybook site
yarn build-storybook

The TypeScript project is configured in tsconfig.json, which extends @tsconfig/recommended, targets ES2019, and aliases the forked SQL parser package: node-sql-parser resolves to ./node_modules/@sgress454/node-sql-parser. Keep this alias in mind if your editor's "go to definition" seems to jump to an unexpected package.

Chrome Extension Toolchain (ee/fleetd-chrome)

This sub-project has its own package.json and tsconfig.json, targeting es2015/es2020 with the chrome, jest, and node type roots. Useful scripts (from ee/fleetd-chrome/package.json):

# Production build
npm run build

# Development build
npm run dev

# Watch mode
npm run watch

# Run tests (jsdom + experimental VM modules)
npm test

Android Agent Toolchain (android/)

The Android module uses Gradle with Kotlin DSL (android/build.gradle.kts, android/app/build.gradle.kts). It applies spotless (ktlint formatting) and detekt (static analysis), plus Jacoco for coverage. Formatting conventions are declared in android/.editorconfig:

  • 4-space indentation for .kt/.kts files, max_line_length = 140.
  • ktlint_standard_function-naming is disabled (Compose functions use PascalCase).
  • ktlint_standard_property-naming is disabled (Android conventionally uses uppercase TAG constants).
  • Import ordering prioritizes android.**, then androidx.**, com.**, org.**, java.**, kotlin.**, kotlinx.**.

Note from android/app/build.gradle.kts: Detekt is explicitly excluded from the check task in local builds (tasks.named("check") { setDependsOn(...) }) and only runs in CI — so running ./gradlew check locally will not by itself catch Detekt findings; run the detekt task directly if you need that feedback loop. Integration tests that exercise the SCEP (Simple Certificate Enrollment Protocol) flow require two Gradle properties, or the build fails fast with a descriptive error:

./gradlew test -PrunIntegrationTests=true \
  -Pscep.url=https://your-scep-server.com/scep \
  -Pscep.challenge=your-challenge-password

Marketing Site Toolchain (website/)

website/package.json targets Node ^20.18 and is a Sails application. Its own .eslintrc and .editorconfig (2-space indent, LF line endings, trailing-whitespace trimming) apply only inside website/ and are explicitly layered: website/views/.eslintrc extends website/assets/.eslintrc, which extends the top-level website/.eslintrc, to separate Node/Sails globals (sails, models like User, Quote) from browser globals (window, Vue, parasails).

Docker and Local Infrastructure

Local development against MySQL, Redis, and object storage is driven by Docker Compose files at the repository root and under tools/:

  • docker-compose.yml — the primary local stack.
  • docker-compose-redis-cluster.yml — Redis cluster variant.
  • tools/test-orbit-mtls/docker-compose.yml — mTLS orbit testing.
  • tools/telemetry/docker-compose.yml — OpenTelemetry/SigNoz-adjacent telemetry stack.

Install Docker and Docker Compose before attempting any of the workflows in ./local-development.md. The default dev configuration in cmd/fleet/main.go (applyDevFlags) assumes a local MinIO-compatible S3 endpoint at http://localhost:9000 with access key locals3 when carves/software-installer buckets are left unset — this is wired for the Compose stack, not a production credential.

Pre-commit Hooks

.pre-commit-config.yaml wires several linters as git hooks across the polyglot codebase:

Hook Tool Scope
php-lint-all digitalpulp/pre-commit-php PHP
gitleaks secret scanning all
golangci-lint golangci/golangci-lint v2.11.3 Go
RuboCop, shellcheck jumanjihouse/pre-commit-hooks Ruby, shell
cpplint pocc/pre-commit-hooks C/C++
eslint pre-commit/mirrors-eslint v8.38.0 JS/TS
end-of-file-fixer, trailing-whitespace pre-commit/pre-commit-hooks all
pylint pylint-dev/pylint Python

Install pre-commit and run pre-commit install in your clone so these hooks run automatically before each commit.

IDE Recommendations and Setup

Visual Studio Code (Primary, Repository-Configured)

The repository ships a full .vscode/ workspace configuration, which is the recommended starting point for any contributor.

Recommended Extensions

.vscode/extensions.json lists the extensions VS Code will prompt you to install when you open the workspace:

{
    "recommendations": [
        "stkb.rewrap",
        "github.vscode-pull-request-github",
        "golang.go",
        "esbenp.prettier-vscode",
        "redhat.vscode-yaml",
        "dbaeumer.vscode-eslint",
        "firefox-devtools.vscode-firefox-debug",
        "editorconfig.editorconfig",
        "timonwong.shellcheck"
    ]
}
Extension Purpose
golang.go Go language server (gopls), debugging, build-tag awareness
esbenp.prettier-vscode JS/TS/JSX formatting on save
dbaeumer.vscode-eslint Frontend linting integration
redhat.vscode-yaml YAML schema validation (used for the codecov.yml schema binding, see below)
firefox-devtools.vscode-firefox-debug Launch/attach debugging for the Firefox frontend configuration
editorconfig.editorconfig Applies .editorconfig rules automatically across editors
timonwong.shellcheck Shell-script linting for the assets/scripts/*.sh and openframe/scripts/*.sh helpers
github.vscode-pull-request-github Review and manage pull requests inline
stkb.rewrap Rewraps prose/comments to a configured column

Workspace Settings

.vscode/settings.json applies these defaults to everyone opening the workspace:

{
    "editor.formatOnPaste": true,
    "editor.formatOnSave": true,
    "editor.formatOnType": true,
    "go.lintTool": "golangci-lint",
    "go.useLanguageServer": true,
    "gopls": { "gofumpt": true },
    "go.autocompleteUnimportedPackages": true,
    "go.buildTags": "full,fts5",
    "go.testTimeout": "5m",
    "go.testEnvVars": {
        "MYSQL_TEST": "1",
        "REDIS_TEST": "1"
    },
    "prettier.requireConfig": true,
    "js/ts.tsdk.path": "node_modules/typescript/lib"
}

Points worth noting:

  • go.buildTags is set to full,fts5 — always build/test with these tags so the Go language server's diagnostics match what the real binary compiles with.
  • gopls.gofumpt enables the stricter gofumpt formatting rules on top of standard gofmt.
  • go.testEnvVars pre-populates MYSQL_TEST and REDIS_TEST so in-editor "Run Test" / "Debug Test" codelenses automatically exercise datastore-backed tests — this mirrors the MYSQL_TEST/REDIS_TEST/NETWORK_TEST variables also declared in .vscode/launch.json (see below).
  • prettier.requireConfig means Prettier only formats files in directories where a config is explicitly found — it will not silently reformat files in sub-projects that use a different style (e.g. website/).
  • js/ts.tsdk.path pins the TypeScript version used by the editor to the project's own node_modules/typescript, avoiding mismatches with a globally-installed TypeScript.
  • yaml.schemas binds the https://json.schemastore.org/codecov.json schema to .github/workflows/codecov.yml for inline validation.

Debug Configurations (launch.json)

.vscode/launch.json defines ready-to-use debug targets — select one from the VS Code "Run and Debug" panel:

Configuration What it does
Test package Runs/debugs all Go tests in the current file's directory, with MYSQL_TEST=1, REDIS_TEST=1, NETWORK_TEST=1 and build tags full,fts5
Test file Same, scoped to the currently open test file
Fleet serve Launches cmd/fleet with serve --dev --logging_debug
Fleet serve (licensed) Same, plus --dev_license to simulate an Enterprise license locally
Fleet vuln_processing (licensed) Runs the vuln_processing subcommand with --dev --logging_debug --dev_license
Attach to a running Fleet server Remote Delve attach on port 61179 at 127.0.0.1
Fleet UI (Chrome) Launches a Chrome instance pointed at https://localhost:8080
Fleet UI (Firefox) Launches Firefox at https://localhost:8080, mapping webpack:///frontend back to the local frontend/ directory for source-mapped breakpoints
Jest: test current file Runs Jest against the active file using ./frontend/test/jest.config.js
Jest: run all tests Runs the full Jest suite using the same config

The Delve configuration under dlvLoadConfig increases variable-inspection limits (maxStringLen: 256, maxArrayValues: 64, maxStructFields: -1, followPointers: true) so debugging large structs (hosts, software inventories) doesn't truncate data in the debugger view.

Tasks (tasks.json)

.vscode/tasks.json registers one build task, runnable via the Command Palette ("Run Task"):

{
    "type": "npm",
    "script": "lint",
    "label": "npm: lint",
    "detail": "eslint frontend cypress --ext .js,.jsx,.ts,.tsx"
}

Editor-Agnostic Formatting (.editorconfig)

For contributors using an editor other than VS Code, .editorconfig files are present at multiple scopes and will be honored by any EditorConfig-aware editor:

  • android/.editorconfig — Kotlin-specific rules described above.
  • website/.editorconfig, ee/fleet-agent-downloader/.editorconfig, ee/vulnerability-dashboard/.editorconfig — identical Sails-app conventions: 2-space indent, LF line endings, UTF-8 charset, trim trailing whitespace, insert final newline.

Install the EditorConfig plugin for your editor if it is not built in (JetBrains IDEs and VS Code both support it natively, VS Code via the recommended editorconfig.editorconfig extension above).

JetBrains GoLand / IntelliJ (Alternative)

No GoLand-specific project files are checked into the repository, but the same signals apply:

  • Point the Go SDK at Go 1.26.6 to match go.mod.
  • Add full fts5 to the custom build tags in Go build/test run configurations (mirroring .vscode/settings.json's go.buildTags), or test runs will diverge from what CI and VS Code produce.
  • Enable the bundled golangci-lint integration and point it at the repository's .golangci.yml.
  • For the frontend, set the project's TypeScript version to the bundled one under node_modules/typescript rather than any IDE-bundled version, matching the js/ts.tsdk.path setting used in VS Code.

Environment Variables for Development

Go Test Environment

Several Go tests are gated behind environment flags so that a plain go test ./... does not require live MySQL/Redis/network dependencies. These same variables appear in both .vscode/launch.json and .vscode/settings.json:

Variable Effect
MYSQL_TEST Set to 1 to enable tests that require a live MySQL connection
REDIS_TEST Set to 1 to enable tests that require a live Redis connection
NETWORK_TEST Set to 1 to enable tests that make real network calls (used in the Test package/Test file launch configurations)

Fleet Server Dev Flags

cmd/fleet/main.go's applyDevFlags function fills in sensible local defaults when the --dev flag is passed to fleet serve, so you do not need to hand-craft every config value for local work. It only fills values that are otherwise empty:

  • Mysql.Password defaults to insecure.
  • S3 carve-storage settings (S3.CarvesBucket, S3.CarvesRegion, S3.CarvesPrefix, S3.CarvesEndpointURL, S3.CarvesAccessKeyID, S3.CarvesSecretAccessKey) default to a local MinIO-style setup at http://localhost:9000 with credentials locals3/locals3, and SSL/path-style flags are adjusted automatically when those defaults are in effect.
  • The same pattern applies to S3.SoftwareInstallers* settings for the software-installer bucket.

Beyond --dev, the full configuration surface for fleet serve is controlled by environment variables, a YAML config file, or CLI flags, in that precedence order (CLI flags > environment variables > config file > defaults) — this precedence is documented directly in the fleet config_dump command's help text in cmd/fleet/config_dump.go. Use:

fleet config_dump

to see the fully merged configuration your current environment produces, which is the fastest way to confirm an environment variable actually took effect.

fleetctl Client Configuration

fleetctl reads and writes a YAML config file (default ~/.fleet/config) with named contexts, as implemented in cmd/fleetctl/fleetctl/config.go. Several settings can be supplied as environment variables instead of CLI flags, per the EnvVars bindings on each flag:

Flag Environment Variable Purpose
--config CONFIG Path to the fleetctl config file
--context CONTEXT Name of the config context to use (default default)
--address ADDRESS Fleet server address
--email EMAIL Account email for the Fleet server
--token TOKEN Fleet API token
--tls-skip-verify INSECURE Skip TLS certificate validation (dev only)
--rootca ROOTCA Custom root CA chain
--url-prefix URL_PREFIX URL prefix matching the server configuration
--custom-header CUSTOM_HEADER Custom header(s) sent on every request, as Header:Value (comma-separated when set via env var)

Set these with fleetctl config set --address ... --email ... or export the corresponding environment variables before invoking fleetctl.

Fleet MCP Server (tools/fleet-mcp)

tools/fleet-mcp/.env.example is the template for the Fleet MCP (Model Context Protocol) server's local .env file. Copy it before use:

cp tools/fleet-mcp/.env.example tools/fleet-mcp/.env

Key variables it defines:

Variable Purpose
PORT Port for the SSE transport (ignored in stdio mode)
MCP_AUTH_TOKEN Bearer token MCP clients must send; required at startup regardless of transport. Generate with openssl rand -hex 32
MCP_AUTH_TOKEN_FILE Alternative: read the token from a file (wins over MCP_AUTH_TOKEN)
FLEET_BASE_URL Base URL of your Fleet instance, including scheme and non-standard port if any
FLEET_API_KEY Fleet API token, generated in Fleet under Settings > Integrations > API
FLEET_API_KEY_FILE Alternative: read the API key from a file (wins over FLEET_API_KEY)
LOG_LEVEL One of debug, info, warn, error
FLEET_TLS_SKIP_VERIFY Dev/test only — skip TLS verification against a self-signed Fleet instance
FLEET_CA_FILE Path to a PEM CA certificate to trust a self-signed Fleet instance, as an alternative to skipping verification

The .env file is loaded only when the binary runs directly (SSE transport, local dev, smoke tests). When Claude Desktop runs it in stdio mode, it reads environment variables from the env block of claude_desktop_config.json instead.

Fleet Slackbot (tools/fleet-slackbot)

tools/fleet-slackbot/.env.example configures the Slack/GitHub/Anthropic integration used by the Slackbot tool. Relevant variables:

Variable Purpose
SLACK_BOT_TOKEN, SLACK_APP_TOKEN Slack bot and app-level tokens
GITHUB_TOKEN GitHub token for repository operations
GITHUB_REPO Target repository, e.g. fleetdm/fleet
GITHUB_BASE_BRANCH Base branch for automated PRs, e.g. main
GITOPS_BASE_PATH Base path for GitOps-managed configuration, e.g. it-and-security
GITHUB_BOT_USERNAME Username the bot commits/comments as
ANTHROPIC_API_KEY, ANTHROPIC_MODEL Anthropic API credentials and model name
GITHUB_WEBHOOK_SECRET Secret used to verify incoming GitHub webhooks
PORT HTTP port for the webhook listener
GITOPS_CI_CHECK_NAME Name of the CI check gating GitOps auto-fix
CI_AUTO_FIX Set to false to disable automated CI fixes
FLEET_MCP_URL, FLEET_MCP_AUTH_TOKEN Connection details for the Fleet MCP server described above

ESLint Globals (Frontend and Sub-Apps)

The root .eslintrc.js configures the main frontend/ TypeScript/React codebase (Airbnb config, @typescript-eslint, react-hooks, Jest, Storybook plugins) and resolves module imports through the webpack.config.js resolver. The three Sails sub-applications (website/, ee/fleet-agent-downloader/, ee/vulnerability-dashboard/) each carry their own .eslintrc, declaring Node-only globals (sails, _, model names like User, Vulnerability, Platform) that differ between apps — do not assume a global available in one Sails app (e.g. AndroidEnterprise in website/.eslintrc) exists in another.

Editor Extensions and Plugins

The VS Code extension list in .vscode/extensions.json is the canonical, repository-endorsed plugin set (see the IDE section above for the full table and rationale). Summarized by concern:

  • Go development: golang.go (language server, debugger, test runner integration with the go.buildTags/go.testEnvVars settings).
  • Formatting: esbenp.prettier-vscode (JS/TS, governed by .prettierrc.json, which is intentionally empty to accept Prettier's defaults) and editorconfig.editorconfig (cross-language whitespace/line-ending rules).
  • Linting: dbaeumer.vscode-eslint (frontend) and timonwong.shellcheck (shell scripts under assets/scripts/ and openframe/scripts/).
  • YAML: redhat.vscode-yaml, used here specifically for schema-validating .github/workflows/codecov.yml.
  • Debugging: firefox-devtools.vscode-firefox-debug, paired with the Fleet UI (Firefox) launch configuration's pathMappings back to frontend/.
  • Collaboration: github.vscode-pull-request-github for reviewing and managing pull requests without leaving the editor. Note this repository does not use GitHub Issues or GitHub Discussions for project management — discussion happens on the OpenMSP Slack community instead.
  • Prose: stkb.rewrap, configured in .vscode/settings.json with rewrap.autoWrap.enabled: true and rewrap.wrappingColumn: 100, useful when editing long comments or Markdown.

For Android work, there are no checked-in IDE project files, but Android Studio (the JetBrains-based IDE for Android) is implied by android/.editorconfig's explicit ktlint_code_style = android_studio setting and its ij_kotlin_* (IntelliJ) keys for trailing-comma and import-order behavior.

Fork-Specific Conventions to Set Up Your Editor For

Because this repository is Flamingo's fork of upstream fleetdm/fleet, one active code-review rule has direct editor implications: any edit to a file that originates from upstream Fleet (for example cmd/fleet/cron_registration.go or client/orbit_client.go) must be wrapped in sentinel comments of the form:

// >>> OPENFRAME(<slug>): <why> — openframe/docs/<doc>.md
... your change ...
// <<< OPENFRAME(<slug>)

Net-new, fork-only code under paths like server/service/openframe/ is exempt from this requirement. Configuring a code snippet or live-template in your editor for this sentinel pair is worth doing if you expect to touch upstream-origin files regularly, since the automated reviewer treats a missing sentinel pair in a shared upstream file as a rejectable finding.

Separately, Go contributions anywhere in the tree are expected to wrap errors at call boundaries with fmt.Errorf("<context>: %w", err), and code under cmd/, server/, and ee/server/ specifically must construct errors via ctxerr.New/ctxerr.Wrap rather than bare fmt.Errorf/errors.New, and log via log/slog's context-aware methods (InfoContext, ErrorContext, DebugContext) with structured key-value pairs rather than global loggers or string interpolation. These conventions are enforced by the automated code reviewer and are worth knowing before your first PR, even though they are not themselves IDE settings.

Where to Go Next

Once your tools are installed and your editor is configured, ./local-development.md covers actually running the Fleet server, frontend, and Docker Compose stack day to day. For a first orientation to the platform, start with ../../getting-started/introduction.md and ../../getting-started/prerequisites.md. Contribution conventions beyond environment setup — commit style, PR expectations, code review norms — live in ../contributing/guidelines.md. For architecture and system design, see ../architecture/README.md and the diagrams indexed at ../../diagrams/architecture/README.md.