Unify the Docker Image build CI template (default branch)

Merged Michael Friedrich requested to merge ci-templates-docker-main into master

What does this MR do?

We are using main as new default branch instead of master in our Developer Evangelism projects. In community workshops, we often show how to build a Docker image: Navigate into the editor, select Docker and that's it, let it build.

The current CI template has master hardcoded in both the job name and the only/except rule and requires manual changes (job name and 2x rules edit).

This MR provides a generic single job with conditional handling for the branches, suggested in !51931 (comment 529010707) It also adds more logging to immediately see what's going on in the CI/CD job logs.

This replaces the old suggestion with 2 jobs and renamed job names.

The documentation in doc/user/packages/container_registry/index.md may need an update, although there are more locations with only/except master examples (grep -r -- '- master' doc/).

This MR is the first iteration of updating the CI templates to help move https://gitlab.com/groups/gitlab-org/-/epics/3600 forward.

cc @dhershkovitch @nadia_sotnikova @danielgruesso

Screenshots (strongly suggested)

Default branch (in this case, 'main') in https://gitlab.com/dnsmichi/ci-cd-playground/-/jobs/1102222235

image

Any branch other than the default branch in https://gitlab.com/dnsmichi/ci-cd-playground/-/jobs/1101989114

image

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Michael Friedrich