DEV Community

Alexey Melezhik
Alexey Melezhik

Posted on

Sparky - Self-hosted Task Runner with Easily Customizable UI

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

mkdir -p ~/.sparky/projects/build-rakudo/
Enter fullscreen mode Exit fullscreen mode

nano ~/.sparky/projects/build-rakudo/sparky.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
Enter fullscreen mode Exit fullscreen mode

nano ~/.sparky/projects/build-rakudo/sparrowfile

#!raku
task-run "files/build-rakudo", %(
  rakudo_version => tags()<version>,
  arch => tags()<arch>,
);
Enter fullscreen mode Exit fullscreen mode

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

mkdir -p ~/.sparky/projects/build-rakudo/files/build/
Enter fullscreen mode Exit fullscreen mode

nano ~/.sparky/projects/build-rakudo/files/build/task.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)
Enter fullscreen mode Exit fullscreen mode

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

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

Top comments (0)