From 07492e04b12abdb158ed5efe6490fea707d567f3 Mon Sep 17 00:00:00 2001 From: "Joel D. Elkins" Date: Sun, 31 Jul 2022 13:37:05 -0500 Subject: [PATCH] Add Expose{Tcp,Udp} to container def --- internal/pkg/container/container.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/internal/pkg/container/container.go b/internal/pkg/container/container.go index 4360d4b..488d438 100644 --- a/internal/pkg/container/container.go +++ b/internal/pkg/container/container.go @@ -52,6 +52,8 @@ type Container struct { Restart string `toml:"restart,omitempty"` Umask null.Int `toml:"umask,omitempty"` User string `toml:"user,omitempty"` + ExposeTcp []uint16 `toml:"expose_tcp,omitempty"` + ExposeUdp []uint16 `toml:"expose_udp,omitempty"` conn context.Context cdata *define.InspectContainerData @@ -115,8 +117,8 @@ func (c *Container) pull() error { } func (c *Container) newCommandSet(op string, cmds cmd.Commands) cmd.CommandSet { - return cmd.CommandSet { - ID: fmt.Sprintf("%s-%s", op, c.Name), + return cmd.CommandSet{ + ID: fmt.Sprintf("%s-%s", op, c.Name), Commands: cmds, } } @@ -158,6 +160,14 @@ func (c *Container) CreateCommands() cmd.CommandSet { dns = append(dns, c.Networks[i].DNS...) } + expose := map[uint16]string{} + for _, p := range c.ExposeTcp { + expose[p] = "tcp" + } + for _, p := range c.ExposeUdp { + expose[p] = "udp" + } + spec := specgen.SpecGenerator{ ContainerBasicConfig: specgen.ContainerBasicConfig{ Name: c.Name, @@ -174,8 +184,10 @@ func (c *Container) CreateCommands() cmd.CommandSet { Mounts: c.Mounts, }, ContainerNetworkConfig: specgen.ContainerNetworkConfig{ - Networks: nets, - DNSServers: dns, + Networks: nets, + DNSServers: dns, + Expose: expose, + PublishExposedPorts: len(expose) > 0, }, ContainerSecurityConfig: specgen.ContainerSecurityConfig{ User: c.User,