DB images for unit testing, again

In the previous article, an option was proposed for creating Docker images of a database for subsequent use in developing and testing applications in GitLab pipelines.

Due to the transition to the new infrastructure k8s 1.30 (restricted psp) and the new gitlab 17.3, all this breaks. So we'll have to fix the situation!

Why buildah will have to be abandoned

You need to collect from user build but for some reason in the new gitlab-runner everything will end with the error remount / failed. It turned out to be unrealistic to fix this, it is impossible to issue privileged rights. Considering that the created image for the DB is simple – no complex operations need to be performed, it is easier to throw out the dependency and look for another solution.

Jib core

Chances are your team is already using a maven or gradle plugin called jib to containerize java applications. This plugin is so full of knowledge of the universe that it provides your API for writing your own plugins.

To generate you only need to create simple task for gradle:

        getLogger().info("Generating image {} from {}", getTargetImageName().get(), getBaseImage().get());
        var image = Jib.from(getBaseImage().get())
                .addLayer(getSqlFiles().get(), AbsoluteUnixPath.get("/docker-entrypoint-initdb.d/"))
                .containerize(Containerizer.to(RegistryImage.named(getTargetImageName().get())
                        .addCredential(getRegistryUsername().get(), getRegistryPassword().get())))
                .getTargetImage();

        if (Boolean.TRUE.equals(getTargetImageIsLatest().get())) {
            Jib.from(image)
                    .containerize(Containerizer.to(RegistryImage.named(replaceWithLatestVersion(getTargetImageName().get()))
                            .addCredential(getRegistryUsername().get(), getRegistryPassword().get())));
        }

And since in the project mireapay liquibase is used, then all the configuration functionality was brought out in plugin for gradle.

Now, to use everything you need, you only need to complete 3 points:

  1. Create a changelog.xml file in the root of the project;

  2. Add .gitlab-ci.yml:

include:
  - project: 'mireapay/devops/pipeline'
    ref: 'v1.1'
    file:
      - 'gradle/liquibase/validate/default.yaml'
      - 'gradle/liquibase/image/default.yaml'
      - 'gradle/liquibase/release/default.yaml'
      - 'gradle/liquibase/deploy/local-dev/clearing.yaml'

stages:
  - validate
  - release
  - image
  - deploy
  1. Configure the plugin for Gradle:

plugins {
    id 'com.lastrix.mps.database.liquibase' version "0.0.9"
}

group 'com.lastrix.mps.clearing.core'

databaseLiquibase {
    defaultSchema = System.getProperty('db.schema') ?: "clearing_core"
}

Example of use here.

Pipelines can be find here . I recommend collecting agent First, for your project you will need to replace gitlab.local in the files with your host.

For employers

Employer, hurry up and get yourself a Java cat for your team! He doesn't catch mice, but he writes Java code and does a little bit of designing.

https://hh.ru/resume/b33504daff020c31070039ed1f77794a774336

And don't forget:

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *