adding EXPOSE command
This commit is contained in:
parent
c2a69c0e24
commit
288ac0b93b
|
|
@ -38,6 +38,8 @@ func GetCommand(cmd instructions.Command) (DockerCommand, error) {
|
|||
switch c := cmd.(type) {
|
||||
case *instructions.RunCommand:
|
||||
return &RunCommand{cmd: c}, nil
|
||||
case *instructions.ExposeCommand:
|
||||
return &ExposeCommand{cmd: c}, nil
|
||||
}
|
||||
return nil, errors.Errorf("%s is not a supported command", cmd.Name())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"github.com/containers/image/manifest"
|
||||
"github.com/docker/docker/builder/dockerfile/instructions"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ExposeCommand struct {
|
||||
cmd *instructions.ExposeCommand
|
||||
}
|
||||
|
||||
func (r *ExposeCommand) ExecuteCommand(config *manifest.Schema2Config) error {
|
||||
return updateExposedPorts(r.Ports, config)
|
||||
}
|
||||
|
||||
func updateExposedPorts(ports []string, config *manifest.Schema2Config) error {
|
||||
// Grab the currently exposed ports
|
||||
existingPorts := config.ExposedPorts
|
||||
|
||||
// Add any new ones in
|
||||
for _, p := range ports {
|
||||
// Add the default protocol if one isn't specified
|
||||
if !strings.Contains(p, "/") {
|
||||
p = p + "/tcp"
|
||||
}
|
||||
existingPorts[p] = {}
|
||||
}
|
||||
config.ExposedPorts = existingPorts
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *ExposeCommand) FilesToSnapshot() []string {
|
||||
return []string{}
|
||||
}
|
||||
|
||||
func (r *ExposeCommand) CreatedBy() string {
|
||||
s := []string{"/bin/sh", "-c"}
|
||||
return strings.Join(append(s, r.Ports...), " ")
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"github.com/GoogleCloudPlatform/k8s-container-builder/testutil"
|
||||
"github.com/containers/image/manifest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUpdateExposedPorts(t *testing.T) {
|
||||
cfg := &manifest.Schema2Config{
|
||||
ExposedPorts: manifest.Schema2PortSet{
|
||||
"8080/tcp": {},
|
||||
},
|
||||
}
|
||||
|
||||
ports := []string{
|
||||
"8080",
|
||||
"8081/tcp",
|
||||
"8082",
|
||||
}
|
||||
|
||||
expectedPorts := manifest.Schema2PortSet{
|
||||
"8080/tcp": {},
|
||||
"8081/tcp": {},
|
||||
"8082/tcp": {},
|
||||
}
|
||||
|
||||
updateExposedPorts(ports, cfg)
|
||||
testutil.CheckErrorAndDeepEqual(t, false, nil, expectedPorts, cfg.ExposedPorts)
|
||||
}
|
||||
Loading…
Reference in New Issue