Skip to content
This repository has been archived by the owner on Jun 13, 2021. It is now read-only.

Transform docker-app as a docker-cli plugin #469

Merged
merged 12 commits into from
Mar 8, 2019
Merged
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/chris-crone/cli . && git checkout d6bfd7e5592dad85969516c131d33910fa5ebd58
# 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
#RUN git clone https://github.com/docker/cli.git . && git checkout 8ddde26af67f9a76734a1676c635e48da4fe8584

RUN make cross binary && \
cp build/docker-linux-amd64 /usr/bin/docker

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

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

# FIXME(vdemeester) change from docker-app to dev once buildkit is merged in moby/docker
FROM cross AS e2e-cross
ARG EXPERIMENTAL="off"
ARG TAG="unknown"
Expand Down
19 changes: 13 additions & 6 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ required = ["github.com/wadey/gocovmerge"]
source = "github.com/simonferquel/containerd"
revision = "a89234684e5884e51ba195bdb16b1c6952d17f11"

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

[[override]]
name = "github.com/deislabs/duffle"
Expand Down
10 changes: 6 additions & 4 deletions Jenkinsfile.baguette
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ pipeline {
options {
skipDefaultCheckout(true)
}
environment{
DOCKER_BUILDKIT=true
}

stages {
stage('Build') {
Expand Down Expand Up @@ -82,6 +79,8 @@ pipeline {
parallel {
stage("Unit Coverage") {
environment {
DOCKERAPP_BINARY = '../e2e/coverage-bin'
DOCKERCLI_BINARY = '../docker-linux'
CODECOV_TOKEN = credentials('jenkins-codecov-token')
}
agent {
Expand Down Expand Up @@ -148,6 +147,7 @@ pipeline {
dir('e2e'){
unstash "e2e"
}
sh './docker-linux version'
sh './docker-app-e2e-linux -test.v --e2e-path=e2e'
}
}
Expand Down Expand Up @@ -180,6 +180,7 @@ pipeline {
dir('e2e'){
unstash "e2e"
}
sh './docker-darwin version'
sh './docker-app-e2e-darwin -test.v --e2e-path=e2e'
}
}
Expand All @@ -201,11 +202,12 @@ pipeline {
steps {
dir('src/github.com/docker/app') {
checkout scm
unstash "binaries"
sh './docker-windows.exe version'
dir('_build') {
unstash "invocation-image"
bat 'docker load -i invocation-image.tar'
}
unstash "binaries"
dir('examples') {
unstash "examples"
}
Expand Down
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,22 @@ check_go_env:
@test $$(go list) = "$(PKG_NAME)" || \
(echo "Invalid Go environment - The local directory structure must match: $(PKG_NAME)" && false)

cross: bin/$(BIN_NAME)-linux bin/$(BIN_NAME)-darwin bin/$(BIN_NAME)-windows.exe ## cross-compile binaries (linux, darwin, windows)
cross: cross-plugin cross-standalone ## cross-compile binaries (linux, darwin, windows)

cross-plugin: bin/$(BIN_NAME)-linux bin/$(BIN_NAME)-darwin bin/$(BIN_NAME)-windows.exe

cross-standalone: bin/${BIN_STANDALONE_NAME}-linux bin/${BIN_STANDALONE_NAME}-darwin bin/${BIN_STANDALONE_NAME}-windows.exe

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

.PHONY: bin/${BIN_STANDALONE_NAME}-windows
bin/${BIN_STANDALONE_NAME}-%.exe bin/${BIN_STANDALONE_NAME}-%: cmd/${BIN_STANDALONE_NAME} check_go_env
GOOS=$* $(GO_BUILD) -o $@ ./$<

.PHONY: bin/${BIN_STANDALONE_NAME}
bin/${BIN_STANDALONE_NAME}: cmd/${BIN_STANDALONE_NAME} check_go_env
$(GO_BUILD) -o $@$(EXEC_EXT) ./$<

.PHONY: bin/$(BIN_NAME)-e2e-windows
bin/$(BIN_NAME)-e2e-%.exe bin/$(BIN_NAME)-e2e-%: e2e bin/$(BIN_NAME)-%
GOOS=$* $(GO_TEST) -c -o $@ ./e2e/
Expand Down
60 changes: 48 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ services:
- 5678:5678
```

With `docker-app` installed let's create an Application Package based on this Compose file:
With `docker-app` [installed](#installation) let's create an Application Package based on this Compose file:

```bash
$ docker-app init --single-file hello
Expand Down Expand Up @@ -187,31 +187,67 @@ Removing network hello_default
## Installation

Pre-built binaries are available on [GitHub releases](https://github.com/docker/app/releases) for Windows, Linux and macOS.
Each tarball contains two binaries:
- `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
Docker CLI
- `docker-app-standalone-{linux|darwin|windows.exe}` which is docker-app as a standalone utility

To use the `docker-app` plugin, just type `docker app` instead of `docker-app` and all the examples will work the same way:
```bash
$ docker app version
Version: v0.8
Git commit: XXX
Built: Wed Feb 27 12:37:06 2019
OS/Arch: darwin/amd64
Experimental: off
Renderers: none

$ docker-app version
Version: v0.8
Git commit: XXX
Built: Wed Feb 27 12:37:06 2019
OS/Arch: darwin/amd64
Experimental: off
Renderers: none
```

### 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"
Copy link
Member

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.

tar xf "/tmp/docker-app-${OSTYPE}.tar.gz" -C /tmp/
install -b "/tmp/docker-app-${OSTYPE}" /usr/local/bin/docker-app
```

To install `docker-app` as a standalone:
```bash
install -b "/tmp/docker-app-standalone-${OSTYPE}" /usr/local/bin/docker-app
```

To install `docker-app` as a docker cli plugin:
```bash
mkdir -p ~/.docker/cli-plugins && cp "/tmp/docker-app-plugin-${OSTYPE}" ~/.docker/cli-plugins/docker-app
```

### Windows
```powershell
function Expand-Tar($tarFile, $dest) {

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

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

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

## Single file or directory representation

Expand Down
50 changes: 50 additions & 0 deletions cmd/docker-app-standalone/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package main

import (
"fmt"
"os"

"github.com/spf13/cobra"
"github.com/spf13/pflag"

"github.com/docker/app/internal"
app "github.com/docker/app/internal/commands"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
cliflags "github.com/docker/cli/cli/flags"
"github.com/sirupsen/logrus"
)

func main() {
dockerCli, err := command.NewDockerCli()
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
logrus.SetOutput(dockerCli.Err())

cmd := app.NewRootCmd("docker-app", dockerCli)
configureRootCmd(cmd, dockerCli)

if err := cmd.Execute(); err != nil {
os.Exit(1)
}
}

func configureRootCmd(cmd *cobra.Command, dockerCli *command.DockerCli) {
var (
opts *cliflags.ClientOptions
flags *pflag.FlagSet
)

cmd.SilenceUsage = true
cmd.TraverseChildren = true
cmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
opts.Common.SetDefaultOptions(flags)
return dockerCli.Initialize(opts)
}
cmd.Version = fmt.Sprintf("%s, build %s", internal.Version, internal.GitCommit)

opts, flags, _ = cli.SetupRootCommand(cmd)
flags.BoolP("version", "v", false, "Print version information")
cmd.SetVersionTemplate("docker-app version {{.Version}}\n")
}
26 changes: 12 additions & 14 deletions cmd/docker-app/main.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package main

import (
"fmt"
"os"

"github.com/docker/app/internal"
app "github.com/docker/app/internal/commands"
"github.com/docker/cli/cli-plugins/manager"
"github.com/docker/cli/cli-plugins/plugin"
"github.com/docker/cli/cli/command"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

func main() {
dockerCli, err := command.NewDockerCli()
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
logrus.SetOutput(dockerCli.Err())
cmd := newRootCmd(dockerCli)
if err := cmd.Execute(); err != nil {
os.Exit(1)
}
plugin.Run(func(dockerCli command.Cli) *cobra.Command {
return app.NewRootCmd("app", dockerCli)
}, manager.Metadata{
SchemaVersion: "0.1.0",
Vendor: "Docker Inc.",
Version: internal.Version,
})
}
Loading