Using Digital Ocean App service to run a Perl Mojolicious docker app

lancew

Lance Wicks

Posted on November 22, 2021

Using Digital Ocean App service to run a Perl Mojolicious docker app

Recently I needed to renovate an old web project; RSS aggregator site written in PHP in early 2000s which after not being maintained for about a decade had finally died.

It is now a new Perl Mojolicious website, moved from the cPanel hosting onto Digital Ocean's docker "App" service. In this post I'd like to share some of the learnings and experiences of moving the app to Digital Ocean's service.

I am not going to cover in this tale/post the code side of the Mojo app, just the infrastructure side. Mainly because I have been really impressed with the ease and usefulness of the Digital Ocean service.

Please note, I am NOT sponsored, or paid by Digital Ocean. This is just a service I have used and enjoyed.

Overview

I write changes in git | -> Push to GitHub | -> Digital Ocean picks up the git change | -> Digital Ocean builds the docker image | -> Digital Ocean runs the image (including HTTP).

More detailed explanation:

I used the basic Docker file that Mojo generates, with a couple of small modifications:

FROM perl
WORKDIR /opt/mojo-planetjudo
COPY . .
# XML::LibXML needs to be there before we
# try to install SimpleObject, Parser.
# TODO: See if parser needed here
# TODO: See why cpanm does not sort this out
RUN cpanm install -n XML::LibXML
RUN cpanm install -n XML::Parser
RUN cpanm install -n XML::SimpleObject
RUN cpanm --installdeps -n .
EXPOSE 3000
CMD ./script/planetjudo prefork

Enter fullscreen mode Exit fullscreen mode

You can see that it's pretty basic. The only oddity is that I install a couple of modules before installing the rest via a cpanfile. That's just because they were not installing nicely for some reason. ;-)

The other thing I do is have a .dockerignore file, it only has two entries:


.git
local

Enter fullscreen mode Exit fullscreen mode

This prevents Docker copying in the .git and local directories. .git is pretty self explanatory you don't need it. local is where cpanm has installed my Perl modules and that can cause an issue I struck when it tried to build modules and failed.

And that's about it!

Developer Workflow

The really nice thing with this setup is that my entire workflow consists of git add, commit, push.

After that Digital Ocean takes care of everything, the build/deploy is all done for me. It is currently a bit slower than I'd like (mainly cpanm, so cpm might be faster). But I love that I don't need to think about anything.

Niceties

Digital Ocean's app service takes care of not only the build, deploy and hosting of the app. It also provides console logs, graphs of things like memory and CPU usage and even a terminal I can use to interact with the app.

Cost

The smallest instance you can run is $5usd per month, which is equivalent to their smallest "droplet" (virtual machine). If, like me it's a low traffic, resources light, site; then it's a great price to pay for a simple, reliable solution.

Summary

Digital Ocean's app service is great for a Perl web developer. With virtually no effort we can get a Perl Mojolicious dockerised application up and running. No need to worry about pipelines or even SSL, it's all just taken care of for you. It does put you firmly in the "vendor lock-in" situation; but it's a pleasant trap to be in. We as Perl developers get to host our applications on a new service.

As a developer who works in Perl (as well as other languages), it's great to have tried this and felt it work really smoothly. It's sometimes not the case; sometimes you try a new approach or tool and Perl is not practical on it.

The only build and deploy step I need to make is git push which is phenomenal. I didn't have to worry about LetsEncrypt or anything like that. Everything "just worked".

Give it a try fellow Perl devs, it's nice.

💖 💪 🙅 🚩
lancew
Lance Wicks

Posted on November 22, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

What was your win this week?
weeklyretro What was your win this week?

November 29, 2024

Where GitOps Meets ClickOps
devops Where GitOps Meets ClickOps

November 29, 2024

How to Use KitOps with MLflow
beginners How to Use KitOps with MLflow

November 29, 2024