Backing Your Own CI in 5 minutes by using Sparrowdo, Sparky and Docker

Alexey Melezhik - Dec 4 '17 - - Dev Community

What I often need is to test my code against different environments. In this small post I am going to show how one can build hosted solution to test your source code in running Docker container by using Sparrowdo and Sparky.

Imperative deployment scenarios written on Perl6, nice web UI and asynchronous task execution is what you'll get for free!

Part1 / Spinning up a docker container

This step is trivial, as we pull desired docker image and run it as a container:

$ git pull docker pull base/archlinux
$ docker run -itd base/archlinux sh

Enter fullscreen mode Exit fullscreen mode

So as we might guess I want to test my code against Arch Linux server. The same pattern is applied if you need to test against different environments, just change the docker image.

Part2 / Here is my code

Say, I keep my source code somewhere in GitHub repository - https://github.com/melezhik/hello-world/blob/master/hello.bash - and for example purpose it is as simple as "hello world" Bash script:

#!bash
echo "Hello World!"
Enter fullscreen mode Exit fullscreen mode

Of course real life application are much more sophisticated, however this does not limit our approach.

Part 3 / Deployment scenario

I am going to use Sparrowdo to deploy an application code, so as the code is quite trivial this one should be as simple as fetching a source code from GitHub and running the "main" script:

#!perl6
git-scm "https://github.com/melezhik/hello-world.git";
bash "bash ./hello.bash";

Enter fullscreen mode Exit fullscreen mode

Part4 / Sparky project

Let's create a Sparky project to deploy mentioned Sparrowdo scenario on the running docker container. Sparky profile sparky.yaml would be:


crontab: "*/10 * * * *"
sparrowdo:
  docker: elastic_sinoussi
  no_sudo: true
Enter fullscreen mode Exit fullscreen mode

Here we ask Sparky to run our deployment scenario every 10 minutes on the running docker container named elastic_sinoussi ( the name of the container could be given by command docker ps).

So the final structure of our Sparky project would be:

$ tree hello-world/
hello-world/
├── sparky.yaml
└── sparrowfile
Enter fullscreen mode Exit fullscreen mode

Where sparrowfile file contains a Sparrow deployment scenario and sparky.yaml does a Sparky settings ( like scheduler parameters, docker instance name and so on ).

Part5 / Sparky Web UI

It will take for awhile to build a project by Sparky, meanwhile we can observer the project builds by visiting nice Sparky web UI, following is couple of screen shots:

  • Recent builds page: sparky1.png

  • And a certain build details:

sparky2.png

And finally we might notice that the project gets built successfully:

running sparrow tasks on 127.0.0.1 ... 
target OS is - archlinux
push [task] fetch from git source: https://github.com/melezhik ... OK
push [task] run bash: bash ./hello.bash ... OK
SPL file /opt/sparky-sparrowdo/hello-world/sparrow.list is empty
get index updates from SparrowHub ... OK
set up task box file - /home/melezhik/.sparrowdo//opt/sparky-sparrowdo/hello-world/task-box.json - OK
public@bash is uptodate (0.1.7)
running task box from /opt/sparky-sparrowdo/hello-world/sparrow-cache/task-box.json ... 
2017-12-04 14:13:34 : [task] fetch from git source: https://github.com/melezhik ... [path] modules/bash-command/ [params] envvars:
2017-12-04 14:13:35 : [task] run bash: bash ./hello.bash ... [path] modules/bash-command/ [params] envvars:
Enter fullscreen mode Exit fullscreen mode

Conclusion

Sparky is a lightweight CI server built upon Sparrowdo framework. In just a few moments in enables integration tests under various environments working smoothly with Docker containers or ssh accessed hosts.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player