Skip to content
rpcpoolPublic

About

GitOps controller and CLI for reconciling Nomad resources from Git

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

tug

Tug is a GitOps controller and CLI for HashiCorp Nomad. It compares live Nomad resources to manifests in Git and can apply changes, repair drift, and prune resources removed from Git.

Quick start

Build Tug, start the controller, and query its status. Set NOMAD_ADDR and NOMAD_TOKEN as needed for your cluster.

go build ./cmd/tug

Copy the guestbook Application into ./apps and point it at a Git repository with your manifests.

./tug controller --apps-dir ./apps --state-backend nomad-var

In a separate terminal, query status or preview changes.

./tug status --server http://127.0.0.1:8080
./tug diff --app ./apps/guestbook.app.hcl

Applications

An Application specifies a Git repository, revision, manifest path, and Nomad destination. Its sync policy controls automated deployment (automated), drift repair (self_heal), and deletion of managed resources removed from Git (prune).

Use HCL (.app.hcl), YAML (.app.yaml, .app.yml), or JSON (.app.json). To load definitions from Git, pass --bootstrap-repo and use --bootstrap-path to select their directory.

ApplicationSets

An ApplicationSet renders one Application for each set of parameters a generator produces. List generators use explicit parameters, Git generators discover directories or load JSON and YAML parameters, and matrix generators combine results. See the list generator example.

Regional deployments

A RegionalDeployment repeats one Application across Nomad regions reachable through the same API endpoint. Each region can override the destination namespace and HCL variables. Use rollout groups to promote from canary to production. See the regional rollout example.

Manifests

Tug supports Nomad jobs, namespaces, quotas, CSI volumes, and variables. See example manifests for the file names and HCL syntax. Job diffs use Nomad's plan API.

Job placement and policy

Deployment previews and tug diff show task groups the Nomad plan could not place. Findings include the node pool, unmet constraints, and exhausted resources when Nomad supplies them. Placement findings are advisory by default. Set require_placement = true in an operator-managed project to block a job when Nomad reports unplaced allocations or cannot return a plan. A controller can also require an OPA decision.

Tug uses a fresh plan when it is about to register a changed or new job, including during automated sync, rollback, and self-heal. Deploy hooks run their checks immediately before registration. Checks apply to each job in wave order. Set up dependencies in earlier waves so Nomad can plan the jobs that need them. A blocked job stops the sync when Tug reaches it. Earlier writes stay in place, and other deployments can consume capacity after a successful dry run.

Sync waves

Put a waves.hcl file at the root of the manifest directory to assign integer waves by resource identity. For example, "Job/guestbook/guestbook" = 10 puts the job in wave 10. Use global as the namespace for namespaces and quotas. Unlisted resources use their existing filename prefix or default to wave 0.

Tug applies lower waves first and waits for their jobs to become healthy before continuing. Within a wave, it applies namespaces, quotas, volumes, variables, and jobs in that order.

Controller configuration

  • Store status in Nomad Variables (--state-backend nomad-var), Consul KV (--state-backend consul), or memory (--state-backend memory, the default).
  • Tug polls Git and watches Nomad events. Set --nomad-event-namespaces=apps,services or TUG_NOMAD_EVENT_NAMESPACES to watch explicit namespaces. Each stream reconnects independently. For one namespace, --nomad-event-namespace and TUG_NOMAD_EVENT_NAMESPACE also work. By default Tug watches all namespaces. To trigger reconciliation on a push, send webhooks to POST /api/v1/webhooks/git. Set TUG_WEBHOOK_SECRET to verify GitHub, Forgejo, Gitea, and GitLab requests. Tug only enables the webhook under a project policy when this secret is set.

Web dashboard

Tug also has a web UI. Open / on the controller's HTTP listener to see application sync status, health, and managed resources.

For OIDC sign-in, set TUG_OIDC_ISSUER_URL, TUG_OIDC_CLIENT_ID, TUG_OIDC_CLIENT_SECRET, and TUG_OIDC_BASE_URL. Register the browser-facing callback, for example https://tug.example.com/auth/callback.

Tug requests the profile scope by default when the provider advertises it. The account menu shows the name, preferred_username, or verified email claim from the ID token. Set TUG_OIDC_SCOPES to choose the scopes explicitly.

Use --projects-file to constrain each project's Git sources, resource kinds, and Nomad destinations. The controller applies those limits to scheduled refreshes, Git and Nomad events, and user-initiated deployments. Put the policy file under operator control and configure OIDC for the HTTP listener.

Define named roles and bind them to OIDC groups within each project. Permissions from matching groups combine. A signed-in user receives only the actions granted in that project. For example:

