MCPcopy Index your code
hub / github.com/ddev/ddev / EnsureSSHAgentContainer

Method EnsureSSHAgentContainer

pkg/ddevapp/ssh_auth.go:39–100  ·  view source on GitHub ↗

EnsureSSHAgentContainer ensures the ssh-auth container is running.

()

Source from the content-addressed store, hash-verified

37
38// EnsureSSHAgentContainer ensures the ssh-auth container is running.
39func (app *DdevApp) EnsureSSHAgentContainer() error {
40 util.Debug("Ensuring ddev-ssh-agent container is running with the current image")
41 sshContainer, err := findDdevSSHAuth()
42 if err != nil {
43 return err
44 }
45 // Nothing to do if the ssh container is running with the current image.
46 // Use HasSuffix to handle registry prefixes (e.g. docker.io/) that Podman includes in image names.
47 if sshContainer != nil &&
48 strings.HasSuffix(sshContainer.Image, ddevImages.GetSSHAuthImage()+"-built") &&
49 (sshContainer.State == "running" || sshContainer.State == "starting") {
50 return nil
51 }
52
53 dockerutil.EnsureDdevNetwork()
54
55 composeFile, err := app.CreateSSHAuthComposeFile()
56 if err != nil {
57 return err
58 }
59
60 _ = app.DockerEnv()
61
62 _, _, err = dockerutil.ComposeCmd(&dockerutil.ComposeCmdOpts{
63 ProjectName: SSHAuthName,
64 ComposeFiles: []string{composeFile},
65 Action: []string{"down"},
66 })
67 if err != nil {
68 util.Warning("failed to docker-compose down on %s: %v", composeFile, err)
69 }
70
71 err = dockerutil.Pull(ddevImages.GetSSHAuthImage())
72 if err != nil {
73 return err
74 }
75
76 // Now restart ddev-ssh-agent
77 _, _, err = dockerutil.ComposeCmd(&dockerutil.ComposeCmdOpts{
78 ProjectName: SSHAuthName,
79 ComposeFiles: []string{composeFile},
80 Action: []string{"up", "--build", "-d"},
81 })
82 if err != nil {
83 return fmt.Errorf("failed to start ddev-ssh-agent: %v", err)
84 }
85
86 // ensure we have a happy sshAuth
87 label := map[string]string{
88 "com.docker.compose.project": SSHAuthName,
89 "com.docker.compose.oneoff": "False",
90 }
91 sshWaitTimeout := 60
92 util.Debug(`Waiting for ddev-ssh-agent to become ready, timeout=%v`, sshWaitTimeout)
93 logOutput, err := dockerutil.ContainerWait(sshWaitTimeout, label)
94 if err != nil {
95 return fmt.Errorf("ddev-ssh-agent failed to become ready; log=%s, err=%v", logOutput, err)
96 }

Callers 3

TestSSHAuthFunction · 0.95
StartMethod · 0.95
auth-ssh.goFile · 0.80

Calls 10

DockerEnvMethod · 0.95
DebugFunction · 0.92
EnsureDdevNetworkFunction · 0.92
ComposeCmdFunction · 0.92
WarningFunction · 0.92
PullFunction · 0.92
ContainerWaitFunction · 0.92
findDdevSSHAuthFunction · 0.85
ErrorfMethod · 0.80

Tested by 1

TestSSHAuthFunction · 0.76