Browse code

Fix EXPOSE cache miss issue

Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes <guillaume@charmes.net> (github: creack)

Guillaume J. Charmes authored on 2014/03/14 05:58:09
Showing 4 changed files
... ...
@@ -7,6 +7,7 @@ import (
7 7
 	"errors"
8 8
 	"fmt"
9 9
 	"github.com/dotcloud/docker/archive"
10
+	"github.com/dotcloud/docker/nat"
10 11
 	"github.com/dotcloud/docker/registry"
11 12
 	"github.com/dotcloud/docker/runconfig"
12 13
 	"github.com/dotcloud/docker/runtime"
... ...
@@ -304,8 +305,22 @@ func (b *buildFile) CmdEntrypoint(args string) error {
304 304
 }
305 305
 
306 306
 func (b *buildFile) CmdExpose(args string) error {
307
-	ports := strings.Split(args, " ")
308
-	b.config.PortSpecs = append(ports, b.config.PortSpecs...)
307
+	portsTab := strings.Split(args, " ")
308
+
309
+	if b.config.ExposedPorts == nil {
310
+		b.config.ExposedPorts = make(nat.PortSet)
311
+	}
312
+	ports, _, err := nat.ParsePortSpecs(append(portsTab, b.config.PortSpecs...))
313
+	if err != nil {
314
+		return err
315
+	}
316
+	for port := range ports {
317
+		if _, exists := b.config.ExposedPorts[port]; !exists {
318
+			b.config.ExposedPorts[port] = struct{}{}
319
+		}
320
+	}
321
+	b.config.PortSpecs = nil
322
+
309 323
 	return b.commit("", b.config.Cmd, fmt.Sprintf("EXPOSE %v", ports))
310 324
 }
311 325
 
... ...
@@ -686,12 +701,12 @@ func (b *buildFile) commit(id string, autoCmd []string, comment string) error {
686 686
 		b.tmpContainers[container.ID] = struct{}{}
687 687
 		fmt.Fprintf(b.outStream, " ---> Running in %s\n", utils.TruncateID(container.ID))
688 688
 		id = container.ID
689
+
689 690
 		if err := container.Mount(); err != nil {
690 691
 			return err
691 692
 		}
692 693
 		defer container.Unmount()
693 694
 	}
694
-
695 695
 	container := b.runtime.Get(id)
696 696
 	if container == nil {
697 697
 		return fmt.Errorf("An error occured while creating the container")
... ...
@@ -64,6 +64,7 @@ func Merge(userConf, imageConf *Config) error {
64 64
 			}
65 65
 		}
66 66
 	}
67
+
67 68
 	if !userConf.Tty {
68 69
 		userConf.Tty = imageConf.Tty
69 70
 	}
... ...
@@ -542,7 +542,6 @@ func (runtime *Runtime) Create(config *runconfig.Config, name string) (*Containe
542 542
 // The image can optionally be tagged into a repository
543 543
 func (runtime *Runtime) Commit(container *Container, repository, tag, comment, author string, config *runconfig.Config) (*image.Image, error) {
544 544
 	// FIXME: freeze the container before copying it to avoid data corruption?
545
-	// FIXME: this shouldn't be in commands.
546 545
 	if err := container.Mount(); err != nil {
547 546
 		return nil, err
548 547
 	}
... ...
@@ -1970,7 +1970,6 @@ func (srv *Server) canDeleteImage(imgID string) error {
1970 1970
 }
1971 1971
 
1972 1972
 func (srv *Server) ImageGetCached(imgID string, config *runconfig.Config) (*image.Image, error) {
1973
-
1974 1973
 	// Retrieve all images
1975 1974
 	images, err := srv.runtime.Graph().Map()
1976 1975
 	if err != nil {