Home >> Blog – EN >> Automated Dependency Management

Automated Dependency Management

08 August 2024

Par Maxime Ancellin.

Introduction

Today, I have the opportunity to make my first blog post!

Our topic of the day will be automated dependency management and its use cases.

It is true that use cases are the most interesting aspect to explore when discussing a tool or technology.

We all know several tools that assist us in our daily activities.
However, we don’t all have the same needs, and this is where experience comes into play to determine what suits us best.

This post is therefore based on personal experience and has been formatted to fit a blog entry.

Objectives of this publication

Through this topic, we aim to answer the following questions:

  • How can we address the challenges of updating tools?
  • How can we test these updates to ensure they do not break our code, container, etc.?
  • How can we solve the above issues through an automated approach?

If you have these questions, you’re in the right place!

Dependency Management

Before we begin, what do we mean by a dependency?

In our technical professions, we work with numerous concepts and tools.

In a project, one could recode all the elements necessary for its proper functioning, but this would be tedious and very difficult to maintain over time (a lot of code and knowledge to manage).

To address this, we use a set of resources shared by companies or the community that we can include/utilize in our projects.

This is what we call dependencies.

Popular Dependency Managers and Dependencies

Most modern languages/technologies use dependency managers to orchestrate different resources and their versions.

We can easily list:

  • NPM/Yarn: NodeJS
  • Maven: Java
  • PIP: Python
  • APT: Debian (and distributions based on it)
  • Homebrew: MacOS

Regarding dependencies, there are countless examples.
Here are some particularly popular packages:

  • AWS SDK
  • MongoDB
  • Keycloak
  • The solutions mentioned above are closely related to the development environment.

With the DevOps methodology, the world of infrastructure is becoming increasingly aligned.

Solutions that allow for deploying infrastructure “As Code” use the same principles.

This is the case with:

  • Terraform with modules
  • Ansible with roles
  • CI/CD when using a versioned pipeline library
  • Or even Kubernetes, which manages all these resources in the form of versioned APIs.

Here is a small illustration that diagrams how this works within the context of an application project.

The Problem

Dependencies offer numerous advantages and significantly simplify our work.
However, they also create a real challenge in keeping packages updated and fixing security vulnerabilities.

We can use tools (npm, pip, etc.) to update them, but this involves a manual process.
In an environment with numerous Git projects and microservices, this represents a lot of work to keep everything up to date.

This is where our topic begins.

To address this issue, there are tools that can do this work for you.
Many solutions are available on the market, but we will focus on the two main ones here.

DependaBot VS Renovate

These are the two solutions widely adopted by the community.

Indeed, they allow for quick installation and do not necessarily require configuration.

DependaBot

This tool is specifically designed for use with GitHub, in a SaaS (Software as a Service) mode.

With this direct integration with GitHub, DependaBot offers a turnkey solution for dependency management, optimizing workflow, enhancing efficiency, and improving security.

The strength of DependaBot lies in its simplicity and very quick integration with your GitHub projects.

Renovate

Just like DependaBot, it is designed to be used in SaaS mode on GitHub (for the Mend.io version).

There is also an Open Source version that allows you to self-host Renovate via a container in a CI/CD pipeline, on a container orchestrator, or install it on a machine via NPM.

This provides better privacy and finer control over credential management.

Strengths of Renovate:

  • Multi-platform Git
  • Can be hosted in ways other than SaaS

However, it can be more complex to configure but offers greater freedom.

As you might have guessed, Renovate is the tool I recommend to address our problem.
Its great flexibility, the ability to self-host, and having the OpenSource code are clearly advantages.

It works like bellow:

Why Do It?

As mentioned earlier, the time spent on manual package management is not time that can be used for value-added tasks.

However, we are compelled to perform these tasks for reasons of Security or Technical Debt, or we can choose to ignore them (Obviously, I do not recommend this; obfuscation is never the right solution).

Security

From a security standpoint, this allows us to continuously track updates. Therefore, we can even instruct Renovate to automatically merge new patches to ensure that fixes are applied promptly.

Caution, this can potentially cause issues if the updates to your dependencies are unreliable.

Technical Debt

Now that we no longer need to manually update packages on each project, we can focus on code production.

Furthermore, with a robust CI/CD pipeline, we can also ensure that updates do not introduce regressions.

This means that technical debt related to packages should no longer accumulate and may even be reduced over time.

Caution, during implementation, there may be a significant number of generated pull requests.
It’s important to manage this workload or gradually activate Renovate’s levels/features.

Integration

If you want to integrate Renovate (or DependaBot for GitHub) into your projects, you can find the steps to follow at the links below:

Configuration

Now that your Renovate Bot is set up on your Git instance,
we will see how to configure it for standard use cases.

You may have noticed that after integrating the tool, a Pull Request was made on all your Git repositories to add a renovate.json file that includes the configuration to apply to your repo.

Default

The file created by Renovate is the basic configuration.
You can find information about it on the presets page of their GitHub.

Here is the translated text in American professional English:


Customization

As I mentioned earlier, it is not always easy to handle all the “Pull Requests” that will be proposed by Renovate during its setup.
Therefore, we have the option to enable only the features we want.

For example, below we enable only the handling of Dockerfile

{
  "enabledManagers": [
    "dockerfile"
  ]
}

The list of available managers can be found in the documentation.

You can also add a number of automations, such as assigning people for reviews or automatically merging certain updates.

Here is an example of an extended configuration:

{
    "packageRules": [
        {
            "matchManagers": ["github-actions"],
            "commitMessageTopic": "Chore(ci): {{depName}} update",
            "automerge": true,
            "automergeType": "pr-comment",
            "automergeComment": "LGTM!"
    }
  ]
}

Above, we define a specific configuration for “Pull Requests” related to “GitHub Actions”.

We have defined the following elements:

  • Targeting the manager: github-actions
  • The commit message will be: Chore(ci): {{depName}} update
  • The Pull Request will be automatically merged under the following conditions:
    • A comment on the Pull Request
    • The comment must be: LGTM!

You can find all Renovate configurations in the official documentation.

Sharing Configurations

Obviously, we don’t want to set up our configuration for all our Git projects individually.
This would bring us back to the situation where it becomes complicated to manage all dependencies across all Git projects.

For this, we can create a set of shared configurations in a Git project (similar to those provided by Renovate).
This allows us to use a single configuration from other projects and thus work on just one file for all our projects.

We can then use the following configuration (in the case where we are on GitLab):

{
  "extends": [
    "gitlab>MyOrganization/my-awesome-project/renovate-bot//configurations/configuration-file-without-extension"
  ]
}

You can find other configurations in the config-presets section of the documentation.

What’s Next

In the next article, we will see how to use Renovate in a GitOps workflow and automate staging/production deployments.

Leave a Reply

  Edit this page