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

Add docker-compose tag <service> <tag> and allow to push a specific tag by using push command #7669

Open
Jokero opened this issue Aug 14, 2020 · 14 comments

Comments

@Jokero
Copy link

Jokero commented Aug 14, 2020

Is your feature request related to a problem? Please describe.
I have several applications with their own Dockerfile within one project and in order to build, launch and test them locally I'm using docker-compose.

It seems like a good idea to reuse docker-compose commands to build, test and push images to registry from CI, so I decided to use them in Jenkinsfile. Project has package.json file with current version which is incremented during CI build. This version is used as tag for docker images.

docker-compose.yaml:

version: '2'

services:
  app1:
    image: my-registry.com/app1
    build:
      context: ./app1
    // other fields
  app2:
    image: my-registry.com/app2
    build:
      context: ./app2
    // other fields
  app3:
    image: my-registry.com/app3
    build:
      context: ./app3
    // other fields

The current CI pipeline looks as follows:

1) Build images
docker-compose build // generates images with "latest" tag

2) Test images
docker-compose run --rm app1 <test command> // the same for app2 and app3

3) If tests passed, increment version and use it as the next docker tag
npm version <patch/minor/major>
newVersion = readJSON('package.json').version

4) Tag and push images
composeServices = readYaml('docker-compose.yaml').services // { app1: { image: my-registry.com/app1 }, ... }
image = composeServices.app1.image // the same for app2 and app3
docker tag <image> <image>:<newVersion>
docker push <image>:<newVersion>

This pipeline works but I have to read compose file to get image that will be used in "docker tag" and "docker push" commands.

Describe the solution you'd like
I'd like to have a new command:

docker-compose tag <service> <tag>
// for my example
docker-compose tag app1 <version from updated package.json>

And I want "push" command to support tag postfix:

docker-compose push <service>:<tag>
// for my example
docker-compose push app1:<version from updated package.json>

Describe alternatives you've considered
Using "docker tag" and "docker push" explicitly but for that I need to read images from docker-compose.yaml file

@so-jelly
Copy link

so-jelly commented Mar 11, 2021

docker-compose "extends" works for me

version: "2.4"
services:
  foo:
    image: foo:${version:-dev}
    build:
      context: .
  foo-latest:
    extends: foo
    image: bar:latest

@existe-deja
Copy link

existe-deja commented Mar 19, 2021

extends can work. But tagging after a build could be very useful, especially for CI pipelines.

@stale
Copy link

stale bot commented Nov 9, 2021

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 Nov 9, 2021
@thetic
Copy link

thetic commented Nov 9, 2021

I am still interested in this functionality.

@stale
Copy link

stale bot commented Nov 9, 2021

This issue has been automatically marked as not stale anymore due to the recent activity.

@stale stale bot removed the stale label Nov 9, 2021
@abdennour
Copy link

abdennour commented Nov 21, 2021

I am still interested in this functionality.

1 similar comment
@neverkas
Copy link

neverkas commented Jan 30, 2022

I am still interested in this functionality.

@Pakoke
Copy link

Pakoke commented Feb 11, 2022

I am still interested in this functionality.
Could we please have some feedback about this change?

@abdennour
Copy link

abdennour commented Feb 11, 2022

I have already implemented this feature. I opened the pull request since 2 months. Check #9052

@Pakoke @neverkas FYI

@glours
Copy link
Contributor

glours commented Feb 11, 2022

We're currently working on adding some capabilities to the build step at the Compose specification level (like specify tags), I hope we can propose something soon and then we'll be able to implement the changes into Compose (v2)

@cyberdevnet
Copy link

cyberdevnet commented Jun 5, 2022

any update about this feature?

@glours
Copy link
Contributor

glours commented Jun 5, 2022

Support of tags during build step has been added to the v2.6.0 release
We don't plan to add a specific tag command

@thetic
Copy link

thetic commented Jun 5, 2022

Cool! This looks like a useful and related feature, but I don't think this addresses the use case described.

@jmfrees
Copy link

jmfrees commented Jul 5, 2022

Support of tags during build step has been added to the v2.6.0 release We don't plan to add a specific tag command

Since they don't plan to support the feature added in #9051, I accomplish the same thing in a more generic environment than Jenkins.

docker compose images | awk '(NR>1) { print $2 }' > image_names
export OLD_VERSION=foo
export VERSION=bar
cat image_names | xargs -I{} docker tag {}:$OLD_VERSION {}:$VERSION
cat image_names | xargs -I{} docker push -a {}  

I would really love it if docker compose tag was a thing, but this will do for now.

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

No branches or pull requests

10 participants