plugins

Home

Examples

Plugins

Source

Blog

Sparrow usage examples

  • Git
  • Utils
  • CICD
  • Kubernetes
  • Azure
  • Development
  • Raku
  • Alpine

Set up Git repository

task-run "set git", "git-base", %(
  email => 'melezhik@gmail.com',
  name  => 'Alexey Melezhik',
  config_scope => 'local',
  set_credential_cache => 'on'
);

List total commits by author (sorted by commit count)
my %state = task-run "commits by authors", "git-commits-by-author";

for %state<list><> -> $i {
  say "author: ",$i<author>, 
      "commits: ", $i<commits>, 
      "email: ", $i<email>;
}

Setup nanorc file

s6 --plg-run nano-setup

Verify that disks are full on no more than 70 percents
s6 --plg-run df-check@threshold=70

Queue Azure DevOps build and wait till it finishes

my %state = task_run "run my build", "ado-pipeline-build", %(
  name => "WebApp",
  variables => "foo:1 bar:2"
  action => "run"
);

# wait till the my  build finishes
task_run "wait my build", "ado-pipeline-build", %(
  action => "wait",
  build_id => %state<build_id>
);

Run GitLab Pipeline
task-run "pipe-run", "gitlab-run-pipeline", %(
  debug => True,
  project => 1001,
  gitlab_api => "https://git.company.com/api/v4/",
  variables => %(
    color => "green",
    size => "big",
    use_salt => True
  )
)

Test if a k8s deployment exists and has attributes

task-run "dpl check", "k8s-deployment-check" %(
  name => "animals",
  namespace => "pets",
  cat => %(
    command => "/usr/bin/cat",
    args => [
      "eat", "milk", "fish" 
    ],
    env => [
      "ENABLE_LOGGING"
    ]
    volume-mounts => {
      foo-bar => "/opt/foo/bar",
    }
  )
);

Test if k8s config map exists and has entries
task-run "cm check", "k8s-config-check", %(
  type => "configmap",
  name => "web-config",
  namespace => "dashboards",
  # check if we have admin and password entries 
  # in config map
  data => [
    "note: creds for login",
    "[admin=root]",
    'regexp: "[password=" \S+ "]" $$',
  ]
);

Check that Azure KV secrets exists

task-run "check secrets", "azure-kv-secrets-check", %(
  name => "kv100", # the name of keyvault
  exists => [ # these keys should exists
    'password1',
    'password2',
    'db-password1',
    'db-password2'
  ]
)

Calculate permission number for Azure Devops permissions
task-run "permissions sum", "ado-permissions-calculator", %(
  namespace => "Library",
  actions => ["View", "Create"]
);

Lint yaml files

task-run "lint these files", "yaml-lint", %(
  files => "path/to/dir/*.yaml",
  use_python => False
);

Clean up python cache files
task-run "clean-cache", "python-helpers", %(
  task => "clean-cache",
  dir => [ "{%*ENV}/.local", '/tmp/foo/' ]
)

Install Azure cli

s6 --plg-run alpine-az-cli-install

Validate APKBUILD file
s6 --plg-run apkbuild-strict@path=community/raku-sparrow6/APKBUILD

Set up fez account

s6 --plg-run fez-login@user=melezhik,password=superSECRET123

Fetch zef distribution and return download directory
my %state = task-run 'zef fetch Kind', 'zef-fetch', %(
  identity => 'Kind'
);

say %state<directory>

Memory Usage statistics using System::Stats::MEMUsage
s6 --plg-run raku-utils-system-stats-mem-usage