Skip to content
This repository was archived by the owner on Sep 13, 2024. It is now read-only.

Commit a531f42

Browse files
aws-gibbsktchienhanlin
authored andcommitted
Extend the mounting to include all dependencies
This results in the same set of folders available for ExecCommand support but also includes as RO the whole /var/lib/ecs/deps/ tree for additional features such as ServiceConnect to reuse without adding additional mounts.
1 parent 6895062 commit a531f42

File tree

2 files changed

+20
-49
lines changed

2 files changed

+20
-49
lines changed

ecs-init/docker/docker.go

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,7 @@ const (
117117
containerResourcesRootDir = "/managed-agents"
118118

119119
execCapabilityName = "execute-command"
120-
execBinRelativePath = "bin"
121120
execConfigRelativePath = "config"
122-
execCertsRelativePath = "certs"
123121

124122
execAgentLogRelativePath = "/exec"
125123
)
@@ -432,7 +430,7 @@ func (c *client) getHostConfig(envVarsFromFiles map[string]string) *godocker.Hos
432430
binds = append(binds, getDockerPluginDirBinds()...)
433431

434432
// only add bind mounts when the src file/directory exists on host; otherwise docker API create an empty directory on host
435-
binds = append(binds, getCapabilityExecBinds()...)
433+
binds = append(binds, getCapabilityBinds()...)
436434

437435
return createHostConfig(binds)
438436
}
@@ -468,31 +466,24 @@ func getDockerPluginDirBinds() []string {
468466
return pluginBinds
469467
}
470468

