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

feat: add --cli option #6584

Closed
wants to merge 10 commits into from
Closed

Conversation

orisano
Copy link

@orisano orisano commented Mar 15, 2019

i implemented --exec option on docker-compose build for to use buildkit.

This PR is prototype. please give me feedback.

@GordonTheTurtle
Copy link

Please sign your commits following these rules:
https://github.com/moby/moby/blob/master/CONTRIBUTING.md#sign-your-work
The easiest way to do this is to amend the last commit:

$ git clone -b "feat-add-exec-build" git@github.com:orisano/compose.git somewhere
$ cd somewhere
$ git commit --amend -s --no-edit
$ git push -f

Amending updates the existing PR. You DO NOT need to open a new one.

@AkihiroSuda
Copy link

cc @tonistiigi @tiborvass

line = p.stdout.readline()
if line == "":
break
line = line.replace("writing image sha256:", "Successfully built ")

Choose a reason for hiding this comment

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

why?

Copy link
Author

Choose a reason for hiding this comment

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

for bypass this.
https://github.com/docker/compose/blob/master/compose/service.py#L1110

        for event in all_events:
            if 'stream' in event:
                match = re.search(r'Successfully built ([0-9a-f]+)', event.get('stream', ''))
                if match:
                    image_id = match.group(1)

Choose a reason for hiding this comment

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

This doesn't seem robust.
Can we just append Successfully built... when it didn't appear from docker build CLI?

Copy link
Author

@orisano orisano Mar 15, 2019

Choose a reason for hiding this comment

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

I do not know how to get image_id from stdout on docker build --progress=plain.
Do you have any idea?

Choose a reason for hiding this comment

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

--iidfile?

Copy link
Author

@orisano orisano Mar 15, 2019

Choose a reason for hiding this comment

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

I implemented to use an iidfile method.

@docteurklein
Copy link

cool! It's not the first time using the CLI is an option (see https://docs.docker.com/compose/reference/envvars/#compose_interactive_no_cli ). maybe there is a way to normalize this?

@mipearson
Copy link

I'm keen to contribute here - is there any guidance from the compose team as to how they'd prefer this to be implemented?

@tonistiigi
Copy link
Member

Not a compose maintainer but this seems ok approach to me. We'll probably take a bit different stab at the same problem at https://github.com/tonistiigi/buildx/issues/13 but the solutions don't seem conflicting and have bit different use cases.

@@ -290,7 +291,8 @@ def build(self, options):
build_args=build_args,
gzip=options.get('--compress', False),
parallel_build=options.get('--parallel', False),
silent=options.get('--quiet', False)
silent=options.get('--quiet', False),
_exec=bool(options.get('--exec', False)),
Copy link
Member

Choose a reason for hiding this comment

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

here as well (I think)

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps other locations as well, but I'm not a python coder 😅 and not super-familiar with the codebase (just noticed the PR)

@orisano orisano force-pushed the feat-add-exec-build branch 2 times, most recently from 36ed2fa to 19b5db9 Compare April 5, 2019 07:36
@ulyssessouza
Copy link
Collaborator

A general doubt I have is about the name of the option... --exec sounds very internal pythonic for me.
From an user's point of view I see something like --native, --cli or anything more generic.

WDYT @chris-crone @thaJeztah @rumpl @shin-

@orisano orisano force-pushed the feat-add-exec-build branch 2 times, most recently from 85a986a to dc846f7 Compare April 24, 2019 14:34
@ulyssessouza
Copy link
Collaborator

Please rebase your PR with upstream master to pass the CI

@orisano orisano force-pushed the feat-add-exec-build branch from dc846f7 to 69415b1 Compare April 25, 2019 11:22
@orisano
Copy link
Author

orisano commented Apr 26, 2019

rebased

@ulgens
Copy link

ulgens commented May 1, 2019

ping @ulyssessouza The last request change is already done 🙂 Is there something else missing?

@ulgens
Copy link

ulgens commented May 1, 2019

Is there anyway to read --exec parameter from environment?

@CpuID
Copy link

CpuID commented Jul 21, 2019

  • compose currently doesn't handle the "nice" output of the docker cli when buildkit is enabled (because it doesn't detect that a TTY is attached when called through docker compose)

    • research if we can make it see the TTY, so that the output of the docker cli is printed correctly

+1, would be nice to know it looks the same between both docker and docker-compose

  • if possible have an option on the docker cli that returns the build output in a machine-parseable format

    • perhaps the "plain" output is suitable, but if not, another format could be added
    • offer this as an option during build
    • as a (future) enhancement; implement code in docker-compose to convert that output into something more "like" the existing output of docker-compose
    • (this could be a nice project to work on for people from the community)

I think the most common part of the output that would be beneficial would be if a layer is cached or not (cache state).

One other nice to have (but notpossible via Buildkit? and independent of this PR) would be exposing intermediate layer image SHA/digests. I've had to on occasion grab the SHA/digest before a failure and run docker run -it --rm sha sh and poke around at the intermediate image and try interactively resolve why a step of a build failed.

