DEV Community

atymic
atymic

Posted on

Serverless Cobol

I'm currently in the process of writing a post covering how to run Laravel Serverless on Google Cloud. There I was, sitting there hashing out the post and I wrote this:

This pretty much means you can run anything that responds to HTTP request, hell you could even run Cobol if you wanted!

Well, I can't really claim that without actually trying it, can I? Well, an hour or so later and were running serverless cobol!

https://serverless-cobol-max7gzuovq-uc.a.run.app/cobol+dev.to=%3C3

It was actually surprisingly easy to build a docker container to run cobol, despite it being a 60+ year old language. There's a modern re-implementation called GnuCobol which support modern OSes like Ubuntu.

Here's the dockerfile which compiles the cobol source code & sets up apache (which interfaces with the cobol program as a CGI script).

FROM ubuntu:bionic

RUN apt-get update
RUN apt-get install software-properties-common -y
RUN add-apt-repository ppa:lud-janvier/gnucobol
RUN apt-get update
RUN apt-get install gnucobol apache2 -y

COPY . /var/www/public
WORKDIR /var/www/public

RUN cobc -x -free serverless.cbl -o the.app
RUN chmod +x ./the.app

COPY docker/apache.conf /etc/apache2/sites-available/000-default.conf

EXPOSE 8080


RUN echo "Listen 8080" >> /etc/apache2/ports.conf && \
    chown -R www-data:www-data /var/www/ && \
    a2enmod rewrite && \
    a2enmod cgid

CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]

Building the container & getting the cobol code to run was the hard part, deploying to Cloud Run is incredibly easy - two command and a few minutes later and we're running cobol in the cloud!

Is it useful? Definitely not. Was in fun? Sure was 🙃

Source code on Github.
Now to do some actual work 😬

Top comments (1)

Collapse
 
1e4_ profile image
Ian

When you don't stop to think if something should be done. Great post, most unexpected haha