diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index b6f2106..8f03291 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -12,11 +12,11 @@ }, { "ImportPath": "github.com/appc/docker2aci/lib", - "Rev": "073a801e328be8d6a6d4c9152cdd13ed88b615b4" + "Rev": "616c01fe7e3d6532768ce9cc4843e97ef6592eb8" }, { "ImportPath": "github.com/appc/docker2aci/tarball", - "Rev": "073a801e328be8d6a6d4c9152cdd13ed88b615b4" + "Rev": "616c01fe7e3d6532768ce9cc4843e97ef6592eb8" }, { "ImportPath": "github.com/appc/spec/aci", diff --git a/Godeps/_workspace/src/github.com/appc/docker2aci/lib/docker2aci.go b/Godeps/_workspace/src/github.com/appc/docker2aci/lib/docker2aci.go index 53f1fa9..9c52bb3 100644 --- a/Godeps/_workspace/src/github.com/appc/docker2aci/lib/docker2aci.go +++ b/Godeps/_workspace/src/github.com/appc/docker2aci/lib/docker2aci.go @@ -417,15 +417,21 @@ func generateManifest(layerData DockerImageData, dockerURL *ParsedDockerURL) (*s genManifest.Labels = labels if dockerConfig != nil { - var exec types.Exec - if len(dockerConfig.Cmd) > 0 { - exec = types.Exec(dockerConfig.Cmd) - } else if len(dockerConfig.Entrypoint) > 0 { - exec = types.Exec(dockerConfig.Entrypoint) - } + exec := getExecCommand(dockerConfig.Entrypoint, dockerConfig.Cmd) if exec != nil { user, group := parseDockerUser(dockerConfig.User) - app := &types.App{Exec: exec, User: user, Group: group} + var env types.Environment + for _, v := range dockerConfig.Env { + parts := strings.SplitN(v, "=", 2) + env.Set(parts[0], parts[1]) + } + app := &types.App{ + Exec: exec, + User: user, + Group: group, + Environment: env, + WorkingDirectory: dockerConfig.WorkingDir, + } genManifest.App = app } } @@ -447,6 +453,20 @@ func generateManifest(layerData DockerImageData, dockerURL *ParsedDockerURL) (*s return genManifest, nil } +func getExecCommand(entrypoint []string, cmd []string) types.Exec { + var command []string + if entrypoint == nil && cmd == nil { + return nil + } + command = append(entrypoint, cmd...) + // non-absolute paths are not allowed, fallback to "/bin/sh -c command" + if !filepath.IsAbs(command[0]) { + command_prefix := []string{"/bin/sh", "-c"} + command = append(command_prefix, strings.Join(command, " ")) + } + return command +} + func parseDockerUser(dockerUser string) (string, string) { // if the docker user is empty assume root user and group if dockerUser == "" { @@ -495,7 +515,7 @@ func writeACI(layer io.ReadSeeker, manifest schema.ImageManifest, output string) return nil } if t.Header.Typeflag == tar.TypeLink { - t.Header.Linkname = path.Join("rootfs" + t.Linkname()) + t.Header.Linkname = path.Join("rootfs", t.Linkname()) } if err := trw.WriteHeader(t.Header); err != nil { @@ -524,7 +544,9 @@ func addMinimalACIStructure(tarWriter *tar.Writer, manifest schema.ImageManifest return err } - writeManifest(tarWriter, manifest) + if err := writeManifest(tarWriter, manifest); err != nil { + return err + } return nil } @@ -734,8 +756,12 @@ func mergeManifests(manifests []schema.ImageManifest) schema.ImageManifest { manifest.Labels = append(manifest.Labels[:layerIndex], manifest.Labels[layerIndex+1:]...) } + // strip layerID: + // myregistry.com/organization/app-name-85738f8f9a7f1b04b5329c590ebcb9e425925c6d0984089c43a022de4f19c281 + // myregistry.com/organization/app-name + n := strings.LastIndex(manifest.Name.String(), "-") // this can't fail because the old name is legal - nameWithoutLayerID, _ := types.NewACName(strings.Split(manifest.Name.String(), "-")[0]) + nameWithoutLayerID, _ := types.NewACName(manifest.Name.String()[:n]) manifest.Name = *nameWithoutLayerID