@jamesharris-garmin
Copy link

Have we addressed the changes needed to merge this PR?

@cristicbz
Copy link

I'm a little worried this fell into the trap of the perfect being the enemy of the good. This PR offers an opt-in, which will offer a good path for folks who need buildkit and don't need build output. The path forward for using the CLI all the time would be good to determine, but it shouldn't block the simple use-case that this PR supports.

@thaJeztah
Copy link
Member

This PR adds a new flag, in addition to all flags that the CLI supports, which means that all of those would have to be supported for future releases

@kristleifur
Copy link

kristleifur commented Aug 5, 2019

If that’s a problem, then if this is merged and announced and documented as experimental it doesn’t have to be supported.

I’m personally running the fork that has the feature and will do so for the foreseeable future.

I also pledge do my utmost to help do any possible work required to get this merged.

orisano and others added 10 commits August 13, 2019 13:54
Signed-off-by: Nao YONASHIRO <yonashiro@r.recruit.co.jp>
Signed-off-by: Nao YONASHIRO <yonashiro@r.recruit.co.jp>
Signed-off-by: Nao YONASHIRO <yonashiro@r.recruit.co.jp>
Signed-off-by: Nao YONASHIRO <yonashiro@r.recruit.co.jp>
Signed-off-by: Nao YONASHIRO <yonashiro@r.recruit.co.jp>
Signed-off-by: Nao YONASHIRO <yonashiro@r.recruit.co.jp>
Signed-off-by: Nao YONASHIRO <yonashiro@r.recruit.co.jp>
Signed-off-by: Ulysses Souza <ulysses.souza@docker.com>
Signed-off-by: Ulysses Souza <ulysses.souza@docker.com>
Only handles the arguments already supported by
`docker-compose build`

Signed-off-by: Ulysses Souza <ulysses.souza@docker.com>
@ulyssessouza
Copy link
Collaborator

Hello @orisano. I'm sorry for the late response. As you can see, I just pushed 3 commits related to the internal meetings with @thaJeztah and the team.
The commits include:

  • Buildkit's nice TTY output by letting the --progress as "auto"
  • Replace --cli by and envvar called COMPOSE_NATIVE_BUILDER.
  • Reduce the arguments passed to docker build to the already present in docker-compose build

PTAL @thaJeztah

Please note this feature is EXPERIMENTAL and could be removed at any new version

@ulyssessouza ulyssessouza self-requested a review August 14, 2019 08:48
@ulyssessouza ulyssessouza dismissed their stale review August 14, 2019 08:55

changes done

@thaJeztah
Copy link
Member

Thanks @ulyssessouza - that looks good for a start!

The only thing I'm thinking is if we should add the --progress flag to compose as well, so that people can use --progress=plain in situations where a terminal is present, but you want the output in a more parsable format (I know we've done so in CI, where a TTY may be attached, you don't need the fancy output)

That could be done as a follow-up though (we'll need follow-ups to discuss / implement other flags anyway)

I haven't tried building/testing this PR yet; did you try if setting DOCKER_BUILDKIT=1 / DOCKER_BUILDKIT=0 as (environment) variable works as expected?

DOCKER_BUILDKIT=1 docker-compose build ...

DOCKER_BUILDKIT=0 docker-compose build ...

We'll also need to make sure the docker-compose up --build follows the same behavior, otherwise the cache is not shared between both.

Some other thoughts;

  • Should we print a warning if someone has this feature enabled, and uses the --compress or --parallel flag? (I think both won't do anything when using the CLI for building?)
  • Possibly hide them if COMPOSE_NATIVE_BUILDER=1 (but that's a nice to have)

@abhaychrungoo
Copy link

abhaychrungoo commented Aug 21, 2019

I have taken this through some limited manual testing on a Linux x86 box

Would it be fair to argue that this PR should produce similar behavior for

  • docker-compose build && docker-compose up
  • docker-compose up --build

Currently, the first uses buildkit (w DOCKER_BUILDKIT=1, COMPOSE_NATIVE_BUILDER=1), but the second does not,

@thaJeztah
Copy link
Member

Would it be fair to argue that this PR should produce similar behavior for

Thanks for testing it! Yes, I think it should work for both (but currently doesn't) (see my comment above yours)

@ulyssessouza is it difficult to make docker compose up --build also call out to the CLI for the actual build(s) ?

@orisano
Copy link
Author

orisano commented Aug 22, 2019

orisano@aac7193
It supports docker-compose up --build

@ulyssessouza ulyssessouza mentioned this pull request Aug 22, 2019
3 tasks
@ulyssessouza
Copy link
Collaborator

Hello all!

Now that the requirements of the PR/issue are quite solid, I just opened a new PR to manage this in a clear way.
The new one includes all the previous commits and the support for docker-compose up --build that @orisano just added squashed in a single commit
So to continue the review of feature, please refer to #6865

Once again, thanks a lot for the contribution @orisano !

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.