471-
func getCapabilityExecBinds() []string {
472-
hostResourcesDir := filepath.Join(hostResourcesRootDir, execCapabilityName)
473-
containerResourcesDir := filepath.Join(containerResourcesRootDir, execCapabilityName)
469+
func getCapabilityBinds() []string {
470+
var binds = []string{}
474471

475-
var binds []string
476-
477-
// bind mount the entire /host/dependency/path/execute-command/bin folder
478-
hostBinDir := filepath.Join(hostResourcesDir, execBinRelativePath)
479-
if isPathValid(hostBinDir, true) {
472+
// bind mount the entire /host/dependency/path/ folder
473+
// as readonly to support all managed dependencies
474+
if isPathValid(hostResourcesRootDir, true) {
480475
binds = append(binds,
481-
hostBinDir+":"+filepath.Join(containerResourcesDir, execBinRelativePath)+readOnly)
476+
hostResourcesRootDir+":"+containerResourcesRootDir+readOnly)
482477
}
483478

484479
// bind mount the entire /host/dependency/path/execute-command/config folder
485480
// in read-write mode to allow ecs-agent to write config files to host file system
486481
// (docker will) create the config folder if it does not exist
487-
hostConfigDir := filepath.Join(hostResourcesDir, execConfigRelativePath)
488-
binds = append(binds,
489-
hostConfigDir+":"+filepath.Join(containerResourcesDir, execConfigRelativePath))
490-
491-
// bind mount the entire /host/dependency/path/execute-command/certs folder
492-
hostCertsDir := filepath.Join(hostResourcesDir, execCertsRelativePath)
493-
if isPathValid(hostCertsDir, true) {
482+
hostConfigDir := filepath.Join(hostResourcesRootDir, execCapabilityName, execConfigRelativePath)
483+
// Check that execute-command folder is present not config folder
484+
if isPathValid(filepath.Dir(hostConfigDir), true) {
494485
binds = append(binds,
495-
hostCertsDir+":"+filepath.Join(containerResourcesDir, execCertsRelativePath)+readOnly)
486+
hostConfigDir+":"+filepath.Join(containerResourcesRootDir, execCapabilityName, execConfigRelativePath))
496487
}
497488

498489
return binds

ecs-init/docker/docker_test.go

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
const (
3434
testTempDirPrefix = "init-docker-test-"
3535

36-
expectedAgentBindsUnspecifiedPlatform = 21
36+
expectedAgentBindsUnspecifiedPlatform = 20
3737
expectedAgentBindsSuseUbuntuPlatform = 18
3838
)
3939

@@ -827,21 +827,13 @@ func TestStartAgentWithExecBinds(t *testing.T) {
827827
hostCapabilityExecResourcesDir := filepath.Join(hostResourcesRootDir, execCapabilityName)
828828
containerCapabilityExecResourcesDir := filepath.Join(containerResourcesRootDir, execCapabilityName)
829829

830-
// binaries
831-
hostBinDir := filepath.Join(hostCapabilityExecResourcesDir, execBinRelativePath)
832-
containerBinDir := filepath.Join(containerCapabilityExecResourcesDir, execBinRelativePath)
833-
834830
// config
835831
hostConfigDir := filepath.Join(hostCapabilityExecResourcesDir, execConfigRelativePath)
836832
containerConfigDir := filepath.Join(containerCapabilityExecResourcesDir, execConfigRelativePath)
837833

838-
// certs
839-
hostCertsDir := filepath.Join(hostCapabilityExecResourcesDir, execCertsRelativePath)
840-
containerCertsDir := filepath.Join(containerCapabilityExecResourcesDir, execCertsRelativePath)
841-
842834
expectedExecBinds := []string{
843-
hostBinDir + ":" + containerBinDir + readOnly,
844-
hostCertsDir + ":" + containerCertsDir + readOnly,
835+
hostResourcesRootDir + ":" + containerResourcesRootDir + readOnly,
836+
hostConfigDir + ":" + containerConfigDir,
845837
}
846838
expectedAgentBinds += len(expectedExecBinds)
847839

@@ -884,18 +876,10 @@ func TestGetCapabilityExecBinds(t *testing.T) {
884876
hostCapabilityExecResourcesDir := filepath.Join(hostResourcesRootDir, execCapabilityName)
885877
containerCapabilityExecResourcesDir := filepath.Join(containerResourcesRootDir, execCapabilityName)
886878

887-
// binaries
888-
hostBinDir := filepath.Join(hostCapabilityExecResourcesDir, execBinRelativePath)
889-
containerBinDir := filepath.Join(containerCapabilityExecResourcesDir, execBinRelativePath)
890-
891879
// config
892880
hostConfigDir := filepath.Join(hostCapabilityExecResourcesDir, execConfigRelativePath)
893881
containerConfigDir := filepath.Join(containerCapabilityExecResourcesDir, execConfigRelativePath)
894882

895-
// certs
896-
hostCertsDir := filepath.Join(hostCapabilityExecResourcesDir, execCertsRelativePath)
897-
containerCertsDir := filepath.Join(containerCapabilityExecResourcesDir, execCertsRelativePath)
898-
899883
testCases := []struct {
900884
name string
901885
testIsPathValid func(string, bool) bool
@@ -907,35 +891,31 @@ func TestGetCapabilityExecBinds(t *testing.T) {
907891
return true
908892
},
909893
expectedBinds: []string{
910-
hostBinDir + ":" + containerBinDir + readOnly,
894+
hostResourcesRootDir + ":" + containerResourcesRootDir + readOnly,
911895
hostConfigDir + ":" + containerConfigDir,
912-
hostCertsDir + ":" + containerCertsDir + readOnly,
913896
},
914897
},
915898
{
916-
name: "only ssm-agent bin path valid",
899+
name: "managed-agents path valid, no execute-command",
917900
testIsPathValid: func(path string, isDir bool) bool {
918-
return path == hostBinDir
901+
return path == hostResourcesRootDir
919902
},
920903
expectedBinds: []string{
921-
hostBinDir + ":" + containerBinDir + readOnly,
922-
hostConfigDir + ":" + containerConfigDir,
904+
hostResourcesRootDir + ":" + containerResourcesRootDir + readOnly,
923905
},
924906
},
925907
{
926908
name: "no path valid",
927909
testIsPathValid: func(path string, isDir bool) bool {
928910
return false
929911
},
930-
expectedBinds: []string{
931-
hostConfigDir + ":" + containerConfigDir,
932-
},
912+
expectedBinds: []string{},
933913
},
934914
}
935915
for _, tc := range testCases {
936916
t.Run(tc.name, func(t *testing.T) {
937917
isPathValid = tc.testIsPathValid
938-
binds := getCapabilityExecBinds()
918+
binds := getCapabilityBinds()
939919
assert.Equal(t, tc.expectedBinds, binds)
940920
})
941921
}

0 commit comments

Comments
 (0)