Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] docker compose tag --template "template" --push #9051

Closed
abdennour opened this issue Dec 18, 2021 · 14 comments
Closed

[Feature Request] docker compose tag --template "template" --push #9051

abdennour opened this issue Dec 18, 2021 · 14 comments
Labels

Comments

@abdennour
Copy link

Description

I would like to tag my built images, then, optionally, push these tags.
In CI environment, image tags are auto-calculated, and CI has to do some governance regardless the YAML definition of .services{}.image

Poposal
Adding subcommand docker compose tag with the following options:

  • --template string: the tag template which can leverage the following variables :
    - {{ .ServiceName }} - service name under tagging
    - {{ .ProjectName }} - compose project name
    - {{ .ServicesCount }} - Total number of services
    - {{ .ServicesToBuildCount }} - Total number of services to build
  • --push: whether to push the new tag(s) or just tagging

i.e.

docker compose tag --template "myregistry.local/myrepo/{{ .ServiceName }}:v1" --push 

Scenario 1

Given a docker-compose file as following:

version: "3.9"
services:
  frontend:
    build: frontend/
    ports:
     -  9090:80
  backend:
    build: backend/
    ports:
     - 8080:80
    image: mybackend:v1
  db:
    image: mysql

And given this script (After implementing this feature)

VERSION=v1.2.3
APP=myapp
docker compose tag --template "nexus.local/myrepo/{{ if eq .ServicesToBuildCount 1}}$APP{{ else }}$APP-{{ .ServiceName }}{{ end }}:$VERSION" --push

Results:

  • New image tag with name nexus.local/myrepo/myapp-frontend:v1.2.3 is created & pushed
  • New image tag with name nexus.local/myrepo/myapp-backend:v1.2.3 is created & pushed
abdennour added a commit to ElmCompany/compose that referenced this issue Dec 18, 2021
related to docker#9051

Signed-off-by: abdennour <mail@abdennoor.com>
abdennour added a commit to ElmCompany/compose that referenced this issue Dec 18, 2021
with --push option also

it resolves docker#9051

Signed-off-by: abdennour <mail@abdennoor.com>
abdennour added a commit to ElmCompany/compose that referenced this issue Dec 18, 2021
it solves docker#9051

Signed-off-by: abdennour <mail@abdennoor.com>
@abarrak
Copy link

abarrak commented Dec 18, 2021

Would maintainers kindly take note of this good feature?
it maximizes productivity and bundles compose with alternative option to tag and push.

@abdennour
Copy link
Author

I think @glours or/and @ndeloof could help here

@ndeloof
Copy link
Contributor

ndeloof commented Dec 20, 2021

Could you please clarify the uses cases for - {{ .ServicesCount }} / {{ .ServicesToBuildCount }}
service definition in compose.yaml should not be considered ordered imho and while service name sounds relevant to me to tag images, I hardly understand the usage of such counters.

@abdennour
Copy link
Author

The use case is CI system has to push built images.
CI system has to apply GRC on image naming. Thus, CI system has to re-tag images as per organization naming conventions, then push them to the registry.

@ndeloof
Copy link
Contributor

ndeloof commented Dec 20, 2021

I understand the global feature request to have additional/atlernative tags for image built by compose, I just wonder about the ServicesCount / ServicesToBuildCount variable you suggest. I don't feel the need for those, and they suggest a fragile design for deterministic image tags

@abdennour
Copy link
Author

Oh! I see your point @ndeloof.
Actually this is the usecase of "ServicesToBuildCount" :

  • While applying the auto-tagging by the CI system, we may reuse the COMPOSE_PROJECT_NAME as name of the repository ( my.registry/${COMPOSE_PROJECT_NAME}:${VERSION} )
    i.e. COMPOSE_PROJECT_NAME=myapp-frontend , then tag is my.registry/myapp-frontend:${VERSION}
  • However, what to do if we have more than one service to build ? we may use my.registry/{{ .ServiceName }}:${VERSION} but this can lead to a conflict of naming among many docker-compose.yaml coming from many projects/many git repos.
    Thus, we want to know how many services need to be built & accordingly, we will decide the tag template.

More real example:

VERSION=v1.2.3
APP=myapp
docker compose tag --template "nexus.local/myrepo/{{ if eq .ServicesToBuildCount 1}}$APP{{ else }}$APP-{{ .ServiceName }}{{ end }}:$VERSION" --push

@ndeloof
Copy link
Contributor

ndeloof commented Dec 20, 2021

I don't expect users would use my.registry/${COMPOSE_PROJECT_NAME}:${VERSION} as this would be terribly ambiguous regarding what has been built. So I expect some variation around my.registry/${PROJECT}:${SERVICE}:${VERSION}. Switching between those would be even worse imho, bringing confusion and eventually more issues reported to project maintainers, i.e. to me ;) So, I'll be more conservative if we approve this feature to make it somehow more deterministic, whatever the compose build command gets as parameters and number of service images to be built.

From my own experience, users relying on compose for CI do tag images with my.registry/${PROJECT}:${SERVICE}:${GIT_SHA} to make it easy track which image has been built from a commit and run tests/deployments accordingly.

@abdennour
Copy link
Author

@ndeloof let me know please what's your acceptance criteria ?

abdennour added a commit to ElmCompany/compose that referenced this issue Jan 10, 2022
Signed-off-by: atoumi <atoumi@elm.sa>
@abdennour
Copy link
Author

OK guys! WE released this feature from our fork. Feel free to use with caution as it's not the official compose.

Read more also the use case

@ndeloof
Copy link
Contributor

ndeloof commented Jan 17, 2022

I'm not fully convinced by this approach.
But I'm sure "compose push" is missing a significant part of the pipeline.
I enjoyed the concept of docker/app to "push a compose file and all required images as an OCI manifest" using manifest-list capability to refer to other images. Maybe we could resurect the idea, so that compose push also push the compose file and images under specified tag.

@abdennour
Copy link
Author

Any change in the mind ? any news t get this reviewed & merged ?

@abdennour
Copy link
Author

@ndeloof Could you please check again? I am pretty sure you may be convinced now

@stale
Copy link

stale bot commented May 21, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label May 21, 2023
@stale
Copy link

stale bot commented Jun 18, 2023

This issue has been automatically closed because it had not recent activity during the stale period.

@stale stale bot closed this as completed Jun 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants