Skip to content
This repository has been archived by the owner on Aug 14, 2020. It is now read-only.

Convert Docker Volumes to mountPoints #43

Merged
merged 6 commits into from
Apr 23, 2015
Merged

Conversation

iaguis
Copy link
Member

@iaguis iaguis commented Apr 14, 2015

A Docker image can specify Volumes which are akin to mountPoints in the
appc spec. This commit converts Volumes to mountPoints allowing the user
to mount volumes with rkt's --volume option.

Since Docker doesn't name Volumes but the appc spec requires a name, we
generate a name by appending the path to "volume-". That is, if a Volume
has "/var/tmp" as path, the resulting mountPoint name will be
"volume-/var/tmp". A mountPoint name must be a valid ACName so any
invalid characters will be replaced by a "-".

@jonboulle
Copy link
Contributor

Could you document this, please?

@iaguis iaguis force-pushed the iaguis/volumes branch 2 times, most recently from d564ce0 to aedb206 Compare April 22, 2015 13:19
@iaguis
Copy link
Member Author

iaguis commented Apr 22, 2015

Done.

@rimusz
Copy link

rimusz commented Apr 22, 2015

@iaguis 👍


for p, _ := range dockerConfig.Volumes {
n := filepath.Join("volume-", p)
sn, err := appctypes.SanitizeACName(n)
Copy link
Contributor

Choose a reason for hiding this comment

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

Hrm maybe a corner case but don't we need to deal with duplicates? e.g. /data#, /data$

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes we do, thanks!

@jonboulle
Copy link
Contributor

LGTM modulo question about duplicates.

mps := []appctypes.MountPoint{}
dup := make(map[string]int)

for p, _ := range dockerVolumes {
Copy link
Member

Choose a reason for hiding this comment

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

No need for the underline, you can simply type p := range dockerVolumes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right

A Docker image can specify Volumes which are akin to mountPoints in the
appc spec. This commit converts Volumes to mountPoints allowing the user
to mount volumes with rkt's --volume option.

Since Docker doesn't name Volumes but the appc spec requires a name, we
generate a name by appending the path to "volume-". That is, if a Volume
has "/var/tmp" as path, the resulting mountPoint name will be
"volume-/var/tmp". A mountPoint name must be a valid ACName so any
invalid characters will be replaced by a "-".
We're converting Docker Volumes to mountPoints but the user doesn't know
it nor their names unless she looks manually in the manifest.

This commit prints the converted volumes: their name, path inside the
container and whether they're read-only or not.
Converting Docker Volumes to mountPoints can result in duplicates. For
example, if there're two Docker Volumes with paths "/data#", "/data$"
and "/data-" the resulting mountPoints will have the same name:
"volume-/data".

This commit adds the "-N" suffix to duplicated mountPoint names, where N
is a number starting from 1. In the previous example, the names would
be "volume-/data", "volume-/data-1" and "volume-/data-2".
@@ -65,6 +68,12 @@ func runDocker2ACI(arg string, flagNoSquash bool, flagImage string, flagDebug bo
return fmt.Errorf("conversion error: %v", err)
}

if squash {
Copy link
Member

Choose a reason for hiding this comment

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

What about printing converted volumes in non-squashing scenario?

Copy link
Member Author

Choose a reason for hiding this comment

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

I can add it. It looks a bit ugly because there will be a lot of repeated volumes:

Converted volumes in "postgres-26bdc4facea7aad8cfdf3da846e3767bfa027fc0b3c621501f8d7a2413fd24e2-latest-linux-amd64.aci":
        name: "volume-/var/lib/postgresql/data", path: "/var/lib/postgresql/data", readOnly: false

Converted volumes in "postgres-3508d36eab9991998d587938711fd19286205eb1a7e994fc4df804ab08e14013-latest-linux-amd64.aci":
        name: "volume-/var/lib/postgresql/data", path: "/var/lib/postgresql/data", readOnly: false

Converted volumes in "postgres-86cff6f79a0869259cd911587f61282d9c7a5afc87ca425290cfc781cfaa83bd-latest-linux-amd64.aci":
        name: "volume-/var/lib/postgresql/data", path: "/var/lib/postgresql/data", readOnly: false

Converted volumes in "postgres-9c5489b55573bdc2e214f35ed102543845c0de6ca5df10eb5c037ee93a126002-latest-linux-amd64.aci":
        name: "volume-/var/lib/postgresql/data", path: "/var/lib/postgresql/data", readOnly: false

Converted volumes in "postgres-dcce0da1c31105323a840ded6e79f39b7338907f5c2477109b68692e7acb75be-latest-linux-amd64.aci":
        name: "volume-/var/lib/postgresql/data", path: "/var/lib/postgresql/data", readOnly: false

Copy link
Member

Choose a reason for hiding this comment

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

Hm, then maybe deduping it beforehand would be useful?

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I dedup the mountpoints before printing them

Copy link
Member Author

Choose a reason for hiding this comment

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

And I hate go for its lack of generics

Downloading layer: d47fc7449244382dc6121e68100a2c677f4964b495c5bdbbe2975be21777151e
Downloading layer: f2fb89b0a711a7178528c7785d247ba3572924353b0d5e23e9b28f0518253b22

Converted volumes in "redis-latest.aci":
Copy link
Member

Choose a reason for hiding this comment

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

This actually is not printed. :P

Copy link
Member Author

Choose a reason for hiding this comment

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

This is still a WIP 😬

@iaguis
Copy link
Member Author

iaguis commented Apr 23, 2015

Updated.

@@ -73,6 +80,41 @@ func runDocker2ACI(arg string, flagNoSquash bool, flagImage string, flagDebug bo
return nil
}

func printConvertedVolumes(aciPaths []string) error {
Copy link
Member

Choose a reason for hiding this comment

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

I would pass just a string instead of an array. Or at least document why we are using only last element here.

@krnowak
Copy link
Member

krnowak commented Apr 23, 2015

LGTM.

@iaguis
Copy link
Member Author

iaguis commented Apr 23, 2015

😃

iaguis added a commit that referenced this pull request Apr 23, 2015
Convert Docker Volumes to mountPoints
@iaguis iaguis merged commit 1bd87f0 into appc:master Apr 23, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants