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

Commit 0ec4226

Browse files
Merge pull request #392 from mikeparker/bundle-external-files
Add attachments (extra files) into the package
2 parents e17c17f + 64ed78b commit 0ec4226

16 files changed

Lines changed: 364 additions & 53 deletions

File tree

e2e/commands_test.go

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"io/ioutil"
66
"os"
77
"path/filepath"
8+
"strings"
89
"testing"
910

1011
"github.com/docker/app/internal"
@@ -260,8 +261,8 @@ func TestSplitMerge(t *testing.T) {
260261
result = icmd.RunCommand(dockerApp, "inspect", "remerged").Assert(t, icmd.Success)
261262
assert.Assert(t, golden.String(result.Combined(), "envvariables-inspect.golden"))
262263
// test inplace
263-
icmd.RunCommand(dockerApp, "merge", "split")
264-
icmd.RunCommand(dockerApp, "split", "split")
264+
icmd.RunCommand(dockerApp, "merge", "split").Assert(t, icmd.Success)
265+
icmd.RunCommand(dockerApp, "split", "split").Assert(t, icmd.Success)
265266
}
266267

267268
func TestURL(t *testing.T) {
@@ -316,3 +317,38 @@ func testFork(registry string) func(*testing.T) {
316317
assert.Assert(t, golden.Bytes(metadata2, "expected-fork-metadata-no-rename.golden"))
317318
}
318319
}
320+
321+
func TestAttachmentsWithRegistry(t *testing.T) {
322+
r := startRegistry(t)
323+
defer r.Stop(t)
324+
registry := r.GetAddress(t)
325+
326+
dir := fs.NewDir(t, "testattachments",
327+
fs.WithDir("attachments.dockerapp", fs.FromDir("testdata/attachments.dockerapp")),
328+
)
329+
defer dir.Remove()
330+
331+
icmd.RunCommand(dockerApp, "push", "--namespace", registry+"/acmecorp", dir.Join("attachments.dockerapp")).Assert(t, icmd.Success)
332+
333+
// inspect will run the core pull code too
334+
result := icmd.RunCommand(dockerApp, "inspect", registry+"/acmecorp/attachments.dockerapp:0.1.0")
335+
336+
result.Assert(t, icmd.Success)
337+
resultOutput := result.Combined()
338+
339+
assert.Assert(t, strings.Contains(resultOutput, "config.cfg"))
340+
assert.Assert(t, strings.Contains(resultOutput, "nesteddir/config2.cfg"))
341+
assert.Assert(t, strings.Contains(resultOutput, "nesteddir/nested2/nested3/config3.cfg"))
342+
343+
// Test forking with external files
344+
tempDir := fs.NewDir(t, "dockerapptest")
345+
defer tempDir.Remove()
346+
347+
icmd.RunCommand(dockerApp, "fork", registry+"/acmecorp/attachments.dockerapp:0.1.0",
348+
"-p", tempDir.Path()).Assert(t, icmd.Success)
349+
externalFile := golden.Get(t, tempDir.Join("attachments.dockerapp", "config.cfg"))
350+
assert.Assert(t, golden.Bytes(externalFile, filepath.Join("attachments.dockerapp", "config.cfg")))
351+
352+
nestedAttachment := golden.Get(t, tempDir.Join("attachments.dockerapp", "nesteddir", "config2.cfg"))
353+
assert.Assert(t, golden.Bytes(nestedAttachment, filepath.Join("attachments.dockerapp", "nesteddir", "config2.cfg")))
354+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Contents of config.cfg
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
version: "3.7"
2+
services:
3+
front:
4+
image: nginx:${myapp.nginx_version}
5+
deploy:
6+
replicas: ${myapp.nginx_replicas}
7+
debug:
8+
image: busybox:latest
9+
ports:
10+
- $aport
11+
- $sport:$dport
12+
privileged: ${privileged}
13+
read_only: $read_only
14+
tty: $tty
15+
stdin_open: $stdin_open
16+
deploy:
17+
resources:
18+
limits:
19+
memory: $memory
20+
healthcheck:
21+
test: ["/ping", "debug"]
22+
interval: 2m
23+
timeout: $timeout
24+
monitor:
25+
image: busybox:latest
26+
command: monitor --source ${app.name}-${app.version} $$dollar
27+
x-enabled: "! ${myapp.debug}"
28+
app-watcher:
29+
image: $watcher.image
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: 0.1.0
2+
name: myapp
3+
description: ""
4+
maintainers:
5+
- name: bearclaw
6+
email: bearclaw@bearclaw.com
7+
- name: bob
8+
email: bob@bob.com
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Contents of nesteddir/config2.cfg
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Contents of nesteddir/nested2/nested3/config3.cfg
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
privileged: false
2+
myapp:
3+
debug: false
4+
nginx_version: latest
5+
nginx_replicas: 2
6+
watcher:
7+
image: watcher:latest
8+
read_only: true
9+
stdin_open: true
10+
tty: true
11+
aport: 10000
12+
sport: 11000
13+
dport: 12000
14+
memory: '100000000'
15+
timeout: 10s

internal/inspect/inspect.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/docker/app/types"
1212
"github.com/docker/app/types/settings"
1313
composetypes "github.com/docker/cli/cli/compose/types"
14+
units "github.com/docker/go-units"
1415
)
1516

1617
// Inspect dumps the metadata of an app
@@ -65,6 +66,15 @@ func Inspect(out io.Writer, app *types.App, argSettings map[string]string) error
6566
}
6667
}, "Setting", "Value")
6768

69+
// Add Attachments section
70+
attachments := app.Attachments()
71+
printSection(out, len(attachments), func(w io.Writer) {
72+
for _, file := range attachments {
73+
sizeString := units.HumanSize(float64(file.Size()))
74+
fmt.Fprintf(w, "%s\t%s\n", file.Path(), sizeString)
75+
}
76+
}, "Attachment", "Size")
77+
6878
return nil
6979
}
7080

internal/inspect/inspect_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ description: "this is sparta !"`),
9191
fs.WithFile(internal.SettingsFileName, `
9292
port: 8080
9393
text: hello`),
94+
fs.WithFile("config.cfg", "something"),
9495
),
9596
)
9697
defer dir.Remove()

internal/inspect/testdata/inspect-full.golden

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@ Settings (2) Value
2424
------------ -----
2525
port 8080
2626
text hello
27+
28+
Attachment (1) Size
29+
-------------- ----
30+
config.cfg 9B

0 commit comments

Comments
 (0)