-
Notifications
You must be signed in to change notification settings - Fork 176
Transform docker-app as a docker-cli plugin #469
Conversation
3d5eeda
to
4697791
Compare
Gopkg.toml
Outdated
@@ -29,7 +29,7 @@ required = ["github.com/wadey/gocovmerge"] | |||
|
|||
[[override]] | |||
name = "github.com/docker/cli" | |||
revision = "f95ca8e1ba6c22c9abcdbf65e8dcc39c53958bba" | |||
revision = "3ddb3133f5b5a74dd4e3f721ced21f4d0b9651b6" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(random location for comment on commit message)
The first commit here is titled Bump docker-cli to include the plugin work
but actually it does far more than that -- it actually match the switch to being a plugin. I'd suggest a title like "Refactor as a CLI plugin" (or "Convert to...") and leave the mention of the CLI bump in the body of the commit message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another commit is rendered as:
Add a new binary docker-app-standalone which is in fact the old docke…
…r-app before its pluginization.
i.e. the first line (summary) is too long. I think:
Add a new binary docker-app-standalone
This is in fact the old docker-app before its pluginization.
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed 👍
e2e/cnab_test.go
Outdated
Env: []string{fmt.Sprintf("DUFFLE_HOME=%s", tmpDir.Path())}, | ||
Env: append(os.Environ(), | ||
fmt.Sprintf("DUFFLE_HOME=%s", tmpDir.Path()), | ||
fmt.Sprintf(manager.ReexecEnvvar+"="+dockerCli)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC since I did the PoC port in in #433 these tests now build a local dockerCli
(because of the context stuff) and so that should be "plugin enabled" and IMHO we should use it here instead of doing this workaround.
Basically where below you transform []string{dockerApp, "install"
into []string{dockerApp, "app", "install"
you should instead transform it to []string{dockerCli, "app", "install"
having arranged for the plugin binary to be in ${DOCKER_CONFIG}/cli-plugins
or setup ``${DOCKER_CONFIG}/config.json` so it includes the right path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you built most of the scaffolding you need for TestInvokePluginFromCLI
below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep indeed we should test docker-app as a plugin, called by the CLI, as it is now the preferred way to use docker-app. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed 👍
e2e/plugin_test.go
Outdated
validate Checks the rendered application is syntactically correct | ||
version Print version information | ||
|
||
Run 'docker app COMMAND --help' for more information on a command.` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should use golden for this block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed 👍
@@ -31,7 +31,7 @@ func findApp() (string, error) { | |||
for _, c := range content { | |||
if strings.HasSuffix(c.Name(), internal.AppExtension) { | |||
if hit != "" { | |||
return "", fmt.Errorf("multiple applications found in current directory, specify the application name on the command line") | |||
return "", fmt.Errorf("Error: multiple applications found in current directory, specify the application name on the command line") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Elsewhere we needed to remove the Error:
prefix (because core plugin framework deals with it), so is this case correct (doesn't result in Error: Error:
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an e2e test which checks this error. It failed until I added this "Error: "...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right, I even realised this in my WIP PR where I wrote in the commit message:
Finally, the idiom in docker/cli (for better or worse) is to include an "Error:
" prefix in the error string itself, rather than injecting it when printing.
Since CLI plugins follow the behaviour of the CLI here it is necessary to
prepend "Error: " to some messages. I've only done exactly those necessary to
pass the e2e tests, a fuller audit is very likely required.
(and then forgot about it, obviously)
Feel free to steal some or all of my words for your commit message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I let this fuller audit as an exercise for the reviewers
internal/commands/root.go
Outdated
cmd := &cobra.Command{ | ||
Use: "app", | ||
// NewRootCmd returns the base root command. | ||
func NewRootCmd() *cobra.Command { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either add to the comment users must set the Use field on the result
or make it an argument and deal with it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I could have done that 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed 👍
internal/commands/root.go
Outdated
Short: "Docker Application Packages", | ||
Long: `Build and deploy Docker Application Packages.`, | ||
} | ||
addCommands(cmd, dockerCli) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both callers do app.AddCommands(cmd, dockerCli)
on the result -- maybe just pass dockerCli
as an argument and do it here instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed 👍
911065d
to
f1c7f52
Compare
At least the |
|
48b7ac0
to
44d0886
Compare
97f22cf
to
98407b9
Compare
a72c61e
to
4b49845
Compare
Codecov Report
@@ Coverage Diff @@
## master #469 +/- ##
==========================================
+ Coverage 69.38% 69.41% +0.02%
==========================================
Files 50 50
Lines 2515 2501 -14
==========================================
- Hits 1745 1736 -9
+ Misses 540 537 -3
+ Partials 230 228 -2
Continue to review full report at Codecov.
|
7f7e65c
to
6b31ce3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just minor changes
|
||
### Linux or macOS | ||
|
||
Download your OS tarball: | ||
```bash | ||
export OSTYPE="$(uname | tr A-Z a-z)" | ||
curl -fsSL --output "/tmp/docker-app-${OSTYPE}.tar.gz" "https://github.com/docker/app/releases/download/v0.6.0/docker-app-${OSTYPE}.tar.gz" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must remember to bump the version when we do a release.
README.md
Outdated
``` | ||
|
||
|
||
**Note:** To use Application Packages as images (i.e.: `save`, `push`, or `install` when package is not present locally) on Windows, one must be in Linux container mode. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this PR, there is no applications as images.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(We can clean this up after Simon's push/pull PR is merged)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks @ulyssessouza and @silvin-lubecki!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few nits
Gopkg.toml
Outdated
@@ -27,9 +27,15 @@ required = ["github.com/wadey/gocovmerge"] | |||
name = "github.com/opencontainers/runc" | |||
version = "v1.0.0-rc6" | |||
|
|||
#[[override]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove commented vendoring
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
e2e/commands_test.go
Outdated
icmd.RunCmd(cmd).Assert(t, icmd.Success) | ||
} | ||
|
||
func TestBundle(t *testing.T) { | ||
tmpDir := fs.NewDir(t, t.Name()) | ||
defer tmpDir.Remove() | ||
// Using a custom DOCKER_CONFIG to store contexts in a temporary directory | ||
cmd := icmd.Cmd{Env: append(os.Environ(), "DOCKER_CONFIG="+tmpDir.Path())} | ||
cmd := icmd.Cmd{Env: os.Environ()} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to patch DOCKER_CONFIG here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been reworked so that we use a new config dir for each test.
We can actually remove the Env: os.Environ()
as it's redundant. Let's do so in a followup @ulyssessouza
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looked at the new dir for each test thing. The main problem is that it changes the environment for the whole test project, while only the child processes we invoke require these environment variables changes. Also, this dockerCli global variable makes it impossible to run tests in parallel.
Dockerfile
Outdated
@@ -8,7 +8,10 @@ RUN apt-get install -y -q --no-install-recommends \ | |||
|
|||
WORKDIR /go/src/github.com/docker/cli | |||
|
|||
RUN git clone https://github.com/docker/cli.git . | |||
RUN git clone https://github.com/ulyssessouza/cli . && git checkout 29d30ec1a05e8a285007240cc0f85864067e7344 | |||
# FIXME(ulyssessouza): Go back to the line below when PRs https://github.com/docker/cli/pull/1710 and https://github.com/docker/cli/pull/1690 hits the cli |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to change, but it might actually end up being docker/cli#1718 in preference to docker/cli#1710
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made this change in my rebase
Gopkg.toml
Outdated
[[override]] | ||
name = "github.com/docker/cli" | ||
revision = "f95ca8e1ba6c22c9abcdbf65e8dcc39c53958bba" | ||
source = "https://github.com/ulyssessouza/cli" | ||
revision="29d30ec1a05e8a285007240cc0f85864067e7344" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop the first commented out one and write:
[[override]]
name = "github.com/docker/cli"
revision = "f95ca8e1ba6c22c9abcdbf65e8dcc39c53958bba"
### Waiting on PR https://github.com/docker/cli/pull/1710 to land on cli ###
source = "https://github.com/ulyssessouza/cli"
revision="29d30ec1a05e8a285007240cc0f85864067e7344"
there's no need to keep the other staza around,it's not a useful reference.
"--description", "my cool app", | ||
"--maintainer", "bob", | ||
"--maintainer", "joe:joe@joe.com", | ||
"--single-file", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are due to docker/cli#1699 I think?
You didn't actually remove the short versions so there is no followup to do when that is fixed, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that's correct
* Use the docker/cli/cli-plugins/plugin.Run helper to create and execute the commands as a plugin * Refactor e2e tests to use “docker app” (docker cli invoking docker-app plugin) * Add CLI plugin invocation e2e tests * Bump docker-cli to include the plugin work * Bump gotest.tools to 2.3.0 Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com>
…can be re-used by another binary. Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com>
This is in fact the old docker-app before its pluginization. Added it to cross compilation Now each released tar.gz file per os comes with two binaries in it: docker-app-plugin-os and docker-app-standalone-os Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com>
* Update windows installation too, which seems obsolete Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com>
Signed-off-by: Jean-Christophe Sirot <jean-christophe.sirot@docker.com>
Signed-off-by: Ulysses Souza <ulysses.souza@docker.com>
Perform the git clone and a chechout to avoid that a Dockerfile cache and enforce determinism Signed-off-by: Ulysses Souza <ulysses.souza@docker.com>
- Update docker/cli is now pointing to chris-crone/cli. The change needs the merge of docker/cli#1718 and docker/cli#1690 - Fix issues relative paths in Jenkinsfile and Jenkinsfile.baguette - Avoid using '--config' in favor of env variable 'DOCKER_CONFIG' Signed-off-by: Ulysses Souza <ulysses.souza@docker.com>
Signed-off-by: Ulysses Souza <ulysses.souza@docker.com>
Signed-off-by: Ulysses Souza <ulysses.souza@docker.com>
Signed-off-by: Ulysses Souza <ulysses.souza@docker.com>
e2e/main_test.go
Outdated
panic(err) | ||
} | ||
err = os.Setenv("DOCKER_CONFIG", configDir) | ||
if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to change the current process environment car but only impact the child process environment (setting this on the process level makes actually tests having huge side effects, preventing them to run in parallel in the future)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The common rule for this kind of member function of a globally shared object is that it should not have side effects on the current process shared state (e.g. should not change process-wide environement variable).
It should return 2 values:
- one string for the config dir
- one map[string]string usable to set child processes environment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of this I've renamed the function createTestCmd
, it returns an icmd.Command
with the Env
prefilled and a cleanup function.
e2e/commands_test.go
Outdated
icmd.RunCmd(cmd).Assert(t, icmd.Success) | ||
} | ||
|
||
func TestBundle(t *testing.T) { | ||
tmpDir := fs.NewDir(t, t.Name()) | ||
defer tmpDir.Remove() | ||
// Using a custom DOCKER_CONFIG to store contexts in a temporary directory | ||
cmd := icmd.Cmd{Env: append(os.Environ(), "DOCKER_CONFIG="+tmpDir.Path())} | ||
cmd := icmd.Cmd{Env: os.Environ()} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looked at the new dir for each test thing. The main problem is that it changes the environment for the whole test project, while only the child processes we invoke require these environment variables changes. Also, this dockerCli global variable makes it impossible to run tests in parallel.
Signed-off-by: Ulysses Souza <ulysses.souza@docker.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
- What I did
Transform docker-app as a docker-cli plugin using docker-cli helpers.
Add a new binary docker-app-standalone which is in fact the old docker-app before its pluginization.
Now each released tar.gz file per os comes with two binaries in it:
- How to verify it
With a master docker-cli built on your own:
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)