In this episode I talk about developing web application based on well known cro framework and specifically how to create CI pipeline using DSCI tool.
Here is example of very simple cro application (taken from cro web site):
use Cro::HTTP::Router;
use Cro::HTTP::Server;
my $application = route {
get -> {
content 'text/html', 'Hello Cro!';
}
}
my Cro::Service $service = Cro::HTTP::Server.new:
:host<localhost>, :port<10000>, :$application;
$service.start;
react whenever signal(SIGINT) {
$service.stop;
exit;
}
Enter fullscreen mode Exit fullscreen mode
First of all let's create jobs file .dsci/jobs.yaml that would contain list of jobs, in our case this is just a single job:
jobs:
-
id: ci
path: .
Enter fullscreen mode Exit fullscreen mode
In this case we would have just a single job that:
- installs apps dependencies
- runs web application in background
- runs some end to end tests using http client
.dsci/job.raku
run_task "install";
run_task "end-to-end";
Enter fullscreen mode Exit fullscreen mode
.dsci/tasks/install/task.bash
set -e
cd ../
ls -l
zef install . --deps-only
zef install .
echo "done"
nohup cro run 1>app.log 2>&1 & </dev/null
Enter fullscreen mode Exit fullscreen mode
The first task just installs application dependencies and runs web application in background, now we can create some end to end test. For simplicity I am going to use curl http client here, but feel free choose any languages you like, for example Raku's HTTP::Tiny client, DSCI is super flexible allowing to write tasks on different languages mixing then effectively.
.dsci/tasks/end-to-end/task.bash
I could have made this simple one line Bash task a part of initial install task, but for claritrty and demonstration of modularity I keep as a separate one. In the future more tests may come (rathe then this trivial one) and it reasonable separate installation and testing logic.
set -e
# the test should fail if HTTP response is not
# successful
curl 127.0.0.1 127.0.0.1:10000 -f -L
Enter fullscreen mode Exit fullscreen mode
Ok, let's try this out. And the very first run results in ... error:
08:47:39 :: ===> Building: Digest::SHA1::Native:ver<1.0.1>:auth<zef:bduggan>
08:47:39 :: [Digest::SHA1::Native] /bin/sh: make: not found
Enter fullscreen mode Exit fullscreen mode
Which means we need to install make on our alpine worker, let's joust add this line to .dsci/tasks/install/task.bash
apk add --no-cache make
Enter fullscreen mode Exit fullscreen mode
And run again ... And bump into similar error:
[Digest::SHA1::Native] make: cc: No such file or directory
Enter fullscreen mode Exit fullscreen mode
So, we just this to .dsci/tasks/install/task.bash
apk add --no-cache make build-base
Enter fullscreen mode Exit fullscreen mode
To fix the issue of vanilla Alpine not having cc preinstalled.
Ok. After making few others tweaks the pipeline finally passes, bits I've missed:
- adding .cro.yml
- running cro full path
/usr/share/rakudo/site/bin/cro
Here is the final ci code and it works!
12:13:02 :: 1 bin/ script [cro] installed to:
12:13:02 :: /usr/share/rakudo/site/bin
12:13:02 :: done
12:13:07 :: ▶ Starting Raku Cro Demo (hello)
[task run: task.bash - .]
[task stdout]
12:13:22 :: HTTP/1.1 200 OK
12:13:22 ::
12:13:22 :: Content-type: text/html; charset=utf-8
12:13:22 :: Content-length: 10
12:13:22 ::
12:13:22 :: Hello Cro!
Enter fullscreen mode Exit fullscreen mode
That's it for today. Thanks for reading and stay tuned for other episodes.
0 Comments
Log in to join the conversation.No comments yet. Be the first to share your thoughts.