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

Add attachments (extra files) into the package #392

Merged
merged 19 commits into from
Sep 26, 2018

Conversation

mikeparker
Copy link
Contributor

@mikeparker mikeparker commented Sep 21, 2018

- What I did
Added ability to attach files to a docker-app package (e.g. config files) including:

  • push will push everything inside /yourapp.dockerapp/ directory
  • pull will correctly pull those files down
  • inspect will show those files in a new output section called Attachments and will list the filesize
  • fork will pull those files down also

Misc

  • If the image is somehow pushed with references to files beyond the parent folder (parent of parent, i.e. ../../../bin/something etc, those files will be ignored
  • Single file format is not supported (split/merge have not been changed)

NOTE: The following have not been done (yet)

  • Filesize limit
  • File exclusion list

- Description for the changelog
Added ability to attach files to a docker-app package (e.g. config files)

- A picture of a cute animal (not mandatory but encouraged)

image

@mikeparker mikeparker force-pushed the bundle-external-files branch 2 times, most recently from b2e0356 to 6dc5bd3 Compare September 21, 2018 13:12
// Check we aren't doing ./../../../ etc in the path
fullFilepath := filepath.Join(appDir, convertedFilepath)
_, err := filepath.Rel(appDir, fullFilepath)
if err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is basically the same in fork.go and registry.go, there is a minor difference whereby fork alters the metadata file. Should I extract the duplication?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep I guess you can try yes 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, i've pushed an attempt at this. There were 2 options: Inject the metadata editing code into the extracted function via a func parameter (ugly), or extract all the files onto disk once then update the metadata file after extraction. I went for the latter as it seemed cleaner, however this is slightly slower. Thoughts?

externalFiles := app.ExternalFilePaths()
printSection(out, len(externalFiles), func(w io.Writer) {
for _, name := range externalFiles {
fmt.Fprintln(w, name) // and info.Size() ?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the comment?

@mikeparker
Copy link
Contributor Author

I'd be interested in ideas about what to call the files to store (not the docker-compose.yml etc)

  • ExternalFiles
  • AdditionalFiles
  • ExtraFiles
  • BundledFiles

I can't think of the right name.

types/types.go Outdated Show resolved Hide resolved
@mikeparker
Copy link
Contributor Author

I added the filesize output to inspect, and renamed External Files -> Attachments

@mikeparker mikeparker changed the title Add ability to bundle external files into the package Add ability to bundle attached files into the package Sep 24, 2018
@mikeparker mikeparker changed the title Add ability to bundle attached files into the package Add attachments (extra files) into the package Sep 24, 2018
@mikeparker
Copy link
Contributor Author

mikeparker commented Sep 24, 2018

  • Add unit to size column
  • Add tests around size column
  • Refactor away duplication between fork and push code
  • Consider what to do about docker/go-units and dustin/go-humanize libs

@docker docker deleted a comment from GordonTheTurtle Sep 24, 2018
Copy link
Member

@chris-crone chris-crone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of minor things

internal/packager/registry.go Outdated Show resolved Hide resolved
internal/packager/registry.go Outdated Show resolved Hide resolved
e2e/testdata/attachments.dockerapp/nesteddir/config2.cfg Outdated Show resolved Hide resolved
internal/packager/registry.go Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Sep 24, 2018

Codecov Report

Merging #392 into master will decrease coverage by 3.25%.
The diff coverage is 68.04%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #392      +/-   ##
==========================================
- Coverage   61.29%   58.04%   -3.26%     
==========================================
  Files          59       59              
  Lines        3462     3246     -216     
==========================================
- Hits         2122     1884     -238     
- Misses       1082     1095      +13     
- Partials      258      267       +9
Impacted Files Coverage Δ
loader/loader.go 78% <100%> (-7.92%) ⬇️
internal/inspect/inspect.go 87.01% <100%> (-2.42%) ⬇️
internal/packager/fork.go 68.62% <35.71%> (-17.09%) ⬇️
internal/packager/registry.go 70.12% <64%> (-12.57%) ⬇️
types/types.go 89.51% <85.18%> (-5.52%) ⬇️
cmd/docker-app/split.go 65.21% <0%> (-24.07%) ⬇️
cmd/docker-app/merge.go 58.82% <0%> (-11.45%) ⬇️
types/settings/settings.go 92.06% <0%> (-4.77%) ⬇️
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e17c17f...64ed78b. Read the comment docs.

internal/packager/fork.go Outdated Show resolved Hide resolved
…t has the external file in

Signed-off-by: Mike Parker <michael.parker@docker.com>
…ernal files from a .dockerapp. Logic will exclude the core 3 files from the root dir.

Test with files in nested directories being reported correctly
Test for sorting files alphabetically
Signed-off-by: Mike Parker <michael.parker@docker.com>
…the inspect output; add external files to the loader

Signed-off-by: Mike Parker <michael.parker@docker.com>
…; delete comments

Signed-off-by: Mike Parker <michael.parker@docker.com>
Signed-off-by: Mike Parker <michael.parker@docker.com>
Signed-off-by: Mike Parker <michael.parker@docker.com>
…in the payload

Signed-off-by: Mike Parker <michael.parker@docker.com>
…pect

Signed-off-by: Mike Parker <michael.parker@docker.com>
Signed-off-by: Mike Parker <michael.parker@docker.com>
Signed-off-by: Mike Parker <michael.parker@docker.com>
…payload and in the app object in memory. Translate only when working with the filesystem.

Fix other nits.

Signed-off-by: Mike Parker <michael.parker@docker.com>
Signed-off-by: Mike Parker <michael.parker@docker.com>
…ebase.

Signed-off-by: Mike Parker <michael.parker@docker.com>
Signed-off-by: Mike Parker <michael.parker@docker.com>
…ery config.cfg to be different

Signed-off-by: Mike Parker <michael.parker@docker.com>
Signed-off-by: Mike Parker <michael.parker@docker.com>
Copy link
Member

@chris-crone chris-crone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple questions but looking good

internal/packager/fork.go Outdated Show resolved Hide resolved
internal/packager/fork.go Outdated Show resolved Hide resolved
appPath := filepath.Join(outputDir, internal.DirNameFromAppName(name))
if err := os.MkdirAll(appPath, 0755); err != nil {
appDir := filepath.Join(outputDir, internal.DirNameFromAppName(name))
if err := os.MkdirAll(appDir, 0755); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this MkdirAll should be changed to a Mkdir. I know it was like this before but it means that you can run docker-app fork -p /tmp/path/does/not/exist ccrone/hello-world.dockerapp:0.1.0 and it will create all the directories from /tmp/ onwards.

I would be OK to err out if the parent directory doesn't exist.

@silvin-lubecki WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should do that in a follow-up, so we can focus on it separately.

internal/packager/registry.go Outdated Show resolved Hide resolved
internal/packager/registry.go Outdated Show resolved Hide resolved
internal/packager/registry.go Outdated Show resolved Hide resolved
types/types.go Outdated Show resolved Hide resolved
types/types.go Outdated Show resolved Hide resolved
Signed-off-by: Mike Parker <michael.parker@docker.com>
…ious refactor)

Signed-off-by: Mike Parker <michael.parker@docker.com>
@mikeparker
Copy link
Contributor Author

I''ve decided to not do anything about the docker/go-units vs dustin/humanize vs tonistiigi/units.

The reasons are:

  1. What we've got works for now
  2. Making the library usage consistent across CLI and docker-app is a larger piece of work
  3. humanize doesnt have exactly the same format of output (35MB vs 35 MB) which (according to Sebastiaan) allowed using linux tools to sort properly, but also caused some breakage for other users so we'd either need to wrap the calls with an adapter, extend the other library to support no-spaces formatting, or deal with the spaces-formatting globally.

Copy link
Member

@chris-crone chris-crone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit but otherwise LGTM

@@ -163,8 +163,9 @@ func TestWithAttachmentsAndNestedDirectories(t *testing.T) {
app, err := NewAppFromDefaultFiles(dir.Path())
assert.NilError(t, err)
assert.Assert(t, is.Len(app.Attachments(), 2))
assert.Assert(t, is.Equal(app.Attachments()[0].FilePath(), "config.cfg"))
assert.Assert(t, is.Equal(app.Attachments()[1].FilePath(), "nesteddirectory/nestedconfig.cfg"))
assert.Assert(t, is.Equal(app.Attachments()[0].Path(), "config.cfg"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: There's a helper to do this:
assert.Equal(t, x, y, msg)

@chris-crone
Copy link
Member

Agree that it doesn't make sense to change the units library. There's a broader conversation to be had around how we handle vendored libraries (and versions of the libraries) across the Docker codebase.

Signed-off-by: Mike Parker <michael.parker@docker.com>
@mikeparker
Copy link
Contributor Author

mikeparker commented Sep 26, 2018

Documentation:

  • Update README.md
  • Update examples with attachment example

Copy link
Contributor

@silvin-lubecki silvin-lubecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you @mikeparker! 🦁

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants