Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 207a945

Browse files
authored
Merge pull request #469 from silvin-lubecki/cli-plugin
Transform docker-app as a docker-cli plugin
2 parents 36fd67f + 30fda72 commit 207a945

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1159
-645
lines changed

Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ RUN apt-get install -y -q --no-install-recommends \
88

99
WORKDIR /go/src/github.com/docker/cli
1010

11-
RUN git clone https://github.com/docker/cli.git .
11+
RUN git clone https://github.com/chris-crone/cli . && git checkout d6bfd7e5592dad85969516c131d33910fa5ebd58
12+
# FIXME(ulyssessouza): Go back to the line below when PRs https://github.com/docker/cli/pull/1718 and https://github.com/docker/cli/pull/1690 hits the cli
13+
#RUN git clone https://github.com/docker/cli.git . && git checkout 8ddde26af67f9a76734a1676c635e48da4fe8584
14+
1215
RUN make cross binary && \
1316
cp build/docker-linux-amd64 /usr/bin/docker
1417

@@ -26,13 +29,11 @@ RUN go get -d gopkg.in/mjibson/esc.v0 && \
2629
rm -rf /go/src/* /go/pkg/* /go/bin/*
2730
COPY . .
2831

29-
# FIXME(vdemeester) change from docker-app to dev once buildkit is merged in moby/docker
3032
FROM dev AS cross
3133
ARG EXPERIMENTAL="off"
3234
ARG TAG="unknown"
3335
RUN make EXPERIMENTAL=${EXPERIMENTAL} TAG=${TAG} cross
3436

35-
# FIXME(vdemeester) change from docker-app to dev once buildkit is merged in moby/docker
3637
FROM cross AS e2e-cross
3738
ARG EXPERIMENTAL="off"
3839
ARG TAG="unknown"

Gopkg.lock

Lines changed: 13 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ required = ["github.com/wadey/gocovmerge"]
3636
source = "github.com/simonferquel/containerd"
3737
revision = "a89234684e5884e51ba195bdb16b1c6952d17f11"
3838

39+
### Waiting on PR https://github.com/docker/cli/pull/1718 and https://github.com/docker/cli/pull/1690 to land on cli ###
3940
[[override]]
4041
name = "github.com/docker/cli"
41-
revision = "06b837a7d7e1115f3d2aa65c47765e25d4bf845b"
42+
source = "https://github.com/chris-crone/cli"
43+
revision="d6bfd7e5592dad85969516c131d33910fa5ebd58"
4244

4345
[[override]]
4446
name = "github.com/deislabs/duffle"

Jenkinsfile.baguette

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ pipeline {
88
options {
99
skipDefaultCheckout(true)
1010
}
11-
environment{
12-
DOCKER_BUILDKIT=true
13-
}
1411

1512
stages {
1613
stage('Build') {
@@ -82,6 +79,8 @@ pipeline {
8279
parallel {
8380
stage("Unit Coverage") {
8481
environment {
82+
DOCKERAPP_BINARY = '../e2e/coverage-bin'
83+
DOCKERCLI_BINARY = '../docker-linux'
8584
CODECOV_TOKEN = credentials('jenkins-codecov-token')
8685
}
8786
agent {
@@ -148,6 +147,7 @@ pipeline {
148147
dir('e2e'){
149148
unstash "e2e"
150149
}
150+
sh './docker-linux version'
151151
sh './docker-app-e2e-linux -test.v --e2e-path=e2e'
152152
}
153153
}
@@ -180,6 +180,7 @@ pipeline {
180180
dir('e2e'){
181181
unstash "e2e"
182182
}
183+
sh './docker-darwin version'
183184
sh './docker-app-e2e-darwin -test.v --e2e-path=e2e'
184185
}
185186
}
@@ -201,11 +202,12 @@ pipeline {
201202
steps {
202203
dir('src/github.com/docker/app') {
203204
checkout scm
205+
unstash "binaries"
206+
sh './docker-windows.exe version'
204207
dir('_build') {
205208
unstash "invocation-image"
206209
bat 'docker load -i invocation-image.tar'
207210
}
208-
unstash "binaries"
209211
dir('examples') {
210212
unstash "examples"
211213
}

Makefile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,22 @@ check_go_env:
3333
@test $$(go list) = "$(PKG_NAME)" || \
3434
(echo "Invalid Go environment - The local directory structure must match: $(PKG_NAME)" && false)
3535

36-
cross: bin/$(BIN_NAME)-linux bin/$(BIN_NAME)-darwin bin/$(BIN_NAME)-windows.exe ## cross-compile binaries (linux, darwin, windows)
36+
cross: cross-plugin cross-standalone ## cross-compile binaries (linux, darwin, windows)
37+
38+
cross-plugin: bin/$(BIN_NAME)-linux bin/$(BIN_NAME)-darwin bin/$(BIN_NAME)-windows.exe
39+
40+
cross-standalone: bin/${BIN_STANDALONE_NAME}-linux bin/${BIN_STANDALONE_NAME}-darwin bin/${BIN_STANDALONE_NAME}-windows.exe
3741

3842
e2e-cross: bin/$(BIN_NAME)-e2e-linux bin/$(BIN_NAME)-e2e-darwin bin/$(BIN_NAME)-e2e-windows.exe
3943

44+
.PHONY: bin/${BIN_STANDALONE_NAME}-windows
45+
bin/${BIN_STANDALONE_NAME}-%.exe bin/${BIN_STANDALONE_NAME}-%: cmd/${BIN_STANDALONE_NAME} check_go_env
46+
GOOS=$* $(GO_BUILD) -o $@ ./$<
47+
48+
.PHONY: bin/${BIN_STANDALONE_NAME}
49+
bin/${BIN_STANDALONE_NAME}: cmd/${BIN_STANDALONE_NAME} check_go_env
50+
$(GO_BUILD) -o $@$(EXEC_EXT) ./$<
51+
4052
.PHONY: bin/$(BIN_NAME)-e2e-windows
4153
bin/$(BIN_NAME)-e2e-%.exe bin/$(BIN_NAME)-e2e-%: e2e bin/$(BIN_NAME)-%
4254
GOOS=$* $(GO_TEST) -c -o $@ ./e2e/

README.md

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ services:
3131
- 5678:5678
3232
```
3333
34-
With `docker-app` installed let's create an Application Package based on this Compose file:
34+
With `docker-app` [installed](#installation) let's create an Application Package based on this Compose file:
3535

3636
```bash
3737
$ docker-app init --single-file hello
@@ -187,31 +187,67 @@ Removing network hello_default
187187
## Installation
188188

189189
Pre-built binaries are available on [GitHub releases](https://github.com/docker/app/releases) for Windows, Linux and macOS.
190+
Each tarball contains two binaries:
191+
- `docker-app-plugin-{linux|darwin|windows.exe}` which is docker-app as a [docker cli plugin](https://github.com/docker/cli/issues/1534). **Note**: This requires a pre-release version of the
192+
Docker CLI
193+
- `docker-app-standalone-{linux|darwin|windows.exe}` which is docker-app as a standalone utility
194+
195+
To use the `docker-app` plugin, just type `docker app` instead of `docker-app` and all the examples will work the same way:
196+
```bash
197+
$ docker app version
198+
Version: v0.8
199+
Git commit: XXX
200+
Built: Wed Feb 27 12:37:06 2019
201+
OS/Arch: darwin/amd64
202+
Experimental: off
203+
Renderers: none
204+
205+
$ docker-app version
206+
Version: v0.8
207+
Git commit: XXX
208+
Built: Wed Feb 27 12:37:06 2019
209+
OS/Arch: darwin/amd64
210+
Experimental: off
211+
Renderers: none
212+
```
190213

191214
### Linux or macOS
192215

216+
Download your OS tarball:
193217
```bash
194218
export OSTYPE="$(uname | tr A-Z a-z)"
195219
curl -fsSL --output "/tmp/docker-app-${OSTYPE}.tar.gz" "https://github.com/docker/app/releases/download/v0.6.0/docker-app-${OSTYPE}.tar.gz"
196220
tar xf "/tmp/docker-app-${OSTYPE}.tar.gz" -C /tmp/
197-
install -b "/tmp/docker-app-${OSTYPE}" /usr/local/bin/docker-app
221+
```
222+
223+
To install `docker-app` as a standalone:
224+
```bash
225+
install -b "/tmp/docker-app-standalone-${OSTYPE}" /usr/local/bin/docker-app
226+
```
227+
228+
To install `docker-app` as a docker cli plugin:
229+
```bash
230+
mkdir -p ~/.docker/cli-plugins && cp "/tmp/docker-app-plugin-${OSTYPE}" ~/.docker/cli-plugins/docker-app
198231
```
199232

200233
### Windows
201-
```powershell
202-
function Expand-Tar($tarFile, $dest) {
203234

204-
if (-not (Get-Command Expand-7Zip -ErrorAction Ignore)) {
205-
Install-Package -Scope CurrentUser -Force 7Zip4PowerShell > $null
206-
}
235+
Download the Windows tarball:
236+
```powershell
237+
Invoke-WebRequest -Uri https://github.com/docker/app/releases/download/v0.6.0/docker-app-windows.tar.gz -OutFile docker-app.tar.gz -UseBasicParsing
238+
tar xf "docker-app.tar.gz"
239+
```
207240

208-
Expand-7Zip $tarFile $dest
209-
}
210-
Invoke-WebRequest -Uri https://github.com/docker/app/releases/download/v0.6.0/docker-app-windows.tar.gz
211-
Expand-Tar docker-app-windows.tar.gz docker-app-windows.exe
241+
To install `docker-app` as a standalone, copy it somewhere in your path:
242+
```powershell
243+
cp docker-app-plugin-windows.exe PATH/docker-app.exe
212244
```
213245

214-
**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.
246+
To install `docker-app` as a docker cli plugin:
247+
```powershell
248+
New-Item -ItemType Directory -Path ~/.docker/cli-plugins -ErrorAction SilentlyContinue
249+
cp docker-app-plugin-windows.exe ~/.docker/cli-plugins/docker-app.exe
250+
```
215251

216252
## Single file or directory representation
217253

cmd/docker-app-standalone/main.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/spf13/cobra"
8+
"github.com/spf13/pflag"
9+
10+
"github.com/docker/app/internal"
11+
app "github.com/docker/app/internal/commands"
12+
"github.com/docker/cli/cli"
13+
"github.com/docker/cli/cli/command"
14+
cliflags "github.com/docker/cli/cli/flags"
15+
"github.com/sirupsen/logrus"
16+
)
17+
18+
func main() {
19+
dockerCli, err := command.NewDockerCli()
20+
if err != nil {
21+
fmt.Fprintln(os.Stderr, err)
22+
}
23+
logrus.SetOutput(dockerCli.Err())
24+
25+
cmd := app.NewRootCmd("docker-app", dockerCli)
26+
configureRootCmd(cmd, dockerCli)
27+
28+
if err := cmd.Execute(); err != nil {
29+
os.Exit(1)
30+
}
31+
}
32+
33+
func configureRootCmd(cmd *cobra.Command, dockerCli *command.DockerCli) {
34+
var (
35+
opts *cliflags.ClientOptions
36+
flags *pflag.FlagSet
37+
)
38+
39+
cmd.SilenceUsage = true
40+
cmd.TraverseChildren = true
41+
cmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
42+
opts.Common.SetDefaultOptions(flags)
43+
return dockerCli.Initialize(opts)
44+
}
45+
cmd.Version = fmt.Sprintf("%s, build %s", internal.Version, internal.GitCommit)
46+
47+
opts, flags, _ = cli.SetupRootCommand(cmd)
48+
flags.BoolP("version", "v", false, "Print version information")
49+
cmd.SetVersionTemplate("docker-app version {{.Version}}\n")
50+
}

cmd/docker-app/main.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
package main
22

33
import (
4-
"fmt"
5-
"os"
6-
4+
"github.com/docker/app/internal"
5+
app "github.com/docker/app/internal/commands"
6+
"github.com/docker/cli/cli-plugins/manager"
7+
"github.com/docker/cli/cli-plugins/plugin"
78
"github.com/docker/cli/cli/command"
8-
"github.com/sirupsen/logrus"
9+
"github.com/spf13/cobra"
910
)
1011

1112
func main() {
12-
dockerCli, err := command.NewDockerCli()
13-
if err != nil {
14-
fmt.Fprintln(os.Stderr, err)
15-
os.Exit(1)
16-
}
17-
logrus.SetOutput(dockerCli.Err())
18-
cmd := newRootCmd(dockerCli)
19-
if err := cmd.Execute(); err != nil {
20-
os.Exit(1)
21-
}
13+
plugin.Run(func(dockerCli command.Cli) *cobra.Command {
14+
return app.NewRootCmd("app", dockerCli)
15+
}, manager.Metadata{
16+
SchemaVersion: "0.1.0",
17+
Vendor: "Docker Inc.",
18+
Version: internal.Version,
19+
})
2220
}

0 commit comments

Comments
 (0)