• +43 660 1453541
  • contact@germaniumhq.com

Dealing With Legacy Code


Dealing With Legacy Code

In the next miniseries of articles we’re going to deal maintaining Legacy Code. We’ll go with how to absorb faster bigger portions of code, how to reason larger codebases, and general day to day life. Since there’s no one size that fits all, your mileage will vary.

Let’s start with the basics.

CI/CD

If the code you got your hands on is working, before doing anything else make sure that you have it versioned, and that you have a CI/CD system around it. My personal preference is Jenkins+Docker, but that won’t scale if you have a lot of projects, builds, or a lot of platforms.

The key learning is that the build system must be versioned with the code itself. Be it a simple shell script, bake it in the source tree. You’ll always need it, and it’s your single source of truth on how to get from the sources to the actual binary.

A simple approach in Jenkins is to have the build composed out of three phases:

stage('build images') {
    node {
        deleteDir()
        checkout scm

        docker.build('my-build-image') // (1)
    }
}

stage('run build') {
    node {
        // (2)
        docker.inside('my-build-image') {
            sh """
                ...
            """

            // (3)
            archiveArtifacts artifacts: '/src/dist/main.exe', fingerprint: true
        }
    }
}
  1. The first phase prepares all the tooling that’s necessary for the build,

  2. then the build is attempted,

  3. and if all is well, the artifacts are copied.

The last part can also mean publishing docker images, or packages to pypi and is highly dependent on the actual software that gets built.

Having this gives us a way to guarantee code changes are immediately built, so we are able to validate those changes.