Skip to content

Commit

Permalink
revendor engine-api
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Goff <[email protected]>
  • Loading branch information
cpuguy83 committed Aug 16, 2016
1 parent e4a88b3 commit 6d98e34
Show file tree
Hide file tree
Showing 36 changed files with 235 additions and 176 deletions.
31 changes: 16 additions & 15 deletions api/client/service/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/docker/docker/opts"
runconfigopts "github.com/docker/docker/runconfig/opts"
mounttypes "github.com/docker/engine-api/types/mount"
"github.com/docker/engine-api/types/swarm"
"github.com/docker/go-connections/nat"
units "github.com/docker/go-units"
Expand Down Expand Up @@ -130,7 +131,7 @@ func (i *Uint64Opt) Value() *uint64 {

// MountOpt is a Value type for parsing mounts
type MountOpt struct {
values []swarm.Mount
values []mounttypes.Mount
}

// Set a new mount value
Expand All @@ -141,23 +142,23 @@ func (m *MountOpt) Set(value string) error {
return err
}

mount := swarm.Mount{}
mount := mounttypes.Mount{}

volumeOptions := func() *swarm.VolumeOptions {
volumeOptions := func() *mounttypes.VolumeOptions {
if mount.VolumeOptions == nil {
mount.VolumeOptions = &swarm.VolumeOptions{
mount.VolumeOptions = &mounttypes.VolumeOptions{
Labels: make(map[string]string),
}
}
if mount.VolumeOptions.DriverConfig == nil {
mount.VolumeOptions.DriverConfig = &swarm.Driver{}
mount.VolumeOptions.DriverConfig = &mounttypes.Driver{}
}
return mount.VolumeOptions
}

bindOptions := func() *swarm.BindOptions {
bindOptions := func() *mounttypes.BindOptions {
if mount.BindOptions == nil {
mount.BindOptions = new(swarm.BindOptions)
mount.BindOptions = new(mounttypes.BindOptions)
}
return mount.BindOptions
}
Expand All @@ -171,7 +172,7 @@ func (m *MountOpt) Set(value string) error {
}
}

mount.Type = swarm.MountTypeVolume // default to volume mounts
mount.Type = mounttypes.TypeVolume // default to volume mounts
// Set writable as the default
for _, field := range fields {
parts := strings.SplitN(field, "=", 2)
Expand All @@ -195,7 +196,7 @@ func (m *MountOpt) Set(value string) error {
value := parts[1]
switch key {
case "type":
mount.Type = swarm.MountType(strings.ToLower(value))
mount.Type = mounttypes.Type(strings.ToLower(value))
case "source", "src":
mount.Source = value
case "target", "dst", "destination":
Expand All @@ -206,7 +207,7 @@ func (m *MountOpt) Set(value string) error {
return fmt.Errorf("invalid value for %s: %s", key, value)
}
case "bind-propagation":
bindOptions().Propagation = swarm.MountPropagation(strings.ToLower(value))
bindOptions().Propagation = mounttypes.Propagation(strings.ToLower(value))
case "volume-nocopy":
volumeOptions().NoCopy, err = strconv.ParseBool(value)
if err != nil {
Expand Down Expand Up @@ -238,11 +239,11 @@ func (m *MountOpt) Set(value string) error {
return fmt.Errorf("source is required when specifying volume-* options")
}

if mount.Type == swarm.MountTypeBind && mount.VolumeOptions != nil {
return fmt.Errorf("cannot mix 'volume-*' options with mount type '%s'", swarm.MountTypeBind)
if mount.Type == mounttypes.TypeBind && mount.VolumeOptions != nil {
return fmt.Errorf("cannot mix 'volume-*' options with mount type '%s'", mounttypes.TypeBind)
}
if mount.Type == swarm.MountTypeVolume && mount.BindOptions != nil {
return fmt.Errorf("cannot mix 'bind-*' options with mount type '%s'", swarm.MountTypeVolume)
if mount.Type == mounttypes.TypeVolume && mount.BindOptions != nil {
return fmt.Errorf("cannot mix 'bind-*' options with mount type '%s'", mounttypes.TypeVolume)
}

m.values = append(m.values, mount)
Expand All @@ -265,7 +266,7 @@ func (m *MountOpt) String() string {
}

// Value returns the mounts
func (m *MountOpt) Value() []swarm.Mount {
func (m *MountOpt) Value() []mounttypes.Mount {
return m.values
}

Expand Down
14 changes: 7 additions & 7 deletions api/client/service/opts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"time"

"github.com/docker/docker/pkg/testutil/assert"
"github.com/docker/engine-api/types/swarm"
mounttypes "github.com/docker/engine-api/types/mount"
)

func TestMemBytesString(t *testing.T) {
Expand Down Expand Up @@ -59,14 +59,14 @@ func TestUint64OptSetAndValue(t *testing.T) {

func TestMountOptString(t *testing.T) {
mount := MountOpt{
values: []swarm.Mount{
values: []mounttypes.Mount{
{
Type: swarm.MountTypeBind,
Type: mounttypes.TypeBind,
Source: "/home/path",
Target: "/target",
},
{
Type: swarm.MountTypeVolume,
Type: mounttypes.TypeVolume,
Source: "foo",
Target: "/target/foo",
},
Expand All @@ -90,8 +90,8 @@ func TestMountOptSetNoError(t *testing.T) {

mounts := mount.Value()
assert.Equal(t, len(mounts), 1)
assert.Equal(t, mounts[0], swarm.Mount{
Type: swarm.MountTypeBind,
assert.Equal(t, mounts[0], mounttypes.Mount{
Type: mounttypes.TypeBind,
Source: "/source",
Target: "/target",
})
Expand All @@ -103,7 +103,7 @@ func TestMountOptSetNoError(t *testing.T) {
func TestMountOptDefaultType(t *testing.T) {
var mount MountOpt
assert.NilError(t, mount.Set("target=/target,source=/foo"))
assert.Equal(t, mount.values[0].Type, swarm.MountTypeVolume)
assert.Equal(t, mount.values[0].Type, mounttypes.TypeVolume)
}

func TestMountOptSetErrorNoTarget(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions api/client/service/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/docker/docker/opts"
runconfigopts "github.com/docker/docker/runconfig/opts"
"github.com/docker/engine-api/types"
mounttypes "github.com/docker/engine-api/types/mount"
"github.com/docker/engine-api/types/swarm"
"github.com/docker/go-connections/nat"
shlex "github.com/flynn-archive/go-shlex"
Expand Down Expand Up @@ -353,14 +354,14 @@ func removeItems(
return newSeq
}

func updateMounts(flags *pflag.FlagSet, mounts *[]swarm.Mount) {
func updateMounts(flags *pflag.FlagSet, mounts *[]mounttypes.Mount) {
if flags.Changed(flagMountAdd) {
values := flags.Lookup(flagMountAdd).Value.(*MountOpt).Value()
*mounts = append(*mounts, values...)
}
toRemove := buildToRemoveSet(flags, flagMountRemove)

newMounts := []swarm.Mount{}
newMounts := []mounttypes.Mount{}
for _, mount := range *mounts {
if _, exists := toRemove[mount.Target]; !exists {
newMounts = append(newMounts, mount)
Expand Down
7 changes: 4 additions & 3 deletions api/client/service/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/docker/docker/pkg/testutil/assert"
mounttypes "github.com/docker/engine-api/types/mount"
"github.com/docker/engine-api/types/swarm"
)

Expand Down Expand Up @@ -104,9 +105,9 @@ func TestUpdateMounts(t *testing.T) {
flags.Set("mount-add", "type=volume,target=/toadd")
flags.Set("mount-rm", "/toremove")

mounts := []swarm.Mount{
{Target: "/toremove", Type: swarm.MountTypeBind},
{Target: "/tokeep", Type: swarm.MountTypeBind},
mounts := []mounttypes.Mount{
{Target: "/toremove", Type: mounttypes.TypeBind},
{Target: "/tokeep", Type: mounttypes.TypeBind},
}

updateMounts(flags, &mounts)
Expand Down
4 changes: 2 additions & 2 deletions api/client/system/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func runInspect(dockerCli *client.DockerCli, opts inspectOptions) error {
}
case "image":
getRefFunc = func(ref string) (interface{}, []byte, error) {
return client.ImageInspectWithRaw(ctx, ref, opts.size)
return client.ImageInspectWithRaw(ctx, ref)
}
case "task":
if opts.size {
Expand All @@ -81,7 +81,7 @@ func inspectAll(ctx context.Context, dockerCli *client.DockerCli, getSize bool)
return c, rawContainer, err
}
// Search for image with that id if a container doesn't exist.
i, rawImage, err := client.ImageInspectWithRaw(ctx, ref, getSize)
i, rawImage, err := client.ImageInspectWithRaw(ctx, ref)
if err == nil || !apiclient.IsErrNotFound(err) {
return i, rawImage, err
}
Expand Down
2 changes: 1 addition & 1 deletion api/client/volume/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func runRemove(dockerCli *client.DockerCli, volumes []string) error {
status := 0

for _, name := range volumes {
if err := client.VolumeRemove(ctx, name); err != nil {
if err := client.VolumeRemove(ctx, name, false); err != nil {
fmt.Fprintf(dockerCli.Err(), "%s\n", err)
status = 1
continue
Expand Down
9 changes: 9 additions & 0 deletions api/server/router/system/system_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/docker/engine-api/types/events"
"github.com/docker/engine-api/types/filters"
timetypes "github.com/docker/engine-api/types/time"
"github.com/docker/engine-api/types/versions"
"golang.org/x/net/context"
)

Expand All @@ -37,6 +38,14 @@ func (s *systemRouter) getInfo(ctx context.Context, w http.ResponseWriter, r *ht
info.Swarm = s.clusterProvider.Info()
}

if versions.LessThan("1.25", httputils.VersionFromContext(ctx)) {
// TODO: handle this conversion in engine-api
type oldInfo struct {
*types.Info
ExecutionDriver string
}
return httputils.WriteJSON(w, http.StatusOK, &oldInfo{Info: info, ExecutionDriver: "<not supported>"})
}
return httputils.WriteJSON(w, http.StatusOK, info)
}

Expand Down
8 changes: 4 additions & 4 deletions container/container_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (container *Container) NetworkMounts() []Mount {
Source: container.ResolvConfPath,
Destination: "/etc/resolv.conf",
Writable: writable,
Propagation: volume.DefaultPropagationMode,
Propagation: string(volume.DefaultPropagationMode),
})
}
}
Expand All @@ -148,7 +148,7 @@ func (container *Container) NetworkMounts() []Mount {
Source: container.HostnamePath,
Destination: "/etc/hostname",
Writable: writable,
Propagation: volume.DefaultPropagationMode,
Propagation: string(volume.DefaultPropagationMode),
})
}
}
Expand All @@ -167,7 +167,7 @@ func (container *Container) NetworkMounts() []Mount {
Source: container.HostsPath,
Destination: "/etc/hosts",
Writable: writable,
Propagation: volume.DefaultPropagationMode,
Propagation: string(volume.DefaultPropagationMode),
})
}
}
Expand Down Expand Up @@ -249,7 +249,7 @@ func (container *Container) IpcMounts() []Mount {
Source: container.ShmPath,
Destination: "/dev/shm",
Writable: true,
Propagation: volume.DefaultPropagationMode,
Propagation: string(volume.DefaultPropagationMode),
})
}

Expand Down
13 changes: 7 additions & 6 deletions daemon/cluster/convert/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"strings"

mounttypes "github.com/docker/engine-api/types/mount"
types "github.com/docker/engine-api/types/swarm"
swarmapi "github.com/docker/swarmkit/api"
"github.com/docker/swarmkit/protobuf/ptypes"
Expand All @@ -22,26 +23,26 @@ func containerSpecFromGRPC(c *swarmapi.ContainerSpec) types.ContainerSpec {

// Mounts
for _, m := range c.Mounts {
mount := types.Mount{
mount := mounttypes.Mount{
Target: m.Target,
Source: m.Source,
Type: types.MountType(strings.ToLower(swarmapi.Mount_MountType_name[int32(m.Type)])),
Type: mounttypes.Type(strings.ToLower(swarmapi.Mount_MountType_name[int32(m.Type)])),
ReadOnly: m.ReadOnly,
}

if m.BindOptions != nil {
mount.BindOptions = &types.BindOptions{
Propagation: types.MountPropagation(strings.ToLower(swarmapi.Mount_BindOptions_MountPropagation_name[int32(m.BindOptions.Propagation)])),
mount.BindOptions = &mounttypes.BindOptions{
Propagation: mounttypes.Propagation(strings.ToLower(swarmapi.Mount_BindOptions_MountPropagation_name[int32(m.BindOptions.Propagation)])),
}
}

if m.VolumeOptions != nil {
mount.VolumeOptions = &types.VolumeOptions{
mount.VolumeOptions = &mounttypes.VolumeOptions{
NoCopy: m.VolumeOptions.NoCopy,
Labels: m.VolumeOptions.Labels,
}
if m.VolumeOptions.DriverConfig != nil {
mount.VolumeOptions.DriverConfig = &types.Driver{
mount.VolumeOptions.DriverConfig = &mounttypes.Driver{
Name: m.VolumeOptions.DriverConfig.Name,
Options: m.VolumeOptions.DriverConfig.Options,
}
Expand Down
2 changes: 1 addition & 1 deletion daemon/oci_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ func setMounts(daemon *Daemon, s *specs.Spec, c *container.Container, mounts []c

if m.Source == "tmpfs" {
data := c.HostConfig.Tmpfs[m.Destination]
options := []string{"noexec", "nosuid", "nodev", volume.DefaultPropagationMode}
options := []string{"noexec", "nosuid", "nodev", string(volume.DefaultPropagationMode)}
if data != "" {
options = append(options, strings.Split(data, ",")...)
}
Expand Down
4 changes: 2 additions & 2 deletions daemon/volumes_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ func (daemon *Daemon) setupMounts(c *container.Container) ([]container.Mount, er
Source: path,
Destination: m.Destination,
Writable: m.RW,
Propagation: m.Propagation,
Propagation: string(m.Propagation),
}
if m.Volume != nil {
attributes := map[string]string{
"driver": m.Volume.DriverName(),
"container": c.ID,
"destination": m.Destination,
"read/write": strconv.FormatBool(m.RW),
"propagation": m.Propagation,
"propagation": string(m.Propagation),
}
daemon.LogVolumeEvent(m.Volume.Name(), "mount", attributes)
}
Expand Down
2 changes: 1 addition & 1 deletion hack/vendor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ clone git golang.org/x/sys eb2c74142fd19a79b3f237334c7384d5167b1b46 https://gith
clone git github.com/docker/go-units eb879ae3e2b84e2a142af415b679ddeda47ec71c
clone git github.com/docker/go-connections fa2850ff103453a9ad190da0df0af134f0314b3d

clone git github.com/docker/engine-api 603ec41824c63d1e6498a22271987fa1f268c0c0
clone git github.com/docker/engine-api ebc51d1954fc8934307dd15841b8d64f7cd505df
clone git github.com/RackSec/srslog 259aed10dfa74ea2961eddd1d9847619f6e98837
clone git github.com/imdario/mergo 0.2.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (cli *Client) ContainerCreate(ctx context.Context, config *container.Config

serverResp, err := cli.post(ctx, "/containers/create", query, body, nil)
if err != nil {
if serverResp != nil && serverResp.statusCode == 404 && strings.Contains(err.Error(), "No such image") {
if serverResp.statusCode == 404 && strings.Contains(err.Error(), "No such image") {
return response, imageNotFoundError{config.Image}
}
return response, err
Expand Down
4 changes: 4 additions & 0 deletions vendor/src/github.com/docker/engine-api/client/image_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ func imageBuildOptionsToQuery(options types.ImageBuildOptions) (url.Values, erro
query.Set("pull", "1")
}

if options.Squash {
query.Set("squash", "1")
}

if !container.Isolation.IsDefault(options.Isolation) {
query.Set("isolation", string(options.Isolation))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (cli *Client) ImageCreate(ctx context.Context, parentReference string, opti
return resp.body, nil
}

func (cli *Client) tryImageCreate(ctx context.Context, query url.Values, registryAuth string) (*serverResponse, error) {
func (cli *Client) tryImageCreate(ctx context.Context, query url.Values, registryAuth string) (serverResponse, error) {
headers := map[string][]string{"X-Registry-Auth": {registryAuth}}
return cli.post(ctx, "/images/create", query, nil, headers)
}
Loading

0 comments on commit 6d98e34

Please sign in to comment.