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

Commit 941df3f

Browse files
rumplsilvin-lubecki
authored andcommitted
CNAB Status action is no more a default action (#451)
* CNAB Status action is no more a default action * Added a complete e2e test. Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
1 parent 23e884d commit 941df3f

20 files changed

Lines changed: 337 additions & 39 deletions

File tree

BUILDING.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,11 @@ directly against `go test` to run root-requiring tests.
103103
# run the test <TEST_NAME>:
104104
go test -v -run "<TEST_NAME>" .
105105
```
106+
107+
**NOTE** if the tests fail with an error message like `"Error: manifest
108+
for docker/cnab-app-base:v0.6.0-68-g3ae57efdb6-dirty not found"`, it means
109+
you forgot to rebuild the base invocation image, simply run
110+
111+
```sh
112+
$ make -f docker.Makefile invocation-image
113+
```

Dockerfile

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
ARG ALPINE_VERSION=3.8
22
ARG GO_VERSION=1.11.0
33

4-
FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS build
5-
ARG DOCKERCLI_VERSION=18.03.1-ce
6-
ARG DOCKERCLI_CHANNEL=edge
7-
RUN apk add --no-cache \
8-
bash \
9-
make\
10-
git \
11-
curl \
12-
util-linux \
13-
coreutils
14-
RUN curl -Ls https://download.docker.com/linux/static/$DOCKERCLI_CHANNEL/x86_64/docker-$DOCKERCLI_VERSION.tgz | \
15-
tar -xz docker/docker && \
16-
mv docker/docker /usr/bin/docker
4+
FROM dockercore/golang-cross:1.11.5@sha256:17a7e0f158521c50316a0d0c1ab1f6a75350b4d82e7ef03c98bcfbdf04feb4f3 AS build
5+
ENV DISABLE_WARN_OUTSIDE_CONTAINER=1
6+
7+
RUN apt-get install -y -q --no-install-recommends \
8+
coreutils \
9+
util-linux \
10+
uuid-runtime
11+
12+
WORKDIR /go/src/github.com/docker/cli
13+
14+
RUN git clone https://github.com/docker/cli.git .
15+
RUN make cross binary && \
16+
cp build/docker-linux-amd64 /usr/bin/docker
1717

1818
WORKDIR /go/src/github.com/docker/app/
1919

@@ -32,13 +32,15 @@ COPY . .
3232
# FIXME(vdemeester) change from docker-app to dev once buildkit is merged in moby/docker
3333
FROM dev AS cross
3434
ARG EXPERIMENTAL="off"
35-
RUN make EXPERIMENTAL=${EXPERIMENTAL} cross
35+
ARG TAG="unknown"
36+
RUN make EXPERIMENTAL=${EXPERIMENTAL} TAG=${TAG} cross
3637

3738
# FIXME(vdemeester) change from docker-app to dev once buildkit is merged in moby/docker
3839
FROM cross AS e2e-cross
3940
ARG EXPERIMENTAL="off"
41+
ARG TAG="unknown"
4042
# Run e2e tests
41-
RUN make EXPERIMENTAL=${EXPERIMENTAL} e2e-cross
43+
RUN make EXPERIMENTAL=${EXPERIMENTAL} TAG=${TAG} e2e-cross
4244

4345
# builder of invocation image entrypoint
4446
FROM build AS invocation-build

Jenkinsfile

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ pipeline {
1919
steps {
2020
dir('src/github.com/docker/app') {
2121
checkout scm
22-
sh 'make -f docker.Makefile BUILD_TAG=$BUILD_TAG lint'
23-
sh 'make -f docker.Makefile BUILD_TAG=$BUILD_TAG vendor'
22+
sh 'make -f docker.Makefile lint'
23+
sh 'make -f docker.Makefile vendor'
2424
}
2525
}
2626
post {
@@ -38,7 +38,7 @@ pipeline {
3838
script {
3939
try {
4040
checkout scm
41-
sh 'make -f docker.Makefile BUILD_TAG=$BUILD_TAG cross e2e-cross tars'
41+
sh 'make -f docker.Makefile cli-cross cross e2e-cross tars'
4242
dir('bin') {
4343
stash name: 'binaries'
4444
}
@@ -53,7 +53,7 @@ pipeline {
5353
archiveArtifacts 'bin/*.tar.gz'
5454
}
5555
} finally {
56-
def clean_images = /docker image ls --format="{{.ID}}" '*$BUILD_TAG*' | xargs docker image rm -f/
56+
def clean_images = /docker image ls --format="{{.Repository}}:{{.Tag}}" '*$BUILD_TAG*' | xargs docker image rm -f/
5757
sh clean_images
5858
}
5959
}
@@ -72,7 +72,7 @@ pipeline {
7272
steps {
7373
dir('src/github.com/docker/app') {
7474
checkout scm
75-
sh 'make -f docker.Makefile BUILD_TAG=$BUILD_TAG save-invocation-image'
75+
sh 'make -f docker.Makefile save-invocation-image'
7676
dir('_build') {
7777
stash name: 'invocation-image', includes: 'invocation-image.tar'
7878
}
@@ -98,7 +98,11 @@ pipeline {
9898
steps {
9999
dir('src/github.com/docker/app') {
100100
checkout scm
101-
sh 'make BUILD_TAG=$BUILD_TAG -f docker.Makefile coverage'
101+
dir('_build') {
102+
unstash "invocation-image"
103+
sh 'docker load -i invocation-image.tar'
104+
}
105+
sh 'make -f docker.Makefile coverage'
102106
archiveArtifacts '_build/ci-cov/all.out'
103107
archiveArtifacts '_build/ci-cov/coverage.html'
104108
}
@@ -116,7 +120,11 @@ pipeline {
116120
steps {
117121
dir('src/github.com/docker/app') {
118122
checkout scm
119-
sh 'make EXPERIMENTAL=on BUILD_TAG=$BUILD_TAG -f docker.Makefile coverage'
123+
dir('_build') {
124+
unstash "invocation-image"
125+
sh 'docker load -i invocation-image.tar'
126+
}
127+
sh 'make EXPERIMENTAL=on -f docker.Makefile coverage'
120128
}
121129
}
122130
post {
@@ -135,7 +143,7 @@ pipeline {
135143
dir("bin") {
136144
unstash "binaries"
137145
}
138-
sh 'make BUILD_TAG=$BUILD_TAG -f docker.Makefile gradle-test'
146+
sh 'make -f docker.Makefile gradle-test'
139147
}
140148
}
141149
post {
@@ -150,6 +158,7 @@ pipeline {
150158
}
151159
environment {
152160
DOCKERAPP_BINARY = '../docker-app-linux'
161+
DOCKERCLI_BINARY = '../docker-linux'
153162
}
154163
steps {
155164
dir('src/github.com/docker/app') {

Jenkinsfile.baguette

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ pipeline {
2424
script {
2525
try {
2626
checkout scm
27-
sh 'make -f docker.Makefile BUILD_TAG=$BUILD_TAG lint'
28-
sh 'make -f docker.Makefile BUILD_TAG=$BUILD_TAG cross e2e-cross tars'
27+
sh 'make -f docker.Makefile lint'
28+
sh 'make -f docker.Makefile cli-cross cross e2e-cross tars'
2929
dir('bin') {
3030
stash name: 'binaries'
3131
}
@@ -40,7 +40,7 @@ pipeline {
4040
}
4141
archiveArtifacts 'bin/*.tar.gz'
4242
} finally {
43-
def clean_images = /docker image ls --format="{{.ID}}" '*$BUILD_TAG*' | xargs docker image rm -f/
43+
def clean_images = /docker image ls --format="{{.Repository}}:{{.Tag}}" '*$BUILD_TAG*' | xargs docker image rm -f/
4444
sh clean_images
4545
}
4646
}
@@ -59,7 +59,7 @@ pipeline {
5959
steps {
6060
dir('src/github.com/docker/app') {
6161
checkout scm
62-
sh 'make -f docker.Makefile BUILD_TAG=$BUILD_TAG save-invocation-image'
62+
sh 'make -f docker.Makefile save-invocation-image'
6363
dir('_build') {
6464
stash name: 'invocation-image', includes: 'invocation-image.tar'
6565
archiveArtifacts 'invocation-image.tar'
@@ -104,7 +104,7 @@ pipeline {
104104
dir("bin") {
105105
unstash "binaries"
106106
}
107-
sh 'make -f docker.Makefile BUILD_TAG=$BUILD_TAG gradle-test'
107+
sh 'make -f docker.Makefile gradle-test'
108108
}
109109
}
110110
post {
@@ -119,6 +119,7 @@ pipeline {
119119
}
120120
environment {
121121
DOCKERAPP_BINARY = '../docker-app-linux'
122+
DOCKERCLI_BINARY = '../docker-linux'
122123
}
123124
steps {
124125
dir('src/github.com/docker/app') {
@@ -150,6 +151,7 @@ pipeline {
150151
}
151152
environment {
152153
DOCKERAPP_BINARY = '../docker-app-darwin'
154+
DOCKERCLI_BINARY = '../docker-darwin'
153155
}
154156
steps {
155157
dir('src/github.com/docker/app') {
@@ -181,6 +183,7 @@ pipeline {
181183
}
182184
environment {
183185
DOCKERAPP_BINARY = '../docker-app-windows.exe'
186+
DOCKERCLI_BINARY = '../docker-windows.exe'
184187
}
185188
steps {
186189
dir('src/github.com/docker/app') {
@@ -227,7 +230,7 @@ pipeline {
227230
unstash "invocation-image"
228231
sh 'docker load -i invocation-image.tar'
229232
}
230-
sh 'make -f docker.Makefile BUILD_TAG=$BUILD_TAG push-invocation-image'
233+
sh 'make -f docker.Makefile push-invocation-image'
231234
}
232235
unstash 'artifacts'
233236
echo "Releasing $TAG_NAME"

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,9 @@ More examples are available in the [examples](examples) directory.
150150
## CNAB
151151

152152
Under the hood `docker-app` is CNAB compliant. It generates a CNAB from your application source and is able to install and manage any other CNAB too.
153-
CNAB specifies four actions which `docker-app` provides as commands:
153+
CNAB specifies three actions which `docker-app` provides as commands:
154154
- `install`
155155
- `upgrade`
156-
- `status`
157156
- `uninstall`
158157

159158
**Note**: These commands need a Docker Context so that `docker-app` knows which endpoint and orchestrator to target.

cmd/docker-app/status.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/deislabs/duffle/pkg/utils/crud"
88
"github.com/docker/cli/cli"
99
"github.com/docker/cli/cli/command"
10+
"github.com/pkg/errors"
1011
"github.com/spf13/cobra"
1112
)
1213

@@ -48,8 +49,10 @@ func runStatus(dockerCli command.Cli, claimName string, opts credentialOptions)
4849
if err := credentials.Validate(creds, c.Bundle.Credentials); err != nil {
4950
return err
5051
}
51-
status := &action.Status{
52+
status := &action.RunCustom{
53+
Action: "status",
5254
Driver: driverImpl,
5355
}
54-
return status.Run(&c, creds, dockerCli.Out())
56+
err = status.Run(&c, creds, dockerCli.Out())
57+
return errors.Wrap(err, "Status failed")
5558
}

docker.Makefile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ LINT_IMAGE_NAME := $(BIN_NAME)-lint:$(BUILD_TAG)
44
DEV_IMAGE_NAME := $(BIN_NAME)-dev:$(BUILD_TAG)
55
BIN_IMAGE_NAME := $(BIN_NAME)-bin:$(BUILD_TAG)
66
CROSS_IMAGE_NAME := $(BIN_NAME)-cross:$(BUILD_TAG)
7+
CLI_IMAGE_NAME := $(BIN_NAME)-cli:$(BUILD_TAG)
78
E2E_CROSS_IMAGE_NAME := $(BIN_NAME)-e2e-cross:$(BUILD_TAG)
89
GRADLE_IMAGE_NAME := $(BIN_NAME)-gradle:$(BUILD_TAG)
910

1011
BIN_CTNR_NAME := $(BIN_NAME)-bin-$(TAG)
12+
CLI_CNTR_NAME := $(BIN_NAME)-cli-$(TAG)
1113
CROSS_CTNR_NAME := $(BIN_NAME)-cross-$(TAG)
1214
E2E_CROSS_CTNR_NAME := $(BIN_NAME)-e2e-cross-$(TAG)
1315
COV_CTNR_NAME := $(BIN_NAME)-cov-$(TAG)
@@ -44,6 +46,17 @@ cross: create_bin ## cross-compile binaries (linux, darwin, windows)
4446
@$(call chmod,+x,bin/$(BIN_NAME)-darwin)
4547
@$(call chmod,+x,bin/$(BIN_NAME)-windows.exe)
4648

49+
cli-cross: create_bin
50+
docker build $(BUILD_ARGS) --target=build -t $(CLI_IMAGE_NAME) .
51+
docker create --name $(CLI_CNTR_NAME) $(CLI_IMAGE_NAME) noop
52+
docker cp $(CLI_CNTR_NAME):/go/src/github.com/docker/cli/build/docker-linux-amd64 bin/docker-linux
53+
docker cp $(CLI_CNTR_NAME):/go/src/github.com/docker/cli/build/docker-darwin-amd64 bin/docker-darwin
54+
docker cp $(CLI_CNTR_NAME):/go/src/github.com/docker/cli/build/docker-windows-amd64 bin/docker-windows.exe
55+
docker rm $(CLI_CNTR_NAME)
56+
@$(call chmod,+x,bin/docker-linux)
57+
@$(call chmod,+x,bin/docker-darwin)
58+
@$(call chmod,+x,bin/docker-windows.exe)
59+
4760
e2e-cross: create_bin
4861
docker build $(BUILD_ARGS) --target=e2e-cross -t $(E2E_CROSS_IMAGE_NAME) .
4962
docker create --name $(E2E_CROSS_CTNR_NAME) $(E2E_CROSS_IMAGE_NAME) noop
@@ -113,4 +126,4 @@ push-invocation-image:
113126
help: ## this help
114127
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort
115128

116-
.PHONY: lint test-e2e test-unit test cross e2e-cross coverage gradle-test shell build_dev_image tars vendor schemas help invocation-image save-invocation-image push-invocation-image
129+
.PHONY: lint test-e2e test-unit test cli-cross cross e2e-cross coverage gradle-test shell build_dev_image tars vendor schemas help invocation-image save-invocation-image push-invocation-image

e2e/cnab_test.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package e2e
2+
3+
import (
4+
"fmt"
5+
"path"
6+
"runtime"
7+
"testing"
8+
9+
"gotest.tools/assert"
10+
is "gotest.tools/assert/cmp"
11+
"gotest.tools/fs"
12+
"gotest.tools/icmd"
13+
)
14+
15+
func TestCallCustomStatusAction(t *testing.T) {
16+
testCases := []struct {
17+
name string
18+
exitCode int
19+
expectedOutput string
20+
cnab string
21+
}{
22+
{
23+
name: "validCustomStatusAction",
24+
exitCode: 0,
25+
expectedOutput: "Status action",
26+
cnab: "cnab-with-status",
27+
},
28+
{
29+
name: "missingCustomStatusAction",
30+
exitCode: 1,
31+
expectedOutput: "Error: Status failed: action not defined for bundle",
32+
cnab: "cnab-without-status",
33+
},
34+
}
35+
36+
for _, testCase := range testCases {
37+
t.Run(testCase.name, func(t *testing.T) {
38+
tmpDir := fs.NewDir(t, t.Name())
39+
defer tmpDir.Remove()
40+
testDir := path.Join("testdata", testCase.cnab)
41+
cmd := icmd.Cmd{
42+
Env: []string{fmt.Sprintf("DUFFLE_HOME=%s", tmpDir.Path())},
43+
}
44+
45+
// We need to explicitly set the SYSTEMROOT on windows
46+
// otherwise we get the error:
47+
// "panic: failed to read random bytes: CryptAcquireContext: Provider DLL failed to initialize correctly."
48+
// See: https://github.com/golang/go/issues/25210
49+
if runtime.GOOS == "windows" {
50+
cmd.Env = append(cmd.Env, `SYSTEMROOT=C:\WINDOWS`)
51+
}
52+
// Build CNAB invocation image
53+
cmd.Command = []string{"docker", "build", "-f", path.Join(testDir, "cnab", "build", "Dockerfile"), "-t", fmt.Sprintf("e2e/%s:v0.1.0", testCase.cnab), testDir}
54+
icmd.RunCmd(cmd).Assert(t, icmd.Success)
55+
56+
// docker-app install
57+
cmd.Command = []string{dockerApp, "install", path.Join(testDir, "bundle.json"), "--name", testCase.name}
58+
icmd.RunCmd(cmd).Assert(t, icmd.Success)
59+
60+
// docker-app uninstall
61+
defer func() {
62+
cmd.Command = []string{dockerApp, "uninstall", testCase.name}
63+
icmd.RunCmd(cmd).Assert(t, icmd.Success)
64+
}()
65+
66+
// docker-app status
67+
cmd.Command = []string{dockerApp, "status", testCase.name}
68+
result := icmd.RunCmd(cmd)
69+
result.Assert(t, icmd.Expected{ExitCode: testCase.exitCode})
70+
assert.Assert(t, is.Contains(result.Combined(), testCase.expectedOutput))
71+
})
72+
}
73+
}

0 commit comments

Comments
 (0)