Use Build pipelines

Originally published on LinkedIn on 2020-05-27.

These days I was on vacation, and I’m preparing for my new job which I will start soon. A friend of mine asked for a bit of help with their mapserver RPM packages, because they needed a special combination of mapserver7.4.4 , php7.4, postgresql12 on CentOS7 and CentOS8.

Packer, Terraform, KVM Ansible solution: Link to heading

As I worked with some hashicorp products in the past I tried to create something local on my workstation on top of KVM together with packer, terraform-cli, terraform-libvirt and ansible. Nice to play around and get in touch with mapserver and compiling it. But this is way to complicated.

KVM with Packer Terraform and Ansible workflow diagram for RPM package building

Complex KVM Packer Terraform Ansible setup diagram for RPM building

Podman Container solution: Link to heading

Yes I’m getting old, but I like to try out new stuff. So I was interessted about using podman on my fedora workstation. Wow, very easy to use, just create the Dockerfile and it worked!

Much easier, but to prepare the build environment I couldn’t use a CentOS7/8 base container. There is plenty of stuff to install inside the container as build requrements. I wouldn’t like to rebuild the image every time I trigger a build of mapserver. To solve this I created the build containers with podman on my local fedora workstation.

Podman container build process for Mapserver on Fedora workstation

Then I used this Container image for the mapserver build. So just de build itselve is trigered when the container starts.

Docker container with Mapserver build artifacts ready for deployment

Nice but not perfect.

Build Pipelines: Link to heading

gitlab Link to heading

So let’s do some GitOPS. Let’s implement this in a gitlab CI/CD pipeline. Jason Tevnan, friend of mine, worked a lot with pipielines, so I asked him for some hints. I knew that there are build pipeline features available at gitlab. And there is also a built in container registry. I uploaded the prepared containers to the container registry of the gitlab project. Then it’s not that much effort anymore to create the CI pipeline. Just a spec file and some gitlab-ci.yml magic and I could download the artifacts.

stages:
  - source
  - build
  - test
  - deploy

.build_template: &rpm_build_definition
    stage: build
    script: 
        - mkdir -p rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
        - spectool -g -C rpmbuild/SOURCES "`pwd`/redhat/mapserver-7.4.4.spec"
        - rpmbuild -D "_topdir `pwd`/rpmbuild" --clean --target x86_64 -ba "`pwd`/redhat/mapserver-7.4.4.spec"
    artifacts:
        expire_in: 1 day
        paths:
            - rpmbuild/SRPMS/mapserver-*.rpm 
            - rpmbuild/RPMS/x86_64/mapserver-*.x86_64.rpm
            - rpmbuild/RPMS/x86_64/php-*.x86_64.rpm

centos7-build:
    <<: *rpm_build_definition
    tags:
        - linux
    image: "registry.gitlab.com/treenerd/mapserver:centos7"

centos8-build:
    <<: *rpm_build_definition
    tags:
        - linux
    image: "registry.gitlab.com/treenerd/mapserver:centos8"

GitLab CI/CD pipeline configuration for building RPM packages

It’s not finished yet and plenty of stuff to improve, but it’s a starting point.

bitbucket Link to heading

I got asked, if I can do this also with bitbucket. I didn’t work with bitbucket that much but the documentation told me that it should be possible. The only thing what I missed, was the build in container registry like in gitlab. But hey let’s use the container registry of my gitlab project… After some bitbucket-pipeline.yml magic the rpm packages where build also there.

image: registry.gitlab.com/treenerd/mapserver:centos7

pipelines:
  default:
    - step:
        script:
          - echo "Everything is awesome!"
          - pwd
          - ls -lah
          - whoami
          - mkdir -p rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
          - spectool -g -C "`pwd`/rpmbuild/SOURCES" "`pwd`/redhat/php-mapserver-7.4.4.spec"
          - rpmbuild -D "_topdir `pwd`/rpmbuild" --clean --target x86_64 -ba "`pwd`/redhat/php-mapserver-7.4.4.spec"
        artifacts:
          - rpmbuild/SRPMS/mapserver-*.rpm
          - rpmbuild/RPMS/x86_64/mapserver-*.x86_64.rpm
          - rpmbuild/RPMS/x86_64/php-*.x86_64.rpm

Bitbucket Pipeline configuration using GitLab container registry

Summary Link to heading

Always be open for new solutions. There is a reason why they exist. Try them, use them and ask people, friends what they think about what you create.

Thank you for your help and also for your questions!