Skip to content

Conversation

@fopina
Copy link
Contributor

@fopina fopina commented Sep 18, 2025

Description

I've often used deploy.replicas: 0 in compose override files to "disable" some of the services. Yet, that just prevents them from starting, they're still built.

Recently, I've seen "unused profile" being used for the same purpose, with the added benefit that this way services images are not built either.

This PR applies that to the unit test compose overrides.

Test results

docker compose build --no-cache (with unit_test override set) takes around 120/140 seconds in current file. In this branch, it takes 100/110 seconds (and doesn't start unused services either).

Checklist

This checklist is for your information.

  • Make sure to rebase your PR against the very latest dev.
  • Features/Changes should be submitted against the dev.
  • Bugfixes should be submitted against the bugfix branch.
  • Give a meaningful name to your PR, as it may end up being used in the release notes.
  • Your code is flake8 compliant.
  • Your code is python 3.11 compliant.
  • If this is a new feature and not a bug fix, you've included the proper documentation in the docs at https://github.com/DefectDojo/django-DefectDojo/tree/dev/docs as part of this PR.
  • Model changes must include the necessary migrations in the dojo/db_migrations folder.
  • Add applicable tests to the unit tests.
  • Add the proper label to categorize your PR.

@valentijnscholten
Copy link
Member

Can you rebase/merge?

Is this "not used" profile something built in to docker compose? Can't seem to find anything about it? Or is the idea that if you do not specify a profile, any service with a profile will not be built/started?

@fopina fopina force-pushed the compose/no_useless_unittest_builds branch from 87d0846 to 913e05f Compare September 19, 2025 20:19
@fopina
Copy link
Contributor Author

fopina commented Sep 19, 2025

Or is the idea that if you do not specify a profile, any service with a profile will not be built/started?

This one!
But "if you do not specify one of those profiles, service will not be built/started", just to include the case "if you specify a profile but it does not match"

@fopina
Copy link
Contributor Author

fopina commented Sep 19, 2025

Actually just tried initializer: !reset {} instead and also works.

Would you prefer? Looks less hacky

@valentijnscholten
Copy link
Member

That looks cleaner indeed.

What does this part do:

    depends_on: !override
      postgres:
        condition: service_started

Is it to get rid of the depends_on for redis and initializer?

@valentijnscholten valentijnscholten added this to the 2.51.0 milestone Sep 20, 2025
@fopina fopina force-pushed the compose/no_useless_unittest_builds branch from 913e05f to e2faab5 Compare September 20, 2025 09:02
@fopina fopina changed the title use profiles to skip unused services in unit test docker compose files do not build/start unused services in unit test docker compose files Sep 20, 2025
@fopina
Copy link
Contributor Author

fopina commented Sep 20, 2025

It does look much cleaner. Should've thought of it from the start when I read about it together with override 🤦

And yes, to remove dependency on non-existing services.

Default compose override behavior is to merge dictionaires. !reset just cleans it up, !override replaces it with new definition.

reset removes the yaml entry, override replaces with new one (instead of merging)

Copy link
Contributor

@mtesauro mtesauro left a comment

Choose a reason for hiding this comment

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

Approved

@Maffooch Maffooch requested a review from rossops September 23, 2025 15:57
@valentijnscholten valentijnscholten merged commit fd2bf22 into DefectDojo:dev Sep 23, 2025
88 checks passed
@fopina fopina deleted the compose/no_useless_unittest_builds branch September 23, 2025 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants