Skip to content

Commit 4435383

Browse files
HaoranRENVishnuKarthikRavindran
authored andcommitted
Fix docker related plugins
cr: https://code.amazon.com/reviews/CR-107199819
1 parent 868defd commit 4435383

File tree

4 files changed

+50
-62
lines changed

4 files changed

+50
-62
lines changed

agent/plugins/configurecontainers/linuxcontainerutil/linuxcontainerutil.go

Lines changed: 36 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ func RunInstallCommands(context context.T, orchestrationDirectory string, out io
2828
log := context.Log()
2929
info, err = dep.GetInstanceInfo(context)
3030
if err != nil {
31-
log.Error("Error determining Linux variant", err)
31+
log.Error("Error determining Linux variant: ", err)
3232
out.MarkAsFailed(fmt.Errorf("Error determining Linux variant: %v", err))
3333
return
3434
}
3535
if info.GetPlatform() == updateconstants.PlatformUbuntu {
36-
log.Error("Ubuntu platform is not currently supported", err)
37-
out.MarkAsFailed(fmt.Errorf("Ubuntu platform is not currently supported: %v", err))
36+
log.Error("Ubuntu platform is not currently supported")
37+
out.MarkAsFailed(fmt.Errorf("Ubuntu platform is not currently supported"))
3838
return
3939
} else if info.GetPlatform() == updateconstants.PlatformLinux {
4040
runAmazonLinuxPlatformInstallCommands(context, log, orchestrationDirectory, out)
@@ -43,8 +43,8 @@ func RunInstallCommands(context context.T, orchestrationDirectory string, out io
4343
runRedhatLinuxPlatformInstallCommands(context, log, orchestrationDirectory, out)
4444
return
4545
} else {
46-
log.Error("Unsupported Linux variant", err)
47-
out.MarkAsFailed(fmt.Errorf("Unsupported Linux variant: %v", err))
46+
log.Error("Unsupported Linux variant: ", info.GetPlatform())
47+
out.MarkAsFailed(fmt.Errorf("Unsupported Linux variant: %v", info.GetPlatform()))
4848
return
4949
}
5050
}
@@ -55,38 +55,38 @@ func runAmazonLinuxPlatformInstallCommands(context context.T, log log.T, orchest
5555
var output string
5656
var parameters []string
5757

58-
out.AppendInfo("Updating yum")
58+
out.AppendInfo("Installing docker through yum")
5959
command = "yum"
60-
parameters = []string{"update", "-y", "docker"}
60+
parameters = []string{"install", "-y", "docker"}
6161
output, err = dep.UpdateUtilExeCommandOutput(context, 120, log, command, parameters, "", "", "", "", false)
6262
if err != nil {
63-
log.Error("Error running yum update", err)
64-
out.MarkAsFailed(fmt.Errorf("Error running yum update: %v", err))
63+
log.Error("Error running yum install: ", err)
64+
out.MarkAsFailed(fmt.Errorf("Error running yum install: %v", err))
6565
return
6666
}
67-
log.Debug("yum update:", output)
67+
log.Debug("yum install: ", output)
6868

69-
out.AppendInfo("Installation docker through yum")
69+
out.AppendInfo("Updating docker through yum")
7070
command = "yum"
71-
parameters = []string{"install", "-y", "docker"}
71+
parameters = []string{"update", "-y", "docker"}
7272
output, err = dep.UpdateUtilExeCommandOutput(context, 120, log, command, parameters, "", "", "", "", false)
7373
if err != nil {
74-
log.Error("Error running yum install", err)
75-
out.MarkAsFailed(fmt.Errorf("Error running yum install: %v", err))
74+
log.Error("Error running yum update: ", err)
75+
out.MarkAsFailed(fmt.Errorf("Error running yum update: %v", err))
7676
return
7777
}
78-
log.Debug("yum install:", output)
78+
log.Debug("yum update: ", output)
7979

8080
out.AppendInfo("Starting docker service")
8181
command = "service"
8282
parameters = []string{"docker", "start"}
8383
output, err = dep.UpdateUtilExeCommandOutput(context, 120, log, command, parameters, "", "", "", "", false)
8484
if err != nil {
85-
log.Error("Error running service docker start", err)
85+
log.Error("Error running service docker start: ", err)
8686
out.MarkAsFailed(fmt.Errorf("Error running ervice docker start: %v", err))
8787
return
8888
}
89-
log.Debug("Service docker start:", output)
89+
log.Debug("Service docker start: ", output)
9090

9191
out.AppendInfo("Installation complete")
9292
out.MarkAsSucceeded()
@@ -104,55 +104,44 @@ func runRedhatLinuxPlatformInstallCommands(context context.T, log log.T, orchest
104104
parameters = []string{"install", "-y", "yum-utils"}
105105
output, err = dep.UpdateUtilExeCommandOutput(context, 120, log, command, parameters, "", "", "", "", false)
106106
if err != nil {
107-
log.Error("Error running yum install", err)
107+
log.Error("Error running yum install ", err)
108108
out.MarkAsFailed(fmt.Errorf("Error running yum install: %v", err))
109109
return
110110
}
111-
log.Debug("yum install:", output)
111+
log.Debug("yum install: ", output)
112112

113113
out.AppendInfo("Add docker repo")
114114
command = "yum-config-manager"
115-
parameters = []string{"--add-repo", "https://docs.docker.com/engine/installation/linux/repo_files/centos/docker.repo"}
115+
parameters = []string{"--add-repo", "https://download.docker.com/linux/centos/docker-ce.repo"}
116116
output, err = dep.UpdateUtilExeCommandOutput(context, 120, log, command, parameters, "", "", "", "", false)
117117
if err != nil {
118-
log.Error("Error running yum-config-manage", err)
118+
log.Error("Error running yum-config-manage: ", err)
119119
out.MarkAsFailed(fmt.Errorf("Error running yum-config-manager: %v", err))
120120
return
121121
}
122-
log.Debug("yum-config-manager:", output)
123-
124-
out.AppendInfo("Update yum package index")
125-
command = "yum"
126-
parameters = []string{"makecache", "fast"}
127-
output, err = dep.UpdateUtilExeCommandOutput(context, 120, log, command, parameters, "", "", "", "", false)
128-
if err != nil {
129-
log.Error("Error running yum makecache", err)
130-
out.MarkAsFailed(fmt.Errorf("Error running yum makecache: %v", err))
131-
return
132-
}
133-
log.Debug("yum makecache:", output)
122+
log.Debug("yum-config-manager: ", output)
134123

135124
out.AppendInfo("Installation docker through yum")
136125
command = "yum"
137-
parameters = []string{"install", "-y", "docker-engine"}
126+
parameters = []string{"install", "-y", "docker-ce"}
138127
output, err = dep.UpdateUtilExeCommandOutput(context, 120, log, command, parameters, "", "", "", "", false)
139128
if err != nil {
140-
log.Error("Error running yum install", err)
129+
log.Error("Error running yum install: ", err)
141130
out.MarkAsFailed(fmt.Errorf("Error running yum install: %v", err))
142131
return
143132
}
144-
log.Debug("yum install:", output)
133+
log.Debug("yum install: ", output)
145134

146135
out.AppendInfo("Starting docker service")
147136
command = "systemctl"
148137
parameters = []string{"start", "docker"}
149138
output, err = dep.UpdateUtilExeCommandOutput(context, 120, log, command, parameters, "", "", "", "", false)
150139
if err != nil {
151-
log.Error("Error running systemctl docker start", err)
140+
log.Error("Error running systemctl docker start: ", err)
152141
out.MarkAsFailed(fmt.Errorf("Error running systemctl docker start: %v", err))
153142
return
154143
}
155-
log.Debug("systemctl docker start:", output)
144+
log.Debug("systemctl docker start: ", output)
156145

157146
out.AppendInfo("Installation complete")
158147
out.MarkAsSucceeded()
@@ -165,12 +154,12 @@ func RunUninstallCommands(context context.T, orchestrationDirectory string, out
165154
log := context.Log()
166155
info, err = dep.GetInstanceInfo(context)
167156
if err != nil {
168-
log.Error("Error determining Linux variant", err)
157+
log.Error("Error determining Linux variant: ", err)
169158
out.MarkAsFailed(fmt.Errorf("Error determining Linux variant: %v", err))
170159
return
171160
}
172161
if info.GetPlatform() == updateconstants.PlatformUbuntu {
173-
log.Error("Ubuntu platform is not currently supported", err)
162+
log.Error("Ubuntu platform is not currently supported: ", err)
174163
out.MarkAsFailed(fmt.Errorf("Ubuntu platform is not currently supported: %v", err))
175164
return
176165
} else if info.GetPlatform() == updateconstants.PlatformLinux {
@@ -180,7 +169,7 @@ func RunUninstallCommands(context context.T, orchestrationDirectory string, out
180169
runRedhatLinuxPlatformUninstallCommands(context, log, orchestrationDirectory, out)
181170
return
182171
} else {
183-
log.Error("Unsupported Linux variant", err)
172+
log.Error("Unsupported Linux variant: ", err)
184173
out.MarkAsFailed(fmt.Errorf("Unsupported Linux variant: %v", err))
185174
return
186175
}
@@ -191,16 +180,16 @@ func runAmazonLinuxPlatformUninstallCommands(context context.T, log log.T, orche
191180
var command string
192181
var output string
193182
var parameters []string
194-
out.AppendInfo("Removing docker though yum")
183+
out.AppendInfo("Removing docker through yum")
195184
command = "yum"
196185
parameters = []string{"remove", "-y", "docker"}
197186
output, err = dep.UpdateUtilExeCommandOutput(context, 120, log, command, parameters, "", "", "", "", false)
198187
if err != nil {
199-
log.Error("Error running yum remove", err)
188+
log.Error("Error running yum remove: ", err)
200189
out.MarkAsFailed(fmt.Errorf("Error running yum remove: %v", err))
201190
return
202191
}
203-
log.Debug("yum remove:", output)
192+
log.Debug("yum remove: ", output)
204193
out.AppendInfo("Uninstall complete")
205194
out.MarkAsSucceeded()
206195
return
@@ -211,16 +200,16 @@ func runRedhatLinuxPlatformUninstallCommands(context context.T, log log.T, orche
211200
var command string
212201
var output string
213202
var parameters []string
214-
out.AppendInfo("Removing docker though yum")
203+
out.AppendInfo("Removing docker through yum")
215204
command = "yum"
216205
parameters = []string{"remove", "-y", "docker-engine"}
217206
output, err = dep.UpdateUtilExeCommandOutput(context, 120, log, command, parameters, "", "", "", "", false)
218207
if err != nil {
219-
log.Error("Error running yum remove", err)
208+
log.Error("Error running yum remove: ", err)
220209
out.MarkAsFailed(fmt.Errorf("Error running yum remove: %v", err))
221210
return
222211
}
223-
log.Debug("yum remove:", output)
212+
log.Debug("yum remove: ", output)
224213
out.AppendInfo("Uninstall complete")
225214
out.MarkAsSucceeded()
226215
return

agent/plugins/configurecontainers/windowscontainerutil/windowscontainerutil.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func RunInstallCommands(context context.T, orchestrationDirectory string, out io
5555
}
5656
log.Debug("Platform Version:", platformVersion)
5757
if !strings.HasPrefix(platformVersion, "10") {
58-
out.MarkAsFailed(errors.New("ConfigureDocker is only supported on Microsoft Windows Server 2016."))
58+
out.MarkAsFailed(errors.New("ConfigureDocker is only supported on Microsoft Windows Server 2016 and above."))
5959
return
6060
}
6161

@@ -165,11 +165,7 @@ func RunInstallCommands(context context.T, orchestrationDirectory string, out io
165165

166166
//Create docker config if it does not exist
167167
daemonConfigPath := os.Getenv("ProgramData") + "\\docker\\config\\daemon.json"
168-
daemonConfigContent := `
169-
{
170-
"fixed-cidr": "172.17.0.0/16"
171-
}
172-
`
168+
daemonConfigContent := `{}`
173169

174170
if err := dep.SetDaemonConfig(daemonConfigPath, daemonConfigContent); err != nil {
175171
log.Error("Error writing Docker daemon config file", err)
@@ -324,7 +320,7 @@ func RunUninstallCommands(context context.T, orchestrationDirectory string, out
324320
}
325321
log.Debug("Platform Version:", platformVersion)
326322
if !strings.HasPrefix(platformVersion, "10") {
327-
out.MarkAsFailed(errors.New("ConfigureDocker is only supported on Microsoft Windows Server 2016."))
323+
out.MarkAsFailed(errors.New("ConfigureDocker is only supported on Microsoft Windows Server 2016 and above."))
328324
return
329325
}
330326

@@ -359,10 +355,11 @@ func RunUninstallCommands(context context.T, orchestrationDirectory string, out
359355
//Unregister Service
360356
if len(strings.TrimSpace(dockerServiceStatusOutput)) > 0 {
361357
out.AppendInfo("Unregistering dockerd service.")
362-
command = "(Get-WmiObject -Class Win32_Service -Filter \"Name='docker'\").delete()"
363358

364-
parameters = make([]string, 0)
365-
dockerServiceStatusOutput, err = dep.UpdateUtilExeCommandOutput(context, 120, log, command, parameters, DOCKER_INSTALLED_DIRECTORY, "", "", "", true)
359+
command = `dockerd`
360+
log.Debug("dockerd cmd:", command)
361+
parameters = []string{"--unregister-service"}
362+
dockerServiceStatusOutput, err = dep.UpdateUtilExeCommandOutput(context, 120, log, command, parameters, "", "", "", "", true)
366363
if err != nil {
367364
log.Error("Error unregistering Docker service", err)
368365
out.MarkAsFailed(fmt.Errorf("Error unregistering Docker service: %v", err))

agent/plugins/dockercontainer/dockercontainer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,11 @@ func (p *Plugin) runCommands(pluginID string, pluginInput DockerContainerPluginI
308308
func validateInputs(pluginInput DockerContainerPluginInput) (err error) {
309309
validContainerName := regexp.MustCompile(`^[a-zA-Z0-9_\-\\\/]*$`)
310310
if !validContainerName.MatchString(pluginInput.Container) {
311-
return errors.New("Invalid container name, only [a-zA-Z0-9_-] are allowed")
311+
return errors.New("Invalid container name, only [a-zA-Z0-9_-\\/] are allowed")
312312
}
313-
validImageValue := regexp.MustCompile(`^[a-zA-Z0-9_\-\\\/]*$`)
313+
validImageValue := regexp.MustCompile(`^[a-zA-Z0-9.:_\-\\\/]*$`)
314314
if !validImageValue.MatchString(pluginInput.Image) {
315-
return errors.New("Invalid image value, only [a-zA-Z0-9_-] are allowed")
315+
return errors.New("Invalid image value, only [a-zA-Z0-9.:_-\\/] are allowed")
316316
}
317317
validUserValue := regexp.MustCompile(`^[a-zA-Z0-9_-]*$`)
318318
if !validUserValue.MatchString(pluginInput.User) {

agent/updateutil/updateutil.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,13 +295,14 @@ func (util *Utility) ExeCommandOutput(
295295
// Run the command and return its output
296296
var out []byte
297297
out, err = cmdOutput(command)
298+
output = string(out)
298299
// Write the returned output so that we can upload it if needed
299300
stdoutWriter.Write(out)
300301
if err != nil {
301302
return
302303
}
303304

304-
return string(out), err
305+
return output, err
305306
}
306307

307308
// TODO move to commandUtil
@@ -333,13 +334,14 @@ func (util *Utility) NewExeCommandOutput(
333334
// Run the command and return its output
334335
var out []byte
335336
out, err = cmdOutput(command)
337+
output = string(out)
336338
// Write the returned output so that we can upload it if needed
337339
stdoutWriter.Write(out)
338340
if err != nil {
339341
return
340342
}
341343

342-
return string(out), err
344+
return output, err
343345
}
344346

345347
// IsServiceRunning returns is service running

0 commit comments

Comments
 (0)