project "checkout" {
  sources = ["https://github.com/example/checkout-nomad.git"]
  kinds   = ["Job", "Variable"]

  destination {
    region    = "us-east"
    namespace = "checkout"
  }

  role "deployer" {
    actions = ["view", "sync", "rollout"]
  }

  role_binding "deployer" {
    groups = ["checkout-deployers"]
  }
}

YAML and JSON represent the same project with a roles list of name and actions entries and a role_bindings list of role and groups entries.

Action Grants
view Read status in the dashboard and JSON API. Include this permission when an operator needs the dashboard.
sync Review the sync plan and deploy a revision. A global sync requires this permission for every application.
rollback Review and deploy a previously deployed revision or resume its configured source revision.
rollout Pause, resume, or cancel a rollout.
orphan_retain Keep a removed application's resources.
orphan_delete Delete a removed application's owned resources.
audit_read Read audit events recorded for the project.

Existing view_groups continue to grant view and audit_read. Existing sync_groups continue to grant all actions in the table. To narrow an existing grant, add an equivalent named role and binding, then remove the legacy group entry when ready. The two formats combine their grants while both are present. Omitting the policy file keeps the legacy unscoped controller mode.

Set --anonymous-read (or TUG_ANONYMOUS_READ=true) with OIDC and mark each public project with public_read = true. Anonymous users receive public status. OIDC roles control access to plans, deployment history, and audit events. Signed-in users use their project roles.

The audit trail records the verified OIDC subject, action, and outcome. It defaults to the status backend. Use Consul or Nomad Variables for persistence, or set --audit-backend separately. Before upgrading a controller with project policies, let pending operations finish. Tug checks a queued request against the current policy and the verified group claims from that request. It rejects older queued operations without claims.

Give Tug a dedicated Nomad token scoped to the namespaces, resource operations, and status and audit variables it uses. When using Consul, scope its token to the configured status and audit prefixes. These credentials authorize the controller's backend calls. OIDC roles authorize human requests.

Operators can pause, resume, or cancel a rollout from the application page. Pausing holds the application until resumed. Cancelling holds the current revision. The page shows which wave or region is blocking progress, and jobs already submitted to Nomad continue running.

The application page keeps deployed revision history. A rollback pins the selected revision until an operator resumes the configured source revision.

Tug requires sync_policy.adopt = true to take ownership of an existing resource and sync_policy.allow_empty = true to apply an empty bundle. When a generated Application is removed, choose whether to retain or delete its resources in the dashboard.

Name a one-off batch jobspec pre-sync-*.nomad.hcl or post-sync-*.nomad.hcl to run it before rollout or after the workload becomes healthy. A failed hook blocks completion unless its job metadata sets tug.hook_failure to continue.

Development and releases

On Linux, run nix develop for the Go and release toolchain, then run go test ./.... Use nix build to build Tug or nix run . -- help to run it.

Maintainers dispatch the binary release workflow for a version tag such as v0.1.0. It publishes signed Linux amd64 and arm64 archives, checksums, and archive SBOMs to GitHub Releases. Pushing the same tag checks the Nix build and publishes a Linux amd64 and arm64 controller image at ghcr.io/rpcpool/tug:v0.1.0. You can also run the tag with Nix using nix run github:rpcpool/tug/v0.1.0 -- help.

Deploy the standalone binary or use the image for a containerized controller. The image starts tug controller by default and accepts the same environment variables as the binary, including NOMAD_ADDR, NOMAD_TOKEN, and TUG_BOOTSTRAP_REPO.

OpenTofu module

The Nomad deployment module registers Tug as a service, bootstraps application specs from Git, and stores status in Nomad Variables. See the OpenTofu example for provider setup and inputs.

Use a tagged source checkout with source = "git::https://github.com/rpcpool/tug.git//modules/tug-controller?ref=v0.1.0", or download the versioned tug-controller_0.1.0.tar.gz asset from the GitHub release.

The controller reads OIDC credentials from Vault at runtime. It can use a Nomad Workload Identity or a separate Nomad runtime token from Vault.

Preview release archives with goreleaser release --snapshot --clean. Set TUG_BUILD_IMAGE=true to also load a snapshot image into a local Docker daemon. Set TUG_KO_PLATFORM=linux/arm64 for an arm64 image.

License

The Tug application and CLI are licensed under the GNU Affero General Public License v3.0 only (LICENSE). The OpenTofu module is separately licensed under the Mozilla Public License 2.0 (module LICENSE).

About

GitOps controller and CLI for reconciling Nomad resources from Git

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages