Skip to content

Conversation

@DanaMaxfield
Copy link
Contributor

@DanaMaxfield DanaMaxfield commented Oct 8, 2025

We recently experienced an issue where the recently updated base image was not updated by the docker build step. To try and address this, implement logic to pre-remove the base images at the same time we pre-remove the output image.

  • Update all Dockerfiles to have the base images(s) be an input variable (e.g. BASEIMAGE_BLACKDUCK_ALERT_RABBITMQ)
  • Set the corresponding variable in the build.gradle to the existing value in the Dockerfile (e.g. dockerBuildParam_BASEIMAGE_BLACKDUCK_ALERT_RABBITMQ)
  • Update ext.createDockerRemoveTask in docker.gradle to accept, and work with, a collection of image names instead of a single string
  • Before calling ext.createDockerRemoveTask, identify the Dockerfile being processed, pull all lines out that begin with FROM, and get the variable. Lookup this variable within gradle properties to be sure it exists, throw exception if not.

Build output when images exist:

> Task :dockerRemoveBlackduckAlert
Docker version 23.0.3, build 3e7cbfd
Untagged: blackducksoftware/blackduck-alert:9.0.0-SNAPSHOT
Untagged: blackducksoftware/hub-docker-common:1.0.7
Untagged: blackducksoftware/hub-docker-common@sha256:fc16140fa4a9fb927b644d18e1a4ac560254909945df108e6db96badd541e1a5
Deleted: sha256:cddb7c140bd341a475c0ee32c44af0415409bd253f3d028e8e90329b648fccdd
Untagged: alpine:3.20
Untagged: alpine@sha256:b3119ef930faabb6b7b976780c0c7a9c1aa24d0c75e9179ac10e6bc9ac080d0d
Deleted: sha256:411bc66a7adb849165d4e733707efe59d6b5edf8b4d96506cb6a1e31ba270199

> Task :dockerRemoveBlackduckAlertDb
Docker version 23.0.3, build 3e7cbfd
Untagged: blackducksoftware/blackduck-alert-db:9.0.0-SNAPSHOT
Untagged: postgres:15.8-alpine
Untagged: postgres@sha256:8b963ea3038c3b32182ee7f592ccde21242fa7c5fd9d1b72aa333c27f1bfc809
Deleted: sha256:0b42deb40e1694f2595be402b1c3d9f0ab132aef0912f0904d1f3efc94edc9e1
Deleted: sha256:1eeda1481da338549e7da6dc0dc1ec863477028c28b6db0018e63c87dd771528
Deleted: sha256:128b79455538b76c4731b7ce8c72608556f07b017554c628f0a16ff663c6ca61
Deleted: sha256:c4154e88f1b1dafeed44c57071e0fe4d1a3e5fbaeb30019a267e25a697e910cc
Deleted: sha256:b117b814d8418101be44b93fa8102b0792ba53498780b34efa0d5e3d2463aac4
Deleted: sha256:85934ca5a2c11a78e6ff13caa4655c5a9da25a3454a65f656ae0c1e1882f65a0
Deleted: sha256:6ddb94f14b0a139493719175a117f2246051a024c817f00764e8aba2d36601b1
Deleted: sha256:6a018ce1bc342c2141c660b04065612a37965d1c5fc826718fead7e3308b166b
Deleted: sha256:75c7f742aad54d65e7aa936cccddc377b056e36ec93a407a791b4f5c1a41a6a4
Deleted: sha256:ceeaf237656ef6908d3fb764efbe4e9f58b5159567fff0391ec6d1c152cbccba
Deleted: sha256:e58295e8f1290b531d3cd4751e9f75202c6b1237d88cdfaa74e16bd2e0b96d2e
Deleted: sha256:75654b8eeebd3beae97271a102f57cdeb794cc91e442648544963a7e951e9558
Untagged: postgres:16.9-alpine
Untagged: postgres@sha256:7c688148e5e156d0e86df7ba8ae5a05a2386aaec1e2ad8e6d11bdf10504b1fb7
Deleted: sha256:dca9c7aa70c71caf8bcc48c8ec40658c1fdf2d1e4e8d26bc27d4d18e030d779a

> Task :dockerRemoveBlackduckAlertRabbitmq
Docker version 23.0.3, build 3e7cbfd
Untagged: blackducksoftware/blackduck-alert-rabbitmq:9.0.0-SNAPSHOT
Untagged: rabbitmq:3.13-alpine
Untagged: rabbitmq@sha256:4fbeedeb89c101b5175bd22bfb6417175ca28e7ae62d9ca44977e22b2ac70563
Deleted: sha256:f9195de9da5fcb7de4b543fe6089e0fa13bbf3a0e713955e23e2ed162b86dbdc
One or more images did not need to be removed, continuing.

Build output when images DO NOT exist:

> Task :dockerRemoveBlackduckAlert
Docker version 23.0.3, build 3e7cbfd
One or more images did not need to be removed, continuing.

> Task :dockerRemoveBlackduckAlertDb
Docker version 23.0.3, build 3e7cbfd
One or more images did not need to be removed, continuing.

> Task :dockerRemoveBlackduckAlertRabbitmq
Docker version 23.0.3, build 3e7cbfd
One or more images did not need to be removed, continuing.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a solution to ensure base Docker images are removed before building, preventing issues where recently updated base images were not being pulled during builds.

  • Parameterized all Dockerfiles to use ARG variables for base images instead of hardcoded values
  • Enhanced the docker remove task to handle multiple images and automatically identify base images from Dockerfiles
  • Added validation to ensure required Gradle properties exist for base image variables

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

File Description
docker/blackduck-alert/Dockerfile Added ARG variables for base images and updated FROM statements to use them
docker/blackduck-alert-rabbitmq/Dockerfile Added ARG variables for base images and updated FROM statements to use them
docker/blackduck-alert-db/Dockerfile Renamed existing ARG variables to follow consistent naming convention
buildSrc/docker.gradle Enhanced createDockerRemoveTask to handle multiple images and added logic to parse Dockerfiles for base image extraction

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants