Skip to content

๐Ÿš€ Getting Started with Sloth Runner

Welcome to Sloth Runner - the AI-powered GitOps task orchestration platform! This guide will get you up and running in minutes.


๐Ÿ“ฆ Installation

Install the latest release with our automated script:

curl -sSL https://raw.githubusercontent.com/chalkan3-sloth/sloth-runner/main/install.sh | bash

This script: - โœ… Detects your OS and architecture automatically - โœ… Downloads the latest release from GitHub - โœ… Installs to /usr/local/bin - โœ… Verifies installation

Note: Requires sudo privileges.

Manual Installation

Download from GitHub Releases:

# Linux AMD64
wget https://github.com/chalkan3-sloth/sloth-runner/releases/latest/download/sloth-runner-linux-amd64.tar.gz
tar xzf sloth-runner-linux-amd64.tar.gz
sudo mv sloth-runner /usr/local/bin/

# macOS ARM64 (Apple Silicon)
wget https://github.com/chalkan3-sloth/sloth-runner/releases/latest/download/sloth-runner-darwin-arm64.tar.gz
tar xzf sloth-runner-darwin-arm64.tar.gz
sudo mv sloth-runner /usr/local/bin/

Verify Installation

sloth-runner version

๐ŸŽฏ Quick Start

Your First Workflow

Create a simple workflow file hello.sloth:

-- hello.sloth
task("hello")
  :description("My first task")
  :command(function()
    print("๐Ÿฆฅ Hello from Sloth Runner!")
    return true
  end)
  :build()

Run it:

sloth-runner run -f hello.sloth

Modern Output Styles

Try different output formats:

# Basic output
sloth-runner run -f hello.sloth -o basic

# Enhanced with colors and icons
sloth-runner run -f hello.sloth -o enhanced

# Rich with progress bars
sloth-runner run -f hello.sloth -o rich

# Modern UI
sloth-runner run -f hello.sloth -o modern

# JSON for CI/CD
sloth-runner run -f hello.sloth -o json

๐Ÿ“š Core Concepts

File Extension

๐Ÿ“ Important: Sloth Runner uses .sloth extension for workflow files (not .lua). The syntax is still Lua - only the extension changed for better identification.

Tasks

Tasks are the building blocks. Define with the builder pattern:

task("build")
  :description("Build the application")
  :command("go build -o app")
  :build()

task("test")
  :description("Run tests")
  :command("go test ./...")
  :depends_on("build")
  :build()

Task Groups

Organize related tasks:

task_group("ci")
  :description("CI pipeline")
  :tasks({"build", "test", "lint"})

๐Ÿ—‚๏ธ Stack Management

Stacks provide state persistence and environment isolation.

Create a Stack

sloth-runner stack new prod-app \
  -f deploy.sloth \
  --description "Production deployment"

Run with Stack

# Run workflow on stack
sloth-runner run prod-app --yes

# Check stack state
sloth-runner stack show prod-app

# List all stacks
sloth-runner stack list

Stack Benefits

  • โœ… State persistence between runs
  • โœ… Environment isolation
  • โœ… History tracking
  • โœ… Resource management

๐ŸŽจ Modern DSL Features

Task Builder API

task("deploy")
  :description("Deploy to production")
  :condition(function() return os.getenv("ENV") == "prod" end)
  :command(function()
    log.info("Deploying...")
    return exec.run("kubectl apply -f k8s/")
  end)
  :on_success(function()
    log.success("โœ… Deployed successfully!")
  end)
  :on_error(function(err)
    log.error("โŒ Deployment failed: " .. err)
  end)
  :timeout(300)
  :retry(3)
  :build()

Values Files

Parameterize workflows with values files:

values.yaml:

environment: production
replicas: 3
image: myapp:v1.2.3

deploy.sloth:

local env = values.environment
local replicas = values.replicas

task("deploy")
  :command(function()
    log.info("Deploying to " .. env)
    log.info("Replicas: " .. replicas)
  end)
  :build()

Run with values:

sloth-runner run -f deploy.sloth -v values.yaml

๐Ÿค– Built-in Modules

Sloth Runner includes powerful built-in modules:

Example: Docker Deployment

local docker = require("docker")

