Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

Support for docker run args for docker image targets #1957

Merged
merged 6 commits into from Dec 17, 2021

Conversation

psigen
Copy link
Contributor

@psigen psigen commented Nov 11, 2021

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

The bazel run command applied to docker images currently does not have functionality to pass any arguments to the underlying docker run command. This means that it is impossible to use docker image targets to perform things like CLI operations on files, or set their network settings.

Issue Number: N/A

What is the new behavior?

This PR changes bazel run's behavior on image targets to mirror docker run's behavior. Docker images can now be run with arbitrary docker flags like:

bazel run //:my_image -- -v /path/to/file:/path/inside/container -- arg0 arg1 arg2

which mirrors a call to

docker run -v /path/to/file:/path/inside/container bazel/my_image -- arg0 arg1 arg2

Since --norun is not a valid docker run flag, we can strip and parse it with no changes, preserving existing functionality.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Can someone please help me with defining appropriate testing and documentation for this change? 🙏

This adds parsing of command-line arguments being passed to 'bazel run'
when executing an image target.  The "--" delimiter is used to separate
arguments for "docker run" from arguments to the container.

This makes the following style of calls possible:

```
bazel run //:my_cool_image -- -p 8080:8080 -v /tmp:/tmp -- --my-cool-flag
```

which is translated into

```
docker run -i --rm -p 8080:8080 -v /tmp:/tmp bazel/my_cool_image:image --my-cool-flag
```
@google-cla google-cla bot added cla: yes and removed cla: no labels Nov 11, 2021
@psigen psigen changed the title Docker run args Support for docker run args for docker image targets Nov 11, 2021
Copy link
Collaborator

@gravypod gravypod left a comment

Choose a reason for hiding this comment

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

I don't see any initial reason to not merge this. @alexeagle any thoughts? It looks like it should be backwards compatible.

@psigen
Copy link
Contributor Author

psigen commented Nov 20, 2021

@gravypod Since previously all the args were just being ignored and we preserved --norun, I think this should be backwards-compatible 👍

@psigen
Copy link
Contributor Author

psigen commented Nov 26, 2021

Where could I add a unit test for the behavior? I think I got the docs updated.

(Also, that build error in CI looks totally unrelated to the PR)

@UebelAndre
Copy link
Contributor

@psigen @gravypod friendly ping 😅 any way to move this change forward? It'd be a very convenient feature!

@psigen
Copy link
Contributor Author

psigen commented Dec 10, 2021

I'd love to move this change forward! Please just let me know what I need to do next to get it approved 😄

@UebelAndre
Copy link
Contributor

For starters. It seems there's a build failure in CI. Fixing that may move this forward

@psigen
Copy link
Contributor Author

psigen commented Dec 11, 2021 via email

@psigen
Copy link
Contributor Author

psigen commented Dec 11, 2021

I have successfully reworded the README.md hard enough to fix the pkg install build reproducibility tests 🤷

Copy link
Collaborator

@gravypod gravypod left a comment

Choose a reason for hiding this comment

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

Thanks for updating the docs. Looks good to me now. Going to check in with @alexeagle but I think this should be backwards compatible.

@gravypod
Copy link
Collaborator

Just remembered, we've previously discussed this. I think we're good to go here.

@gravypod gravypod merged commit 40cc8e8 into bazelbuild:master Dec 17, 2021
@psigen
Copy link
Contributor Author

psigen commented Dec 19, 2021

Thanks @gravypod!

@robmartorano
Copy link

I think there may have been a mistake in the merge earlier in this PR, line "%{run_tag}": run_tag, was lost in layer_tools.bzl, which results in bazel run not working against head. Adding that line back results in things working. Great feature addition overall!

@psigen psigen mentioned this pull request Jan 8, 2022
12 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants