Been awhile since I made a new post, been rather busy as of late. Anyways, I took a moment to see how easy and convenient it is to run both an FPC compile and execution into a
Docker container. I am very happy to say, that a simple console program was able to effortlessly compile inside a Docker container, and I was able to generate a new container using alpine as the base to create what is an extremely small image of just 5.7MB! This means that FreePascal programs seem to work fine with the limited library support of a base alpine install. Currently, one of the more popular Docker container languages for compiled code is
GoLang, if one wants to generate tiny, efficient, and super scalable containers in a production environment. I will provide below a working Dockerfile which will generate a container which will allow one to compile FreePascal programs using the latest compiler, and another Dockerfile to display how easy it is to containerize a simple FreePascal program. It would be really awesome to see native Docker image creation right from the Lazarus IDE.
FROM debian:stretch
RUN apt-get update && apt-get install -y build-essential
ADD fpc-3.0.4.x86_64-linux /tmp/fpc-install
RUN cd /tmp/fpc-install && sh install.sh && cd / && rm -rf /tmp/fpc-install
Build the above using
docker build -t fpc:3.0.4 .
To use this Dockerfile, I did need to modify the
install.sh to support an unintended installation. I also removed doc-pdf and demos, as that isn't needed during a build pipeline. I am planning on expanding on this to add Lazarus building support using
lazbuild. I also use Debian Stretch as the building environment due to it's extensive library and overall development support.
Here's a Dockerfile to show how this can be used to build a docker image with a compiled final product bound for a production server in the cloud.
FROM fpc:3.0.4 AS builder
ADD hello.pas /root
RUN cd /root && fpc hello.pas
FROM alpine:latest
COPY --from=builder /root/hello /root/hello
ENTRYPOINT ["/root/hello"]
I am planning on pushing up the fpc:3.0.4 docker image, and later on, a docker image capable of building Lazarus programs.
Docker is also a nice alternative to cross-compiling on the same arch. I am planning on also releasing docker images such as this which will allow one to effortlessly cross-compile to a Raspberry Pi using the same method shown above.
https://ownyourbits.com/2018/06/27/running-and-building-arm-docker-containers-in-x86/