task("deploy_container")
  :command(function()
    -- Pull image
    docker.pull("nginx:latest")

    -- Run container
    docker.run({
      image = "nginx:latest",
      name = "web-server",
      ports = {"80:80"},
      detach = true
    })

    return true
  end)
  :build()

Available Modules

  • ๐Ÿณ docker - Container management
  • โ˜๏ธ aws, azure, gcp - Cloud providers
  • ๐Ÿ”ง systemd - Service management
  • ๐Ÿ“ฆ pkg - Package management
  • ๐Ÿ“Š metrics - Monitoring
  • ๐Ÿ” vault - Secrets management
  • ๐ŸŒ terraform - Infrastructure as Code

See all modules โ†’


๐ŸŽญ Common Workflows

CI/CD Pipeline

task("lint")
  :command("golangci-lint run")
  :build()

task("test")
  :command("go test -v ./...")
  :depends_on("lint")
  :build()

task("build")
  :command("go build -o app")
  :depends_on("test")
  :build()

task("deploy")
  :command(function()
    exec.run("docker build -t myapp .")
    exec.run("docker push myapp")
    exec.run("kubectl rollout restart deployment/myapp")
  end)
  :depends_on("build")
  :build()

Run the pipeline:

sloth-runner run -f pipeline.sloth -o rich

Infrastructure Automation

local terraform = require("terraform")

task("plan")
  :command(function()
    return terraform.plan({
      dir = "./terraform",
      var_file = "prod.tfvars"
    })
  end)
  :build()

task("apply")
  :command(function()
    return terraform.apply({
      dir = "./terraform",
      auto_approve = true
    })
  end)
  :depends_on("plan")
  :build()

๐ŸŒ Distributed Execution

Start Master Server

sloth-runner master --port 50053 --daemon

Start Agents

On different servers:

# Web server agent
sloth-runner agent start \
  --master master.example.com:50053 \
  --name web-01 \
  --tags web,nginx

# Database agent  
sloth-runner agent start \
  --master master.example.com:50053 \
  --name db-01 \
  --tags database,postgres

Distribute Tasks

task("deploy_web")
  :target_agent("web-01")
  :command("nginx -s reload")
  :build()

task("backup_db")
  :target_agent("db-01")
  :command("pg_dump mydb > backup.sql")
  :build()

๐Ÿ“Š Web Dashboard

Start the UI for visual management:

sloth-runner ui --port 8080

Access at: http://localhost:8080

Features: - ๐Ÿ“ˆ Real-time task monitoring - ๐Ÿค– Agent health dashboard - ๐Ÿ“… Scheduler management - ๐Ÿ“ฆ Stack browser - ๐Ÿ“Š Metrics and analytics


๐Ÿ”„ Scheduler

Schedule recurring tasks:

-- In your workflow
schedule("nightly_backup")
  :cron("0 2 * * *")  -- 2 AM daily
  :task("backup")
  :build()

Manage from CLI:

# Enable scheduler
sloth-runner scheduler enable

# List scheduled tasks
sloth-runner scheduler list

# Disable scheduler
sloth-runner scheduler disable

๐Ÿ’ก Tips & Best Practices

1. Use Stacks for State Management

# โœ… Good: Use stacks
sloth-runner stack new myapp
sloth-runner run myapp

# โŒ Avoid: Direct execution without state
sloth-runner run -f workflow.sloth

2. Choose the Right Output Format

# Interactive terminal
sloth-runner run -f deploy.sloth -o rich

# CI/CD pipelines
sloth-runner run -f ci.sloth -o json

# Simple scripts
sloth-runner run -f task.sloth -o basic

3. Use Values Files for Environments

# Development
sloth-runner run -f app.sloth -v dev-values.yaml

# Production
sloth-runner run -f app.sloth -v prod-values.yaml

4. Leverage Built-in Modules

-- โŒ Don't shell out unnecessarily
task("install"):command("apt-get install nginx"):build()

-- โœ… Use built-in modules
local pkg = require("pkg")
task("install"):command(function()
  return pkg.install("nginx")
end):build()

๐Ÿ“– Next Steps

Now that you're started, explore more:


๐Ÿ†˜ Getting Help


Ready to automate? Create your first workflow and start orchestrating! ๐Ÿš€


English | Portuguรชs | ไธญๆ–‡