Sparky - Self-hosted Task Runner with Easily Customizable UI
Tags: ci, rakulang, automation
Published: 2024-01-02 14:25:42

---
title: Sparky - Self-hosted Task Runner with Easily Customizable UI 
published: true
description: How to use Sparky to automate internal tasks 
tags: CI, RakuLang, Automation
# cover_image: https://github.com/melezhik/sparky/blob/master/logos/sparky.small.png?raw=true
# Use a ratio of 100:42 for best results.
# published_at: 2024-01-02 11:47 +0000
---

Sparky is a task-runner allow teams to automate their daily tasks by creating #Rakulang scenarios and customizable UI

```bash
mkdir -p ~/.sparky/projects/build-rakudo/
```

`nano ~/.sparky/projects/build-rakudo/sparky.yaml`

```yaml
sparrowdo:
  no_sudo: true
  no_index_update: true
  bootstrap: false
  format: default
allow_manual_run: true
vars:
  -
      name: version
      default: "2023.12"
      type: input
  -
      name: arch
      values: [ alpine, debian, ubuntu ]
      type: select
      default: alpine
```

`nano ~/.sparky/projects/build-rakudo/sparrowfile`
```perl
#!raku
task-run "files/build-rakudo", %(
  rakudo_version => tags()<version>,
  arch => tags()<arch>,
);
```

In this imaginary scenario we want to build a Rakudo docker image for a specific Rakudo version and Linux distribution:

```bash
mkdir -p ~/.sparky/projects/build-rakudo/files/build/
```

`nano ~/.sparky/projects/build-rakudo/files/build/task.bash`

```bash

cat << HERE > $cache_root_dir/install-rakudo.sh
mkdir ~/rakudo && cd $_
curl -LJO https://rakudo.org/dl/rakudo/rakudo-$1.tar.gz
tar -xvzf rakudo-*.tar.gz
cd rakudo-*
perl Configure.pl --backend=moar --gen-moar
make
make install
HERE

if test $(config arch) == "alpine"; then
cat << HERE > $cache_root_dir/Dockerfile
FROM alpine:latest
ARG rakudo_version=2023.12
RUN apk update && apk add git make gcc musl-dev
RUN adduser -D -h /home/worker -s /bin/bash -G wheel worker
USER worker
ENV PATH="/home/worker/rakudo-$rakudo_version/install/bin:/home/worker/rakudo-$rakudo_version/install/share/perl6/vendor/bin:/home/worker/rakudo-$rakudo_version/install/share/perl6/core/bin:/home/worker/rakudo-$rakudo_version/install/share/perl6/site/bin:/home/worker/.raku/bin:${PATH}"
COPY install-rakudo.sh . 
RUN sh ./install-rakudo.sh $rakudo_version
HERE
elif test $(config arch) == "debian"; then
cat << HERE > $cache_root_dir/Dockerfile
FROM debian:latest
ARG rakudo_version=2023.12
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update -q -o Dpkg::Use-Pty=0
RUN apt-get install -q -y -o Dpkg::Use-Pty=0 build-essential curl git
RUN useradd -m  -d /home/worker --shell /bin/bash worker
USER worker
ENV PATH="/home/worker/rakudo-$rakudo_version/install/bin:/home/worker/rakudo-$rakudo_version/install/share/perl6/vendor/bin:/home/worker/rakudo-$rakudo_version/install/share/perl6/core/bin:/home/worker/rakudo-$rakudo_version/install/share/perl6/site/bin:/home/worker/.raku/bin:${PATH}"
COPY install-rakudo.sh . 
RUN sh ./install-rakudo.sh $rakudo_version
HERE
elif test $(config arch) == "ubuntu"; then
cat << HERE > $cache_root_dir/Dockerfile
FROM ubuntu:latest
ARG rakudo_version=2023.12
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update -q -o Dpkg::Use-Pty=0
RUN apt-get install -q -y -o Dpkg::Use-Pty=0 build-essential curl git
RUN useradd -m  -d /home/worker --shell /bin/bash worker
USER worker
ENV PATH="/home/worker/rakudo-$rakudo_version/install/bin:/home/worker/rakudo-$rakudo_version/install/share/perl6/vendor/bin:/home/worker/rakudo-$rakudo_version/install/share/perl6/core/bin:/home/worker/rakudo-$rakudo_version/install/share/perl6/site/bin:/home/worker/.raku/bin:${PATH}"
COPY install-rakudo.sh . 
RUN sh ./install-rakudo.sh $rakudo_version
HERE
else
echo "$(config arch) is not supported"
exit 1
fi

docker build $cache_root_dir/ \
-f $cache_root_dir/Dockerfile \
--build-arg rakudo_version=$(config rakudo_version) \
-t team/rakudo:$(config arch)-$(config version)

docker push team/rakudo:$(config arch)-$(config version)
```

Once we've created all necessary files we can navigate to a "build-rakudo" project in Sparky UI and hit "build now" button:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pdd5nkaqmjhdvmi7gjn7.jpeg)

By choosing a Rakudo version and Linux distribution and launching a new build, within a few minutes we get a new Rakudo docker image published to an internal docker registry.

---

This is just a _simple_ example of how one can use Sparky for automation, there is more then that, but the main idea is to spin up jobs quickly with simple web interfaces generated from YAML specifications, resulting in various kinds of centralized tools available for needs of your team. 

For the scaling it's even possible to convert scenarios into plain Raku modules or Sparrow plugins and distribute them across many teams.

---

Conclusion

Sparky is versatile task runner enable small teams of developers of self-hosted platform to automate all boring and manual stuff they might have during development cycle, check it out for more details - https://raku.land/zef:melezhik/Sparky